options: transition properties from flag to bool

This commit is contained in:
Christoph Heinrich 2023-02-20 06:53:09 +01:00 committed by Dudemanguy
parent 4ebfe9851c
commit 17d91b9d4d
5 changed files with 39 additions and 40 deletions

View File

@ -212,7 +212,7 @@ struct m_sub_options {
bool (*get_sub_options)(int index, const struct m_sub_options **sub);
};
#define CONF_TYPE_FLAG (&m_option_type_flag)
#define CONF_TYPE_BOOL (&m_option_type_bool)
#define CONF_TYPE_INT (&m_option_type_int)
#define CONF_TYPE_INT64 (&m_option_type_int64)
#define CONF_TYPE_FLOAT (&m_option_type_float)
@ -232,7 +232,6 @@ struct m_sub_options {
// size/alignment requirements for option values in general.
union m_option_value {
bool bool_;
int flag; // not the C type "bool"!
int int_;
int64_t int64;
float float_;

View File

@ -352,14 +352,14 @@ void m_properties_print_help_list(struct mp_log *log,
mp_info(log, "\nTotal: %d properties\n", count);
}
int m_property_flag_ro(int action, void* arg, int var)
int m_property_bool_ro(int action, void* arg, int var)
{
switch (action) {
case M_PROPERTY_GET:
*(int *)arg = !!var;
return M_PROPERTY_OK;
case M_PROPERTY_GET_TYPE:
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_FLAG};
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_BOOL};
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;

View File

@ -176,7 +176,7 @@ char* m_properties_expand_string(const struct m_property *prop_list,
const char *str, void *ctx);
// Trivial helpers for implementing properties.
int m_property_flag_ro(int action, void* arg, int var);
int m_property_bool_ro(int action, void* arg, int var);
int m_property_int_ro(int action, void* arg, int var);
int m_property_int64_ro(int action, void* arg, int64_t var);
int m_property_float_ro(int action, void* arg, float var);
@ -207,8 +207,8 @@ struct m_sub_property {
.type = {.type = CONF_TYPE_FLOAT}, .value = {.float_ = (f)}
#define SUB_PROP_DOUBLE(f) \
.type = {.type = CONF_TYPE_DOUBLE}, .value = {.double_ = (f)}
#define SUB_PROP_FLAG(f) \
.type = {.type = CONF_TYPE_FLAG}, .value = {.flag = (f)}
#define SUB_PROP_BOOL(f) \
.type = {.type = CONF_TYPE_BOOL}, .value = {.bool_ = (f)}
#define SUB_PROP_PTS(f) \
.type = {.type = &m_option_type_time}, .value = {.double_ = (f)}

View File

@ -970,7 +970,7 @@ void mpv_wakeup(mpv_handle *ctx)
// map client API types to internal types
static const struct m_option type_conv[] = {
[MPV_FORMAT_STRING] = { .type = CONF_TYPE_STRING },
[MPV_FORMAT_FLAG] = { .type = CONF_TYPE_FLAG },
[MPV_FORMAT_FLAG] = { .type = CONF_TYPE_BOOL },
[MPV_FORMAT_INT64] = { .type = CONF_TYPE_INT64 },
[MPV_FORMAT_DOUBLE] = { .type = CONF_TYPE_DOUBLE },
[MPV_FORMAT_NODE] = { .type = CONF_TYPE_NODE },

View File

@ -428,7 +428,7 @@ static int mp_property_display_sync_active(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
return m_property_flag_ro(action, arg, mpctx->display_sync_active);
return m_property_bool_ro(action, arg, mpctx->display_sync_active);
}
static int mp_property_pid(void *ctx, struct m_property *prop,
@ -1103,7 +1103,7 @@ static int get_edition_entry(int item, int action, void *arg, void *ctx)
{"id", SUB_PROP_INT(item)},
{"title", SUB_PROP_STR(title),
.unavailable = !title},
{"default", SUB_PROP_FLAG(ed->default_edition)},
{"default", SUB_PROP_BOOL(ed->default_edition)},
{0}
};
@ -1338,14 +1338,14 @@ static int mp_property_core_idle(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
return m_property_flag_ro(action, arg, !mpctx->playback_active);
return m_property_bool_ro(action, arg, !mpctx->playback_active);
}
static int mp_property_idle(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
return m_property_flag_ro(action, arg, mpctx->stop_play == PT_STOP);
return m_property_bool_ro(action, arg, mpctx->stop_play == PT_STOP);
}
static int mp_property_window_id(void *ctx, struct m_property *prop,
@ -1367,7 +1367,7 @@ static int mp_property_eof_reached(void *ctx, struct m_property *prop,
return M_PROPERTY_UNAVAILABLE;
bool eof = mpctx->video_status == STATUS_EOF &&
mpctx->audio_status == STATUS_EOF;
return m_property_flag_ro(action, arg, eof);
return m_property_bool_ro(action, arg, eof);
}
static int mp_property_seeking(void *ctx, struct m_property *prop,
@ -1376,14 +1376,14 @@ static int mp_property_seeking(void *ctx, struct m_property *prop,
MPContext *mpctx = ctx;
if (!mpctx->playback_initialized)
return M_PROPERTY_UNAVAILABLE;
return m_property_flag_ro(action, arg, !mpctx->restart_complete);
return m_property_bool_ro(action, arg, !mpctx->restart_complete);
}
static int mp_property_playback_abort(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
return m_property_flag_ro(action, arg, !mpctx->playing || mpctx->stop_play);
return m_property_bool_ro(action, arg, !mpctx->playing || mpctx->stop_play);
}
static int mp_property_cache_speed(void *ctx, struct m_property *prop,
@ -1447,7 +1447,7 @@ static int mp_property_demuxer_cache_idle(void *ctx, struct m_property *prop,
struct demux_reader_state s;
demux_get_reader_state(mpctx->demuxer, &s);
return m_property_flag_ro(action, arg, s.idle);
return m_property_bool_ro(action, arg, s.idle);
}
static int mp_property_demuxer_cache_state(void *ctx, struct m_property *prop,
@ -1526,7 +1526,7 @@ static int mp_property_paused_for_cache(void *ctx, struct m_property *prop,
MPContext *mpctx = ctx;
if (!mpctx->playback_initialized)
return M_PROPERTY_UNAVAILABLE;
return m_property_flag_ro(action, arg, mpctx->paused_for_cache);
return m_property_bool_ro(action, arg, mpctx->paused_for_cache);
}
static int mp_property_cache_buffering(void *ctx, struct m_property *prop,
@ -1546,7 +1546,7 @@ static int mp_property_demuxer_is_network(void *ctx, struct m_property *prop,
if (!mpctx->demuxer)
return M_PROPERTY_UNAVAILABLE;
return m_property_flag_ro(action, arg, mpctx->demuxer->is_network);
return m_property_bool_ro(action, arg, mpctx->demuxer->is_network);
}
@ -1568,7 +1568,7 @@ static int mp_property_seekable(void *ctx, struct m_property *prop,
MPContext *mpctx = ctx;
if (!mpctx->demuxer)
return M_PROPERTY_UNAVAILABLE;
return m_property_flag_ro(action, arg, mpctx->demuxer->seekable);
return m_property_bool_ro(action, arg, mpctx->demuxer->seekable);
}
static int mp_property_partially_seekable(void *ctx, struct m_property *prop,
@ -1577,14 +1577,14 @@ static int mp_property_partially_seekable(void *ctx, struct m_property *prop,
MPContext *mpctx = ctx;
if (!mpctx->demuxer)
return M_PROPERTY_UNAVAILABLE;
return m_property_flag_ro(action, arg, mpctx->demuxer->partially_seekable);
return m_property_bool_ro(action, arg, mpctx->demuxer->partially_seekable);
}
static int mp_property_mixer_active(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
return m_property_flag_ro(action, arg, !!mpctx->ao);
return m_property_bool_ro(action, arg, !!mpctx->ao);
}
/// Volume (RW)
@ -1672,7 +1672,7 @@ static int mp_property_ao_mute(void *ctx, struct m_property *prop,
return M_PROPERTY_OK;
}
case M_PROPERTY_GET_TYPE:
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_FLAG};
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_BOOL};
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
@ -1961,15 +1961,15 @@ static int get_track_entry(int item, int action, void *arg, void *ctx)
.unavailable = !track->lang},
{"audio-channels", SUB_PROP_INT(track_channels(track)),
.unavailable = track_channels(track) <= 0},
{"image", SUB_PROP_FLAG(track->image)},
{"albumart", SUB_PROP_FLAG(track->attached_picture)},
{"default", SUB_PROP_FLAG(track->default_track)},
{"forced", SUB_PROP_FLAG(track->forced_track)},
{"dependent", SUB_PROP_FLAG(track->dependent_track)},
{"visual-impaired", SUB_PROP_FLAG(track->visual_impaired_track)},
{"hearing-impaired", SUB_PROP_FLAG(track->hearing_impaired_track)},
{"external", SUB_PROP_FLAG(track->is_external)},
{"selected", SUB_PROP_FLAG(track->selected)},
{"image", SUB_PROP_BOOL(track->image)},
{"albumart", SUB_PROP_BOOL(track->attached_picture)},
{"default", SUB_PROP_BOOL(track->default_track)},
{"forced", SUB_PROP_BOOL(track->forced_track)},
{"dependent", SUB_PROP_BOOL(track->dependent_track)},
{"visual-impaired", SUB_PROP_BOOL(track->visual_impaired_track)},
{"hearing-impaired", SUB_PROP_BOOL(track->hearing_impaired_track)},
{"external", SUB_PROP_BOOL(track->is_external)},
{"selected", SUB_PROP_BOOL(track->selected)},
{"main-selection", SUB_PROP_INT(order), .unavailable = order < 0},
{"external-filename", SUB_PROP_STR(track->external_filename),
.unavailable = !track->external_filename},
@ -2329,9 +2329,9 @@ static int mp_property_video_frame_info(void *ctx, struct m_property *prop,
struct m_sub_property props[] = {
{"picture-type", SUB_PROP_STR(pict_type), .unavailable = !pict_type},
{"interlaced", SUB_PROP_FLAG(!!(f->fields & MP_IMGFIELD_INTERLACED))},
{"tff", SUB_PROP_FLAG(!!(f->fields & MP_IMGFIELD_TOP_FIRST))},
{"repeat", SUB_PROP_FLAG(!!(f->fields & MP_IMGFIELD_REPEAT_FIRST))},
{"interlaced", SUB_PROP_BOOL(!!(f->fields & MP_IMGFIELD_INTERLACED))},
{"tff", SUB_PROP_BOOL(!!(f->fields & MP_IMGFIELD_TOP_FIRST))},
{"repeat", SUB_PROP_BOOL(!!(f->fields & MP_IMGFIELD_REPEAT_FIRST))},
{0}
};
@ -2491,7 +2491,7 @@ static int mp_property_focused(void *ctx, struct m_property *prop,
if (vo_control(vo, VOCTRL_GET_FOCUSED, &focused) < 1)
return M_PROPERTY_UNAVAILABLE;
return m_property_flag_ro(action, arg, focused);
return m_property_bool_ro(action, arg, focused);
}
static int mp_property_display_names(void *ctx, struct m_property *prop,
@ -2522,7 +2522,7 @@ static int mp_property_vo_configured(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
return m_property_flag_ro(action, arg,
return m_property_bool_ro(action, arg,
mpctx->video_out && mpctx->video_out->config_ok);
}
@ -3027,8 +3027,8 @@ static int get_playlist_entry(int item, int action, void *arg, void *ctx)
bool playing = mpctx->playing == e;
struct m_sub_property props[] = {
{"filename", SUB_PROP_STR(e->filename)},
{"current", SUB_PROP_FLAG(1), .unavailable = !current},
{"playing", SUB_PROP_FLAG(1), .unavailable = !playing},
{"current", SUB_PROP_BOOL(1), .unavailable = !current},
{"playing", SUB_PROP_BOOL(1), .unavailable = !playing},
{"title", SUB_PROP_STR(e->title), .unavailable = !e->title},
{"id", SUB_PROP_INT64(e->id)},
{0}
@ -3421,8 +3421,8 @@ static int mp_property_option_info(void *ctx, struct m_property *prop,
struct m_sub_property props[] = {
{"name", SUB_PROP_STR(co->name)},
{"type", SUB_PROP_STR(opt->type->name)},
{"set-from-commandline", SUB_PROP_FLAG(co->is_set_from_cmdline)},
{"set-locally", SUB_PROP_FLAG(co->is_set_locally)},
{"set-from-commandline", SUB_PROP_BOOL(co->is_set_from_cmdline)},
{"set-locally", SUB_PROP_BOOL(co->is_set_locally)},
{"default-value", *opt, def},
{"min", SUB_PROP_DOUBLE(opt->min),
.unavailable = !(has_minmax && opt->min != DBL_MIN)},