summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-06-10 20:46:07 +0200
committerwm4 <wm4@nowhere>2014-06-11 00:34:46 +0200
commit7689f5f7cedcafe30d8ede3609cf4f2a3314a1d8 (patch)
treed46cb5666c5dcdd6582ff13e7973787fbdbf49a9
parent73ac34b220d168e0f9c3399aedfb73f78e5fa455 (diff)
downloadmpv-7689f5f7cedcafe30d8ede3609cf4f2a3314a1d8.tar.bz2
mpv-7689f5f7cedcafe30d8ede3609cf4f2a3314a1d8.tar.xz
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.)
-rw-r--r--stream/stream.c2
-rw-r--r--stream/stream.h1
2 files changed, 3 insertions, 0 deletions
diff --git a/stream/stream.c b/stream/stream.c
index 773f8662c4..617420b5ae 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -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)) {
diff --git a/stream/stream.h b/stream/stream.h
index ba3f6a4fe0..4561ec3cdc 100644
--- a/stream/stream.h
+++ b/stream/stream.h
@@ -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;