Skip to content

Commit

Permalink
Start of new option system
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Uoti Urpala committed Apr 23, 2008
1 parent f894294 commit 9db0c11
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 36 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
10 changes: 8 additions & 2 deletions cfg-mplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
* config for cfgparser
*/

#include <stddef.h>

#include "cfg-common.h"
#include "options.h"

extern int key_fifo_size;
extern unsigned doubleclick_time;
Expand Down Expand Up @@ -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 */

Expand All @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
9 changes: 9 additions & 0 deletions defaultopts.c
Original file line number Diff line number Diff line change
@@ -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,
};
}
2 changes: 2 additions & 0 deletions defaultopts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
struct MPOpts;
void set_default_mplayer_options(struct MPOpts *opts);
41 changes: 32 additions & 9 deletions m_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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--;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion m_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 4 additions & 14 deletions m_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};


Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion mencoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion mp_core.h
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -42,6 +43,7 @@


typedef struct MPContext {
struct MPOpts opts;
int osd_show_percentage;
int osd_function;
const ao_functions_t *audio_out;
Expand Down Expand Up @@ -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;


Expand Down
17 changes: 10 additions & 7 deletions mplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ static int max_framesize=0;
#include "mixer.h"

#include "mp_core.h"
#include "options.h"
#include "defaultopts.h"

//**************************************************************************//
//**************************************************************************//
Expand All @@ -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;
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down
8 changes: 8 additions & 0 deletions options.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef MPLAYER_OPTIONS_H
#define MPLAYER_OPTIONS_H

typedef struct MPOpts {
int fixed_vo;
} MPOpts;

#endif

0 comments on commit 9db0c11

Please sign in to comment.