From 9db0c118d3acee07880472e590dc0a25e5b51be6 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Mon, 31 Mar 2008 06:19:29 +0300 Subject: Start of new option system First part of option restructuring. The aim is to move option values from a huge number of separate globals to a single non-global struct. This part adds some support for parsing option values into such struct instances, and moves one example option (fixed-vo) to the struct. --- Makefile | 1 + cfg-mplayer.h | 10 ++++++++-- command.c | 2 +- defaultopts.c | 9 +++++++++ defaultopts.h | 2 ++ m_config.c | 41 ++++++++++++++++++++++++++++++++--------- m_config.h | 4 +++- m_option.h | 18 ++++-------------- mencoder.c | 6 +++++- mp_core.h | 3 ++- mplayer.c | 17 ++++++++++------- options.h | 8 ++++++++ 12 files changed, 85 insertions(+), 36 deletions(-) create mode 100644 defaultopts.c create mode 100644 defaultopts.h create mode 100644 options.h diff --git a/Makefile b/Makefile index b10187134b..b494e0c307 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ LDFLAGS_MENCODER = $(EXTRALIBS_MENCODER) \ SRCS_COMMON = asxparser.c \ codec-cfg.c \ cpudetect.c \ + defaultopts.c \ edl.c \ find_sub.c \ get_path.c \ diff --git a/cfg-mplayer.h b/cfg-mplayer.h index a8a6e25515..462e09f7f1 100644 --- a/cfg-mplayer.h +++ b/cfg-mplayer.h @@ -5,7 +5,10 @@ * config for cfgparser */ +#include + #include "cfg-common.h" +#include "options.h" extern int key_fifo_size; extern unsigned doubleclick_time; @@ -84,6 +87,9 @@ const m_option_t tvscan_conf[]={ * by Folke */ +#define FLAG_ON(optname, varname, flags) {optname, NULL, CONF_TYPE_FLAG, flags, 0, 1, NULL, 1, offsetof(struct MPOpts, varname)} +#define FLAG_OFF(optname, varname, flags) {optname, NULL, CONF_TYPE_FLAG, flags, 1, 0, NULL, 1, offsetof(struct MPOpts, varname)} + const m_option_t mplayer_opts[]={ /* name, pointer, type, flags, min, max */ @@ -92,8 +98,8 @@ const m_option_t mplayer_opts[]={ CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL}, {"vo", &video_driver_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL}, {"ao", &audio_driver_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL}, - {"fixed-vo", &fixed_vo, CONF_TYPE_FLAG,CONF_GLOBAL , 0, 1, NULL}, - {"nofixed-vo", &fixed_vo, CONF_TYPE_FLAG,CONF_GLOBAL, 1, 0, NULL}, + FLAG_ON("fixed-vo", fixed_vo, CONF_GLOBAL), + FLAG_OFF("nofixed-vo", fixed_vo, CONF_GLOBAL), {"ontop", &vo_ontop, CONF_TYPE_FLAG, 0, 0, 1, NULL}, {"noontop", &vo_ontop, CONF_TYPE_FLAG, 0, 1, 0, NULL}, {"rootwin", &vo_rootwin, CONF_TYPE_FLAG, 0, 0, 1, NULL}, diff --git a/command.c b/command.c index 446198440c..1a7fd635da 100644 --- a/command.c +++ b/command.c @@ -903,7 +903,7 @@ static int mp_property_video(m_option_t * prop, int action, void *arg, || (video_id > -1 && mpctx->demuxer->video->id != current_id && current_id != -2)) uninit_player(INITIALIZED_VCODEC | - (fixed_vo && video_id != -2 ? 0 : INITIALIZED_VO)); + (mpctx->opts.fixed_vo && video_id != -2 ? 0 : INITIALIZED_VO)); if (video_id > -1 && mpctx->demuxer->video->id != current_id) { sh_video_t *sh2; sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id]; diff --git a/defaultopts.c b/defaultopts.c new file mode 100644 index 0000000000..21ee1eaad9 --- /dev/null +++ b/defaultopts.c @@ -0,0 +1,9 @@ +#include "defaultopts.h" +#include "options.h" + +void set_default_mplayer_options(struct MPOpts *opts) +{ + *opts = (const struct MPOpts){ + .fixed_vo = 0, + }; +} diff --git a/defaultopts.h b/defaultopts.h new file mode 100644 index 0000000000..7305a07d75 --- /dev/null +++ b/defaultopts.h @@ -0,0 +1,2 @@ +struct MPOpts; +void set_default_mplayer_options(struct MPOpts *opts); diff --git a/m_config.c b/m_config.c index 263144813e..e32fcfd024 100644 --- a/m_config.c +++ b/m_config.c @@ -34,8 +34,28 @@ m_config_add_option(m_config_t *config, const m_option_t *arg, const char* prefi static int list_options(m_option_t *opt, char* name, char *param); +static void m_option_save(const m_config_t *config, const m_option_t *opt, + void *dst) +{ + if (opt->type->save) { + void *src = opt->new ? (char*)config->optstruct + opt->offset : opt->p; + opt->type->save(opt, dst, src); + } +} + +static void m_option_set(const m_config_t *config, const m_option_t *opt, + void *src) +{ + if (opt->type->set) { + void *dst = opt->new ? (char*)config->optstruct + opt->offset : opt->p; + opt->type->set(opt, dst, src); + } +} + + + m_config_t* -m_config_new(void) { +m_config_new(void *optstruct) { m_config_t* config; static int initialized = 0; static m_option_type_t profile_opt_type; @@ -60,7 +80,8 @@ m_config_new(void) { for(i = 0 ; config->self_opts[i].name ; i++) config->self_opts[i].priv = config; m_config_register_options(config,config->self_opts); - + config->optstruct = optstruct; + return config; } @@ -130,7 +151,7 @@ m_config_push(m_config_t* config) { continue; // Update the current status - m_option_save(co->opt,co->slots->data,co->opt->p); + m_option_save(config, co->opt, co->slots->data); // Allocate a new slot slot = calloc(1,sizeof(m_config_save_slot_t) + co->opt->type->size); @@ -174,7 +195,7 @@ m_config_pop(m_config_t* config) { pop++; } if(pop) // We removed some ctx -> set the previous value - m_option_set(co->opt,co->opt->p,co->slots->data); + m_option_set(config, co->opt, co->slots->data); } config->lvl--; @@ -214,9 +235,11 @@ m_config_add_option(m_config_t *config, const m_option_t *arg, const char* prefi } else { m_config_option_t *i; // Check if there is already an option pointing to this address - if(arg->p) { + if(arg->p || arg->new && arg->offset >= 0) { for(i = config->opts ; i ; i = i->next ) { - if(i->opt->p == arg->p) { // So we don't save the same vars more than 1 time + if (arg->new ? (i->opt->new && i->opt->offset == arg->offset) + : (!i->opt->new && i->opt->p == arg->p)) { + // So we don't save the same vars more than 1 time co->slots = i->slots; co->flags |= M_CFG_OPT_ALIAS; break; @@ -226,12 +249,12 @@ m_config_add_option(m_config_t *config, const m_option_t *arg, const char* prefi if(!(co->flags & M_CFG_OPT_ALIAS)) { // Allocate a slot for the defaults sl = calloc(1,sizeof(m_config_save_slot_t) + arg->type->size); - m_option_save(arg,sl->data,(void**)arg->p); + m_option_save(config, arg, sl->data); // Hack to avoid too much trouble with dynamically allocated data : // We always use a dynamic version if((arg->type->flags & M_OPT_TYPE_DYNAMIC) && arg->p && (*(void**)arg->p)) { *(void**)arg->p = NULL; - m_option_set(arg,arg->p,sl->data); + m_option_set(config, arg, sl->data); } sl->lvl = 0; sl->prev = NULL; @@ -355,7 +378,7 @@ m_config_parse_option(m_config_t *config, char* arg, char* param,int set) { return r; // Set the option if(set) { - m_option_set(co->opt,co->opt->p,co->slots->data); + m_option_set(config, co->opt, co->slots->data); co->flags |= M_CFG_OPT_SET; } diff --git a/m_config.h b/m_config.h index e6b8bc9247..889ff597ed 100644 --- a/m_config.h +++ b/m_config.h @@ -78,6 +78,8 @@ typedef struct m_config { int profile_depth; /// Options defined by the config itself. struct m_option* self_opts; + + void *optstruct; // struct mpopts or other } m_config_t; /// \defgroup ConfigOptionFlags Config option flags @@ -96,7 +98,7 @@ typedef struct m_config { /** \ingroup Config */ m_config_t* -m_config_new(void); +m_config_new(void *optstruct); /// Free a config object. void diff --git a/m_option.h b/m_option.h index a54aac540f..cf7a1d495d 100644 --- a/m_option.h +++ b/m_option.h @@ -282,6 +282,10 @@ struct m_option { * Passing a 'default func' is still valid for all func based option types. */ void* priv; + + int new; + + int offset; }; @@ -476,20 +480,6 @@ m_option_print(const m_option_t* opt, const void* val_ptr) { return (char*)-1; } -/// Helper around \ref m_option_type::save. -inline static void -m_option_save(const m_option_t* opt,void* dst, void* src) { - if(opt->type->save) - opt->type->save(opt,dst,src); -} - -/// Helper around \ref m_option_type::set. -inline static void -m_option_set(const m_option_t* opt,void* dst, void* src) { - if(opt->type->set) - opt->type->set(opt,dst,src); -} - /// Helper around \ref m_option_type::copy. inline static void m_option_copy(const m_option_t* opt,void* dst, void* src) { diff --git a/mencoder.c b/mencoder.c index c5e0d682fa..3e86b9e1cc 100644 --- a/mencoder.c +++ b/mencoder.c @@ -90,6 +90,10 @@ #endif #include "libmpcodecs/ae.h" +#include "options.h" + +MPOpts opts; + int vo_doublebuffering=0; int vo_directrendering=0; int vo_config_count=1; @@ -420,7 +424,7 @@ user_correct_pts = 0; mp_msg_init(); // Create the config context and register the options - mconfig = m_config_new(); + mconfig = m_config_new(&opts); m_config_register_options(mconfig,mencoder_opts); // Preparse the command line diff --git a/mp_core.h b/mp_core.h index e6149266c2..c40c948114 100644 --- a/mp_core.h +++ b/mp_core.h @@ -1,6 +1,7 @@ #ifndef MPLAYER_MP_CORE_H #define MPLAYER_MP_CORE_H +#include "options.h" #include "mp_osd.h" #include "libao2/audio_out.h" #include "playtree.h" @@ -42,6 +43,7 @@ typedef struct MPContext { + struct MPOpts opts; int osd_show_percentage; int osd_function; const ao_functions_t *audio_out; @@ -114,7 +116,6 @@ extern FILE *edl_fd; extern int file_filter; // These appear in options list extern float playback_speed; -extern int fixed_vo; extern int forced_subs_only; diff --git a/mplayer.c b/mplayer.c index 59d274b081..383ab1cf56 100644 --- a/mplayer.c +++ b/mplayer.c @@ -180,6 +180,8 @@ static int max_framesize=0; #include "mixer.h" #include "mp_core.h" +#include "options.h" +#include "defaultopts.h" //**************************************************************************// //**************************************************************************// @@ -205,8 +207,6 @@ static MPContext mpctx_s = { static MPContext *mpctx = &mpctx_s; -int fixed_vo=0; - // benchmark: double video_time_usage=0; double vout_time_usage=0; @@ -2136,10 +2136,11 @@ static int sleep_until_update(float *time_frame, float *aq_sleep_time) } int reinit_video_chain(void) { + MPOpts *opts = &mpctx->opts; sh_video_t * const sh_video = mpctx->sh_video; double ar=-1.0; //================== Init VIDEO (codec & libvo) ========================== - if(!fixed_vo || !(initialized_flags&INITIALIZED_VO)){ + if(opts->fixed_vo || !(initialized_flags&INITIALIZED_VO)){ current_module="preinit_libvo"; //shouldn't we set dvideo->id=-2 when we fail? @@ -2209,7 +2210,7 @@ int reinit_video_chain(void) { mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n"); if(!sh_video->initialized){ - if(!fixed_vo) uninit_player(INITIALIZED_VO); + if(!opts->fixed_vo) uninit_player(INITIALIZED_VO); goto err_out; } @@ -2563,8 +2564,10 @@ int gui_no_filename=0; mp_msg_init(); + MPOpts *opts = &mpctx->opts; + set_default_mplayer_options(opts); // Create the config context and register the options - mconfig = m_config_new(); + mconfig = m_config_new(opts); m_config_register_options(mconfig,mplayer_opts); mp_input_register_options(mconfig); @@ -3921,7 +3924,7 @@ mp_msg(MSGT_GLOBAL,MSGL_V,"EOF code: %d \n",mpctx->eof); if(mpctx->dvbin_reopen) { mpctx->eof = 0; - uninit_player(INITIALIZED_ALL-(INITIALIZED_GUI|INITIALIZED_STREAM|INITIALIZED_INPUT|INITIALIZED_GETCH2|(fixed_vo?INITIALIZED_VO:0))); + uninit_player(INITIALIZED_ALL-(INITIALIZED_GUI|INITIALIZED_STREAM|INITIALIZED_INPUT|INITIALIZED_GETCH2|(opts->fixed_vo?INITIALIZED_VO:0))); cache_uninit(mpctx->stream); mpctx->dvbin_reopen = 0; goto goto_enable_cache; @@ -3959,7 +3962,7 @@ if(benchmark){ } // time to uninit all, except global stuff: -uninit_player(INITIALIZED_ALL-(INITIALIZED_GUI+INITIALIZED_INPUT+(fixed_vo?INITIALIZED_VO:0))); +uninit_player(INITIALIZED_ALL-(INITIALIZED_GUI+INITIALIZED_INPUT+(opts->fixed_vo?INITIALIZED_VO:0))); if(mpctx->set_of_sub_size > 0) { current_module="sub_free"; diff --git a/options.h b/options.h new file mode 100644 index 0000000000..d9061add1a --- /dev/null +++ b/options.h @@ -0,0 +1,8 @@ +#ifndef MPLAYER_OPTIONS_H +#define MPLAYER_OPTIONS_H + +typedef struct MPOpts { + int fixed_vo; +} MPOpts; + +#endif -- cgit v1.2.3