summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-09-09 17:44:02 +0200
committerwm4 <wm4@nowhere>2016-09-09 17:54:57 +0200
commit04320d26ebb8a9ea2cfba9a7b6ddec0920326233 (patch)
tree2908ca8415f17ae9ed687797a9b8acddf8cccf71
parentc15764101943e93ea9e8223596d8a6a2571494c3 (diff)
downloadmpv-04320d26ebb8a9ea2cfba9a7b6ddec0920326233.tar.bz2
mpv-04320d26ebb8a9ea2cfba9a7b6ddec0920326233.tar.xz
stream, demux, config: remove some dead/unneeded option-related code
This has all been made unnecessary recently. The change not to copy the global option struct in particular can be made because now nothing accesses the global options anymore in the demux and stream layers. Some code that was accidentally added/changed in commit 5e30e7a0 is also removed, because it was simply committed accidentally, and was never used.
-rw-r--r--demux/demux_edl.c1
-rw-r--r--options/m_config.c68
-rw-r--r--options/m_config.h9
-rw-r--r--player/core.h1
-rw-r--r--player/loadfile.c4
-rw-r--r--player/misc.c17
-rw-r--r--stream/stream.c79
-rw-r--r--stream/stream.h13
8 files changed, 6 insertions, 186 deletions
diff --git a/demux/demux_edl.c b/demux/demux_edl.c
index f4968905bd..67a4290303 100644
--- a/demux/demux_edl.c
+++ b/demux/demux_edl.c
@@ -28,7 +28,6 @@
#include "demux.h"
#include "timeline.h"
#include "common/msg.h"
-#include "common/global.h"
#include "options/path.h"
#include "misc/bstr.h"
#include "common/common.h"
diff --git a/options/m_config.c b/options/m_config.c
index 695c9569e9..f4d544c798 100644
--- a/options/m_config.c
+++ b/options/m_config.c
@@ -411,8 +411,11 @@ static void add_sub_options(struct m_config *config,
assert(config->groups[n].group != subopts);
void *new_optstruct = NULL;
- if (config->optstruct) // only if not noalloc
- new_optstruct = m_config_alloc_struct(config, subopts);
+ if (config->optstruct) { // only if not noalloc
+ new_optstruct = talloc_zero_size(config, subopts->size);
+ if (subopts->defaults)
+ memcpy(new_optstruct, subopts->defaults, subopts->size);
+ }
if (parent && parent->data)
substruct_write_ptr(parent->data, new_optstruct);
@@ -1270,67 +1273,6 @@ struct m_config *mp_get_root_config(struct mpv_global *global)
return global->config->root;
}
-void *m_config_alloc_struct(void *talloc_ctx,
- const struct m_sub_options *subopts)
-{
- void *substruct = talloc_zero_size(talloc_ctx, subopts->size);
- if (subopts->defaults)
- memcpy(substruct, subopts->defaults, subopts->size);
- return substruct;
-}
-
-struct dtor_info {
- const struct m_sub_options *opts;
- void *ptr;
-};
-
-static void free_substruct(void *ptr)
-{
- struct dtor_info *d = ptr;
- for (int n = 0; d->opts->opts && d->opts->opts[n].type; n++) {
- const struct m_option *opt = &d->opts->opts[n];
- void *dst = (char *)d->ptr + opt->offset;
- m_option_free(opt, dst);
- }
-}
-
-// Passing ptr==NULL initializes it from proper defaults.
-void *m_sub_options_copy(void *talloc_ctx, const struct m_sub_options *opts,
- const void *ptr)
-{
- void *new = m_config_alloc_struct(talloc_ctx, opts);
- struct dtor_info *dtor = talloc_ptrtype(new, dtor);
- *dtor = (struct dtor_info){opts, new};
- talloc_set_destructor(dtor, free_substruct);
- for (int n = 0; opts->opts && opts->opts[n].type; n++) {
- const struct m_option *opt = &opts->opts[n];
- if (opt->offset < 0)
- continue;
- void *src = ptr ? (char *)ptr + opt->offset : NULL;
- void *dst = (char *)new + opt->offset;
- if (opt->type->flags & M_OPT_TYPE_HAS_CHILD) {
- // Specifying a default struct for a sub-option field in the
- // containing struct's default struct is not supported here.
- // (Out of laziness. Could possibly be supported.)
- assert(!substruct_read_ptr(dst));
-
- const struct m_sub_options *subopts = opt->priv;
-
- const void *sub_src = NULL;
- if (src)
- sub_src = substruct_read_ptr(src);
- if (!sub_src)
- sub_src = subopts->defaults;
-
- void *sub_dst = m_sub_options_copy(new, subopts, sub_src);
- substruct_write_ptr(dst, sub_dst);
- } else {
- init_opt_inplace(opt, dst, src);
- }
- }
- return new;
-}
-
struct m_config *m_config_dup(void *talloc_ctx, struct m_config *config)
{
struct m_config *new = m_config_new(talloc_ctx, config->log, config->size,
diff --git a/options/m_config.h b/options/m_config.h
index 1e23a2b0dd..ec9eb21ae2 100644
--- a/options/m_config.h
+++ b/options/m_config.h
@@ -272,15 +272,6 @@ int m_config_set_profile(struct m_config *config, char *name, int flags);
struct mpv_node m_config_get_profiles(struct m_config *config);
-void *m_config_alloc_struct(void *talloc_ctx,
- const struct m_sub_options *subopts);
-
-// Create a copy of the struct ptr, described by opts.
-// "opts" must live until the struct is free'd.
-// Freeing the struct frees all members.
-void *m_sub_options_copy(void *talloc_ctx, const struct m_sub_options *opts,
- const void *ptr);
-
// This can be used to create and synchronize per-thread option structs,
// which then can be read without synchronization. No concurrent access to
// the cache itself is allowed.
diff --git a/player/core.h b/player/core.h
index bdf19a815a..0ffb47404c 100644
--- a/player/core.h
+++ b/player/core.h
@@ -497,7 +497,6 @@ void error_on_track(struct MPContext *mpctx, struct track *track);
int stream_dump(struct MPContext *mpctx, const char *source_filename);
int mpctx_run_reentrant(struct MPContext *mpctx, void (*thread_fn)(void *arg),
void *thread_arg);
-struct mpv_global *create_sub_global(struct MPContext *mpctx);
double get_track_seek_offset(struct MPContext *mpctx, struct track *track);
// osd.c
diff --git a/player/loadfile.c b/player/loadfile.c
index b42b8f14e3..8f065e8d07 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -809,7 +809,7 @@ static void open_demux_thread(void *pctx)
static void open_demux_reentrant(struct MPContext *mpctx)
{
struct demux_open_args args = {
- .global = create_sub_global(mpctx),
+ .global = mpctx->global,
.cancel = mpctx->playback_abort,
.log = mpctx->log,
.stream_flags = mpctx->playing->stream_flags,
@@ -819,12 +819,10 @@ static void open_demux_reentrant(struct MPContext *mpctx)
args.stream_flags = 0;
mpctx_run_reentrant(mpctx, open_demux_thread, &args);
if (args.demux) {
- talloc_steal(args.demux, args.global);
mpctx->demuxer = args.demux;
enable_demux_thread(mpctx, mpctx->demuxer);
} else {
mpctx->error_playing = args.err;
- talloc_free(args.global);
}
talloc_free(args.url);
}
diff --git a/player/misc.c b/player/misc.c
index 62223ebfef..17232ff828 100644
--- a/player/misc.c
+++ b/player/misc.c
@@ -251,23 +251,6 @@ void merge_playlist_files(struct playlist *pl)
talloc_free(edl);
}
-// Create a talloc'ed copy of mpctx->global. It contains a copy of the global
-// option struct. It still just references some things though, like mp_log.
-// The main purpose is letting threads access the option struct without the
-// need for additional synchronization.
-struct mpv_global *create_sub_global(struct MPContext *mpctx)
-{
- struct mpv_global *new = talloc_ptrtype(NULL, new);
- struct m_config *new_config = m_config_dup(new, mpctx->mconfig);
- *new = (struct mpv_global){
- .log = mpctx->global->log,
- .config = mpctx->global->config,
- .opts = new_config->optstruct,
- .client_api = mpctx->clients,
- };
- return new;
-}
-
struct wrapper_args {
struct MPContext *mpctx;
void (*thread_fn)(void *);
diff --git a/stream/stream.c b/stream/stream.c
index ed7697e9c6..d5cf747b1e 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -183,65 +183,6 @@ char *mp_url_escape(void *talloc_ctx, const char *s, const char *ok)
return 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]; 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;
-}
-
-static bstr split_next(bstr *s, char end, const char *delim)
-{
- int idx = bstrcspn(*s, delim);
- if (end && (idx >= s->len || s->start[idx] != end))
- return (bstr){0};
- bstr r = bstr_splice(*s, 0, idx);
- *s = bstr_cut(*s, idx + (end ? 1 : 0));
- return r;
-}
-
-// Parse the stream URL, syntax:
-// proto:// [<username>@]<hostname>[:<port>][/<filename>]
-// (the proto:// part is assumed to be already removed from s)
-// This code originates from times when http code used this, but now it's
-// just relict from other stream implementations reusing this code.
-void mp_parse_legacy_url(bstr s, bstr c[4])
-{
- c[0] = split_next(&s, '@', "@:/");
- c[1] = split_next(&s, 0, ":/");
- c[2] = bstr_eatstart0(&s, ":") ? split_next(&s, 0, "/") : (bstr){0};
- c[3] = bstr_eatstart0(&s, "/") ? s : (bstr){0};
-}
-
-static bool parse_url(struct stream *st, struct m_config *config)
-{
- bstr f[4];
- mp_parse_legacy_url(bstr0(st->path), f);
- const char *f_names[4] = {"username", "hostname", "port", "filename"};
- for (int n = 0; n < 4; n++) {
- if (f[n].len) {
- const char *opt = find_url_opt(st, f_names[n]);
- if (!opt) {
- MP_ERR(st, "Stream type '%s' accepts no '%s' field in URLs.\n",
- st->info->name, f_names[n]);
- return false;
- }
- int r = m_config_set_option(config, bstr0(opt), f[n]);
- if (r < 0) {
- MP_ERR(st, "Error setting stream option: %s\n",
- m_option_strerror(r));
- return false;
- }
- }
- }
- return true;
-}
-
static stream_t *new_stream(void)
{
return talloc_zero_size(NULL, sizeof(stream_t) + TOTAL_BUFFER_SIZE);
@@ -284,7 +225,6 @@ static int open_internal(const stream_info_t *sinfo, const char *url, int flags,
stream_t *s = new_stream();
s->log = mp_log_new(s, global->log, sinfo->name);
s->info = sinfo;
- s->opts = global->opts;
s->cancel = c;
s->global = global;
s->url = talloc_strdup(s, url);
@@ -301,24 +241,6 @@ static int open_internal(const stream_info_t *sinfo, const char *url, int flags,
return STREAM_NO_MATCH;
}
- // Parse options
- if (sinfo->priv_size) {
- struct m_obj_desc desc = {
- .priv_size = sinfo->priv_size,
- .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)) {
- MP_ERR(s, "URL parsing failed on url %s\n", url);
- talloc_free(s);
- return STREAM_ERROR;
- }
- }
-
int r = (sinfo->open)(s);
if (r != STREAM_OK) {
talloc_free(s);
@@ -757,7 +679,6 @@ static stream_t *open_cache(stream_t *orig, const char *name)
cache->lavf_type = talloc_strdup(cache, orig->lavf_type);
cache->streaming = orig->streaming,
cache->is_network = orig->is_network;
- cache->opts = orig->opts;
cache->cancel = orig->cancel;
cache->global = orig->global;
diff --git a/stream/stream.h b/stream/stream.h
index 90545da087..4444da8ed3 100644
--- a/stream/stream.h
+++ b/stream/stream.h
@@ -157,11 +157,6 @@ typedef struct stream_info_st {
// opts is set from ->opts
int (*open)(struct stream *st);
const char *const *protocols;
- int priv_size;
- const void *priv_defaults;
- void *(*get_defaults)(struct stream *st);
- const struct m_option *options;
- const char *const *url_options;
bool can_write; // correctly checks for READ/WRITE modes
bool is_safe; // opening is no security issue, even with remote provided URLs
bool is_network; // used to restrict remote playlist entries to remote URLs
@@ -203,7 +198,6 @@ typedef struct stream {
bool is_network : 1; // original stream_info_t.is_network flag
bool allow_caching : 1; // stream cache makes sense
struct mp_log *log;
- struct MPOpts *opts;
struct mpv_global *global;
struct mp_cancel *cancel; // cancellation notification
@@ -296,13 +290,6 @@ void mp_setup_av_network_options(struct AVDictionary **dict,
struct mpv_global *global,
struct mp_log *log);
-// sort-of legacy handling of options-in-stream-URL
-#define URL_USERNAME 0
-#define URL_HOSTNAME 1
-#define URL_PORT 2
-#define URL_FILENAME 3
-void mp_parse_legacy_url(bstr url, bstr components[4]);
-
void stream_print_proto_list(struct mp_log *log);
char **stream_get_proto_list(void);
bool stream_has_proto(const char *proto);