mirror of
https://github.com/mpv-player/mpv
synced 2025-04-26 13:19:12 +00:00
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.
This commit is contained in:
parent
f894294bae
commit
9db0c118d3
1
Makefile
1
Makefile
@ -18,6 +18,7 @@ LDFLAGS_MENCODER = $(EXTRALIBS_MENCODER) \
|
|||||||
SRCS_COMMON = asxparser.c \
|
SRCS_COMMON = asxparser.c \
|
||||||
codec-cfg.c \
|
codec-cfg.c \
|
||||||
cpudetect.c \
|
cpudetect.c \
|
||||||
|
defaultopts.c \
|
||||||
edl.c \
|
edl.c \
|
||||||
find_sub.c \
|
find_sub.c \
|
||||||
get_path.c \
|
get_path.c \
|
||||||
|
@ -5,7 +5,10 @@
|
|||||||
* config for cfgparser
|
* config for cfgparser
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#include "cfg-common.h"
|
#include "cfg-common.h"
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
extern int key_fifo_size;
|
extern int key_fifo_size;
|
||||||
extern unsigned doubleclick_time;
|
extern unsigned doubleclick_time;
|
||||||
@ -84,6 +87,9 @@ const m_option_t tvscan_conf[]={
|
|||||||
* by Folke
|
* 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[]={
|
const m_option_t mplayer_opts[]={
|
||||||
/* name, pointer, type, flags, min, max */
|
/* name, pointer, type, flags, min, max */
|
||||||
|
|
||||||
@ -92,8 +98,8 @@ const m_option_t mplayer_opts[]={
|
|||||||
CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
|
CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
|
||||||
{"vo", &video_driver_list, CONF_TYPE_STRING_LIST, 0, 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},
|
{"ao", &audio_driver_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL},
|
||||||
{"fixed-vo", &fixed_vo, CONF_TYPE_FLAG,CONF_GLOBAL , 0, 1, NULL},
|
FLAG_ON("fixed-vo", fixed_vo, CONF_GLOBAL),
|
||||||
{"nofixed-vo", &fixed_vo, CONF_TYPE_FLAG,CONF_GLOBAL, 1, 0, NULL},
|
FLAG_OFF("nofixed-vo", fixed_vo, CONF_GLOBAL),
|
||||||
{"ontop", &vo_ontop, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
{"ontop", &vo_ontop, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
||||||
{"noontop", &vo_ontop, CONF_TYPE_FLAG, 0, 1, 0, NULL},
|
{"noontop", &vo_ontop, CONF_TYPE_FLAG, 0, 1, 0, NULL},
|
||||||
{"rootwin", &vo_rootwin, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
{"rootwin", &vo_rootwin, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
||||||
|
@ -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
|
|| (video_id > -1 && mpctx->demuxer->video->id != current_id
|
||||||
&& current_id != -2))
|
&& current_id != -2))
|
||||||
uninit_player(INITIALIZED_VCODEC |
|
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) {
|
if (video_id > -1 && mpctx->demuxer->video->id != current_id) {
|
||||||
sh_video_t *sh2;
|
sh_video_t *sh2;
|
||||||
sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
|
sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
|
||||||
|
9
defaultopts.c
Normal file
9
defaultopts.c
Normal file
@ -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
defaultopts.h
Normal file
2
defaultopts.h
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
struct MPOpts;
|
||||||
|
void set_default_mplayer_options(struct MPOpts *opts);
|
41
m_config.c
41
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
|
static int
|
||||||
list_options(m_option_t *opt, char* name, char *param);
|
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_t*
|
||||||
m_config_new(void) {
|
m_config_new(void *optstruct) {
|
||||||
m_config_t* config;
|
m_config_t* config;
|
||||||
static int initialized = 0;
|
static int initialized = 0;
|
||||||
static m_option_type_t profile_opt_type;
|
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++)
|
for(i = 0 ; config->self_opts[i].name ; i++)
|
||||||
config->self_opts[i].priv = config;
|
config->self_opts[i].priv = config;
|
||||||
m_config_register_options(config,config->self_opts);
|
m_config_register_options(config,config->self_opts);
|
||||||
|
config->optstruct = optstruct;
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +151,7 @@ m_config_push(m_config_t* config) {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Update the current status
|
// 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
|
// Allocate a new slot
|
||||||
slot = calloc(1,sizeof(m_config_save_slot_t) + co->opt->type->size);
|
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++;
|
pop++;
|
||||||
}
|
}
|
||||||
if(pop) // We removed some ctx -> set the previous value
|
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--;
|
config->lvl--;
|
||||||
@ -214,9 +235,11 @@ m_config_add_option(m_config_t *config, const m_option_t *arg, const char* prefi
|
|||||||
} else {
|
} else {
|
||||||
m_config_option_t *i;
|
m_config_option_t *i;
|
||||||
// Check if there is already an option pointing to this address
|
// 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 ) {
|
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->slots = i->slots;
|
||||||
co->flags |= M_CFG_OPT_ALIAS;
|
co->flags |= M_CFG_OPT_ALIAS;
|
||||||
break;
|
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)) {
|
if(!(co->flags & M_CFG_OPT_ALIAS)) {
|
||||||
// Allocate a slot for the defaults
|
// Allocate a slot for the defaults
|
||||||
sl = calloc(1,sizeof(m_config_save_slot_t) + arg->type->size);
|
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 :
|
// Hack to avoid too much trouble with dynamically allocated data :
|
||||||
// We always use a dynamic version
|
// We always use a dynamic version
|
||||||
if((arg->type->flags & M_OPT_TYPE_DYNAMIC) && arg->p && (*(void**)arg->p)) {
|
if((arg->type->flags & M_OPT_TYPE_DYNAMIC) && arg->p && (*(void**)arg->p)) {
|
||||||
*(void**)arg->p = NULL;
|
*(void**)arg->p = NULL;
|
||||||
m_option_set(arg,arg->p,sl->data);
|
m_option_set(config, arg, sl->data);
|
||||||
}
|
}
|
||||||
sl->lvl = 0;
|
sl->lvl = 0;
|
||||||
sl->prev = NULL;
|
sl->prev = NULL;
|
||||||
@ -355,7 +378,7 @@ m_config_parse_option(m_config_t *config, char* arg, char* param,int set) {
|
|||||||
return r;
|
return r;
|
||||||
// Set the option
|
// Set the option
|
||||||
if(set) {
|
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;
|
co->flags |= M_CFG_OPT_SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,6 +78,8 @@ typedef struct m_config {
|
|||||||
int profile_depth;
|
int profile_depth;
|
||||||
/// Options defined by the config itself.
|
/// Options defined by the config itself.
|
||||||
struct m_option* self_opts;
|
struct m_option* self_opts;
|
||||||
|
|
||||||
|
void *optstruct; // struct mpopts or other
|
||||||
} m_config_t;
|
} m_config_t;
|
||||||
|
|
||||||
/// \defgroup ConfigOptionFlags Config option flags
|
/// \defgroup ConfigOptionFlags Config option flags
|
||||||
@ -96,7 +98,7 @@ typedef struct m_config {
|
|||||||
/** \ingroup Config
|
/** \ingroup Config
|
||||||
*/
|
*/
|
||||||
m_config_t*
|
m_config_t*
|
||||||
m_config_new(void);
|
m_config_new(void *optstruct);
|
||||||
|
|
||||||
/// Free a config object.
|
/// Free a config object.
|
||||||
void
|
void
|
||||||
|
18
m_option.h
18
m_option.h
@ -282,6 +282,10 @@ struct m_option {
|
|||||||
* Passing a 'default func' is still valid for all func based option types.
|
* Passing a 'default func' is still valid for all func based option types.
|
||||||
*/
|
*/
|
||||||
void* priv;
|
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;
|
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.
|
/// Helper around \ref m_option_type::copy.
|
||||||
inline static void
|
inline static void
|
||||||
m_option_copy(const m_option_t* opt,void* dst, void* src) {
|
m_option_copy(const m_option_t* opt,void* dst, void* src) {
|
||||||
|
@ -90,6 +90,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "libmpcodecs/ae.h"
|
#include "libmpcodecs/ae.h"
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
|
MPOpts opts;
|
||||||
|
|
||||||
int vo_doublebuffering=0;
|
int vo_doublebuffering=0;
|
||||||
int vo_directrendering=0;
|
int vo_directrendering=0;
|
||||||
int vo_config_count=1;
|
int vo_config_count=1;
|
||||||
@ -420,7 +424,7 @@ user_correct_pts = 0;
|
|||||||
mp_msg_init();
|
mp_msg_init();
|
||||||
|
|
||||||
// Create the config context and register the options
|
// Create the config context and register the options
|
||||||
mconfig = m_config_new();
|
mconfig = m_config_new(&opts);
|
||||||
m_config_register_options(mconfig,mencoder_opts);
|
m_config_register_options(mconfig,mencoder_opts);
|
||||||
|
|
||||||
// Preparse the command line
|
// Preparse the command line
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef MPLAYER_MP_CORE_H
|
#ifndef MPLAYER_MP_CORE_H
|
||||||
#define MPLAYER_MP_CORE_H
|
#define MPLAYER_MP_CORE_H
|
||||||
|
|
||||||
|
#include "options.h"
|
||||||
#include "mp_osd.h"
|
#include "mp_osd.h"
|
||||||
#include "libao2/audio_out.h"
|
#include "libao2/audio_out.h"
|
||||||
#include "playtree.h"
|
#include "playtree.h"
|
||||||
@ -42,6 +43,7 @@
|
|||||||
|
|
||||||
|
|
||||||
typedef struct MPContext {
|
typedef struct MPContext {
|
||||||
|
struct MPOpts opts;
|
||||||
int osd_show_percentage;
|
int osd_show_percentage;
|
||||||
int osd_function;
|
int osd_function;
|
||||||
const ao_functions_t *audio_out;
|
const ao_functions_t *audio_out;
|
||||||
@ -114,7 +116,6 @@ extern FILE *edl_fd;
|
|||||||
extern int file_filter;
|
extern int file_filter;
|
||||||
// These appear in options list
|
// These appear in options list
|
||||||
extern float playback_speed;
|
extern float playback_speed;
|
||||||
extern int fixed_vo;
|
|
||||||
extern int forced_subs_only;
|
extern int forced_subs_only;
|
||||||
|
|
||||||
|
|
||||||
|
17
mplayer.c
17
mplayer.c
@ -180,6 +180,8 @@ static int max_framesize=0;
|
|||||||
#include "mixer.h"
|
#include "mixer.h"
|
||||||
|
|
||||||
#include "mp_core.h"
|
#include "mp_core.h"
|
||||||
|
#include "options.h"
|
||||||
|
#include "defaultopts.h"
|
||||||
|
|
||||||
//**************************************************************************//
|
//**************************************************************************//
|
||||||
//**************************************************************************//
|
//**************************************************************************//
|
||||||
@ -205,8 +207,6 @@ static MPContext mpctx_s = {
|
|||||||
|
|
||||||
static MPContext *mpctx = &mpctx_s;
|
static MPContext *mpctx = &mpctx_s;
|
||||||
|
|
||||||
int fixed_vo=0;
|
|
||||||
|
|
||||||
// benchmark:
|
// benchmark:
|
||||||
double video_time_usage=0;
|
double video_time_usage=0;
|
||||||
double vout_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) {
|
int reinit_video_chain(void) {
|
||||||
|
MPOpts *opts = &mpctx->opts;
|
||||||
sh_video_t * const sh_video = mpctx->sh_video;
|
sh_video_t * const sh_video = mpctx->sh_video;
|
||||||
double ar=-1.0;
|
double ar=-1.0;
|
||||||
//================== Init VIDEO (codec & libvo) ==========================
|
//================== Init VIDEO (codec & libvo) ==========================
|
||||||
if(!fixed_vo || !(initialized_flags&INITIALIZED_VO)){
|
if(opts->fixed_vo || !(initialized_flags&INITIALIZED_VO)){
|
||||||
current_module="preinit_libvo";
|
current_module="preinit_libvo";
|
||||||
|
|
||||||
//shouldn't we set dvideo->id=-2 when we fail?
|
//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");
|
mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
|
||||||
|
|
||||||
if(!sh_video->initialized){
|
if(!sh_video->initialized){
|
||||||
if(!fixed_vo) uninit_player(INITIALIZED_VO);
|
if(!opts->fixed_vo) uninit_player(INITIALIZED_VO);
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2563,8 +2564,10 @@ int gui_no_filename=0;
|
|||||||
|
|
||||||
mp_msg_init();
|
mp_msg_init();
|
||||||
|
|
||||||
|
MPOpts *opts = &mpctx->opts;
|
||||||
|
set_default_mplayer_options(opts);
|
||||||
// Create the config context and register the options
|
// Create the config context and register the options
|
||||||
mconfig = m_config_new();
|
mconfig = m_config_new(opts);
|
||||||
m_config_register_options(mconfig,mplayer_opts);
|
m_config_register_options(mconfig,mplayer_opts);
|
||||||
mp_input_register_options(mconfig);
|
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)
|
if(mpctx->dvbin_reopen)
|
||||||
{
|
{
|
||||||
mpctx->eof = 0;
|
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);
|
cache_uninit(mpctx->stream);
|
||||||
mpctx->dvbin_reopen = 0;
|
mpctx->dvbin_reopen = 0;
|
||||||
goto goto_enable_cache;
|
goto goto_enable_cache;
|
||||||
@ -3959,7 +3962,7 @@ if(benchmark){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// time to uninit all, except global stuff:
|
// 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) {
|
if(mpctx->set_of_sub_size > 0) {
|
||||||
current_module="sub_free";
|
current_module="sub_free";
|
||||||
|
Loading…
Reference in New Issue
Block a user