summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-04-09 11:27:38 +0200
committerwm4 <wm4@nowhere>2020-04-09 11:27:38 +0200
commitbc1a18ee245ec2243d4b7b0fa22894f4326b3758 (patch)
treef8b56c493a058c17bb64ae5b3b77b77003d5d0be
parent823e5205eac66e5bff0953605b5b6c9ddde54739 (diff)
downloadmpv-bc1a18ee245ec2243d4b7b0fa22894f4326b3758.tar.bz2
mpv-bc1a18ee245ec2243d4b7b0fa22894f4326b3758.tar.xz
options: cleanup .min use for OPT_CHANNELS
Replace use of .min==1 with a proper flag. This is a good idea, because it has nothing to do with numeric limits (also see commit 9d32d62b61547 for how this can go wrong). With this, m_option.min/max are strictly used for numeric limits.
-rw-r--r--audio/filter/af_format.c6
-rw-r--r--demux/demux_raw.c2
-rw-r--r--options/m_option.c3
-rw-r--r--options/m_option.h6
4 files changed, 9 insertions, 8 deletions
diff --git a/audio/filter/af_format.c b/audio/filter/af_format.c
index 79d78d1d96..88ae99ed56 100644
--- a/audio/filter/af_format.c
+++ b/audio/filter/af_format.c
@@ -130,9 +130,11 @@ const struct mp_user_filter_entry af_format = {
.options = (const struct m_option[]) {
{"format", OPT_AUDIOFORMAT(in_format)},
{"srate", OPT_INT(in_srate), M_RANGE(1000, 8*48000)},
- {"channels", OPT_CHANNELS(in_channels), .min = 1},
+ {"channels", OPT_CHANNELS(in_channels),
+ .flags = M_OPT_CHANNELS_LIMITED},
{"out-srate", OPT_INT(out_srate), M_RANGE(1000, 8*48000)},
- {"out-channels", OPT_CHANNELS(out_channels), .min = 1},
+ {"out-channels", OPT_CHANNELS(out_channels),
+ .flags = M_OPT_CHANNELS_LIMITED},
{"fail", OPT_FLAG(fail)},
{0}
},
diff --git a/demux/demux_raw.c b/demux/demux_raw.c
index e606a24c9f..edc89e7418 100644
--- a/demux/demux_raw.c
+++ b/demux/demux_raw.c
@@ -54,7 +54,7 @@ struct demux_rawaudio_opts {
#define OPT_BASE_STRUCT struct demux_rawaudio_opts
const struct m_sub_options demux_rawaudio_conf = {
.opts = (const m_option_t[]) {
- {"channels", OPT_CHANNELS(channels), .min = 1},
+ {"channels", OPT_CHANNELS(channels), .flags = M_OPT_CHANNELS_LIMITED},
{"rate", OPT_INT(samplerate), M_RANGE(1000, 8 * 48000)},
{"format", OPT_CHOICE(aformat,
{"u8", PCM(0, 0, 8, 0)},
diff --git a/options/m_option.c b/options/m_option.c
index aa1ac71ae6..51e3c38801 100644
--- a/options/m_option.c
+++ b/options/m_option.c
@@ -2493,8 +2493,7 @@ const m_option_type_t m_option_type_afmt = {
static int parse_channels(struct mp_log *log, const m_option_t *opt,
struct bstr name, struct bstr param, void *dst)
{
- // see OPT_CHANNELS for semantics.
- bool limited = opt->min;
+ bool limited = opt->flags & M_OPT_CHANNELS_LIMITED;
struct m_channels res = {0};
diff --git a/options/m_option.h b/options/m_option.h
index 8a8b54b510..f51ca95fa8 100644
--- a/options/m_option.h
+++ b/options/m_option.h
@@ -372,7 +372,6 @@ struct m_option {
// -/+INFINITY, the range can be extended to INFINITY. (This part is buggy
// for "float".)
// Preferably use M_RANGE() to set these fields.
- // Some types will abuse the min or max field for unrelated things.
double min, max;
// Type dependent data (for all kinds of extended settings).
@@ -432,6 +431,9 @@ char *format_file_size(int64_t size);
// type time: string "no" maps to MP_NOPTS_VALUE (if unset, NOPTS is rejected)
#define M_OPT_ALLOW_NO (1 << 26)
+// type channels: disallow "auto" (still accept ""), limit list to at most 1 item.
+#define M_OPT_CHANNELS_LIMITED (1 << 27)
+
// Like M_OPT_TYPE_OPTIONAL_PARAM.
#define M_OPT_OPTIONAL_PARAM (1 << 30)
@@ -655,8 +657,6 @@ extern const char m_option_path_separator;
#define OPT_AUDIOFORMAT(field) \
OPT_TYPED_FIELD(m_option_type_afmt, int, field)
-// If .min==1, then passing auto is disallowed, but "" is still accepted, and
-// limit channel list to 1 item.
#define OPT_CHANNELS(field) \
OPT_TYPED_FIELD(m_option_type_channels, struct m_channels, field)