1
0
mirror of https://github.com/mpv-player/mpv synced 2025-04-01 00:07:33 +00:00

commands: add generic option -> property wrapper

Add mp_property_generic_option(), a property function that can be used
for generic option-based properties that do not require any action
beyond manipulating the value of the option variable. Currently it
directly implements GET and SET, plus STEP_UP for "choice" options
only. Use it to add a property for -pts-association-mode (not
particularly useful in normal use, but serves as a test).
This commit is contained in:
Uoti Urpala 2010-12-18 08:02:48 +02:00
parent 7e366113f7
commit b9a3579ec9
4 changed files with 46 additions and 2 deletions

View File

@ -513,6 +513,7 @@ name type min max get set step comment
osdlevel int 0 3 X X X as -osdlevel
speed float 0.01 100 X X X as -speed
loop int -1 X X X as -loop
pts_association_mode string X X X as -pts-association-mode
pause flag 0 1 X 1 if paused, use with pausing_keep_force
filename string X file playing wo path
path string X file playing

View File

@ -34,6 +34,7 @@
#include "libvo/sub.h"
#include "m_option.h"
#include "m_property.h"
#include "m_config.h"
#include "metadata.h"
#include "libmpcodecs/vf.h"
#include "libmpcodecs/vd.h"
@ -226,6 +227,39 @@ static void log_sub(struct MPContext *mpctx)
/// \ingroup Properties
///@{
static int mp_property_generic_option(struct m_option *prop, int action,
void *arg, MPContext *mpctx)
{
char *optname = prop->priv;
const struct m_option *opt = m_config_get_option(mpctx->mconfig, optname);
void *valptr = m_option_get_ptr(opt, &mpctx->opts);
switch (action) {
case M_PROPERTY_GET_TYPE:
*(const struct m_option **)arg = opt;
return M_PROPERTY_OK;
case M_PROPERTY_GET:
m_option_copy(opt, arg, valptr);
return M_PROPERTY_OK;
case M_PROPERTY_SET:
m_option_copy(opt, valptr, arg);
return M_PROPERTY_OK;
case M_PROPERTY_STEP_UP:
if (opt->type == &m_option_type_choice) {
int v = *(int *) valptr;
int best = v;
struct m_opt_choice_alternatives *alt;
for (alt = opt->priv; alt->name; alt++)
if ((unsigned) alt->value - v - 1 < (unsigned) best - v - 1)
best = alt->value;
*(int *) valptr = best;
return M_PROPERTY_OK;
}
break;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
/// OSD level (RW)
static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
@ -2189,6 +2223,8 @@ static const m_option_t mp_properties[] = {
M_OPT_RANGE, 0, 1, NULL },
{ "capturing", mp_property_capture, CONF_TYPE_FLAG,
M_OPT_RANGE, 0, 1, NULL },
{ "pts_association_mode", mp_property_generic_option, &m_option_type_choice,
0, 0, 0, "pts-association-mode" },
// Audio
{ "volume", mp_property_volume, CONF_TYPE_FLOAT,
@ -2362,6 +2398,7 @@ static struct property_osd_display {
{ "loop", 0, -1, _("Loop: %s") },
{ "chapter", -1, -1, NULL },
{ "capturing", 0, -1, _("Capturing: %s") },
{ "pts_association_mode", 0, -1, "PTS association mode: %s" },
// audio
{ "volume", OSD_VOLUME, -1, _("Volume") },
{ "mute", 0, -1, _("Mute: %s") },

View File

@ -150,7 +150,7 @@ static void m_option_save(const m_config_t *config, const m_option_t *opt,
void *dst)
{
if (opt->type->save) {
const void *src = opt->new ? (char*)config->optstruct + opt->offset : opt->p;
const void *src = m_option_get_ptr(opt, config->optstruct);
opt->type->save(opt, dst, src);
}
}
@ -159,7 +159,7 @@ static void m_option_set(const m_config_t *config, const m_option_t *opt,
const void *src)
{
if (opt->type->set) {
void *dst = opt->new ? (char*)config->optstruct + opt->offset : opt->p;
void *dst = m_option_get_ptr(opt, config->optstruct);
opt->type->set(opt, dst, src);
}
}

View File

@ -493,6 +493,12 @@ struct m_option {
*/
const m_option_t* m_option_list_find(const m_option_t* list,const char* name);
static inline void *m_option_get_ptr(const struct m_option *opt,
void *optstruct)
{
return opt->new ? (char *) optstruct + opt->offset : opt->p;
}
/// Helper to parse options, see \ref m_option_type::parse.
inline static int
m_option_parse(const m_option_t* opt,const char *name, const char *param, void* dst, int src) {