From 26f4f18c0629998a9b91e94722d166866d8b80a3 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 14 Mar 2020 21:28:01 +0100 Subject: options: change option macros and all option declarations Change all OPT_* macros such that they don't define the entire m_option initializer, and instead expand only to a part of it, which sets certain fields. This requires changing almost every option declaration, because they all use these macros. A declaration now always starts with {"name", ... followed by designated initializers only (possibly wrapped in macros). The OPT_* macros now initialize the .offset and .type fields only, sometimes also .priv and others. I think this change makes the option macros less tricky. The old code had to stuff everything into macro arguments (and attempted to allow setting arbitrary fields by letting the user pass designated initializers in the vararg parts). Some of this was made messy due to C99 and C11 not allowing 0-sized varargs with ',' removal. It's also possible that this change is pointless, other than cosmetic preferences. Not too happy about some things. For example, the OPT_CHOICE() indentation I applied looks a bit ugly. Much of this change was done with regex search&replace, but some places required manual editing. In particular, code in "obscure" areas (which I didn't include in compilation) might be broken now. In wayland_common.c the author of some option declarations confused the flags parameter with the default value (though the default value was also properly set below). I fixed this with this change. --- demux/demux_raw.c | 56 +++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'demux/demux_raw.c') diff --git a/demux/demux_raw.c b/demux/demux_raw.c index de657feb8c..e606a24c9f 100644 --- a/demux/demux_raw.c +++ b/demux/demux_raw.c @@ -54,27 +54,27 @@ 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[]) { - OPT_CHANNELS("channels", channels, 0, .min = 1), - OPT_INTRANGE("rate", samplerate, 0, 1000, 8 * 48000), - OPT_CHOICE("format", aformat, 0, - ({"u8", PCM(0, 0, 8, 0)}, - {"s8", PCM(1, 0, 8, 0)}, - {"u16le", PCM(0, 0, 16, 0)}, {"u16be", PCM(0, 0, 16, 1)}, - {"s16le", PCM(1, 0, 16, 0)}, {"s16be", PCM(1, 0, 16, 1)}, - {"u24le", PCM(0, 0, 24, 0)}, {"u24be", PCM(0, 0, 24, 1)}, - {"s24le", PCM(1, 0, 24, 0)}, {"s24be", PCM(1, 0, 24, 1)}, - {"u32le", PCM(0, 0, 32, 0)}, {"u32be", PCM(0, 0, 32, 1)}, - {"s32le", PCM(1, 0, 32, 0)}, {"s32be", PCM(1, 0, 32, 1)}, - {"floatle", PCM(0, 1, 32, 0)}, {"floatbe", PCM(0, 1, 32, 1)}, - {"doublele",PCM(0, 1, 64, 0)}, {"doublebe", PCM(0, 1, 64, 1)}, - {"u16", PCM(0, 0, 16, NE)}, - {"s16", PCM(1, 0, 16, NE)}, - {"u24", PCM(0, 0, 24, NE)}, - {"s24", PCM(1, 0, 24, NE)}, - {"u32", PCM(0, 0, 32, NE)}, - {"s32", PCM(1, 0, 32, NE)}, - {"float", PCM(0, 1, 32, NE)}, - {"double", PCM(0, 1, 64, NE)})), + {"channels", OPT_CHANNELS(channels), .min = 1}, + {"rate", OPT_INT(samplerate), M_RANGE(1000, 8 * 48000)}, + {"format", OPT_CHOICE(aformat, + {"u8", PCM(0, 0, 8, 0)}, + {"s8", PCM(1, 0, 8, 0)}, + {"u16le", PCM(0, 0, 16, 0)}, {"u16be", PCM(0, 0, 16, 1)}, + {"s16le", PCM(1, 0, 16, 0)}, {"s16be", PCM(1, 0, 16, 1)}, + {"u24le", PCM(0, 0, 24, 0)}, {"u24be", PCM(0, 0, 24, 1)}, + {"s24le", PCM(1, 0, 24, 0)}, {"s24be", PCM(1, 0, 24, 1)}, + {"u32le", PCM(0, 0, 32, 0)}, {"u32be", PCM(0, 0, 32, 1)}, + {"s32le", PCM(1, 0, 32, 0)}, {"s32be", PCM(1, 0, 32, 1)}, + {"floatle", PCM(0, 1, 32, 0)}, {"floatbe", PCM(0, 1, 32, 1)}, + {"doublele",PCM(0, 1, 64, 0)}, {"doublebe", PCM(0, 1, 64, 1)}, + {"u16", PCM(0, 0, 16, NE)}, + {"s16", PCM(1, 0, 16, NE)}, + {"u24", PCM(0, 0, 24, NE)}, + {"s24", PCM(1, 0, 24, NE)}, + {"u32", PCM(0, 0, 32, NE)}, + {"s32", PCM(1, 0, 32, NE)}, + {"float", PCM(0, 1, 32, NE)}, + {"double", PCM(0, 1, 64, NE)})}, {0} }, .size = sizeof(struct demux_rawaudio_opts), @@ -107,13 +107,13 @@ struct demux_rawvideo_opts { #define OPT_BASE_STRUCT struct demux_rawvideo_opts const struct m_sub_options demux_rawvideo_conf = { .opts = (const m_option_t[]) { - OPT_INTRANGE("w", width, 0, 1, 8192), - OPT_INTRANGE("h", height, 0, 1, 8192), - OPT_GENERAL(int, "format", vformat, 0, .type = &m_option_type_fourcc), - OPT_IMAGEFORMAT("mp-format", mp_format, 0), - OPT_STRING("codec", codec, 0), - OPT_FLOATRANGE("fps", fps, 0, 0.001, 1000), - OPT_INTRANGE("size", imgsize, 0, 1, 8192 * 8192 * 4), + {"w", OPT_INT(width), M_RANGE(1, 8192)}, + {"h", OPT_INT(height), M_RANGE(1, 8192)}, + {"format", OPT_FOURCC(vformat)}, + {"mp-format", OPT_IMAGEFORMAT(mp_format)}, + {"codec", OPT_STRING(codec)}, + {"fps", OPT_FLOAT(fps), M_RANGE(0.001, 1000)}, + {"size", OPT_INT(imgsize), M_RANGE(1, 8192 * 8192 * 4)}, {0} }, .size = sizeof(struct demux_rawvideo_opts), -- cgit v1.2.3