summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-09-18 16:06:12 +0200
committerwm4 <wm4@nowhere>2016-09-18 16:08:21 +0200
commit2415b695724c15def54a039527ee9eb574ffb65f (patch)
tree97ed9e4c272bf3ac29764557db73b24d99503945 /player
parent3ecc6d0a7934c42395d863b74e47f903fe864760 (diff)
downloadmpv-2415b695724c15def54a039527ee9eb574ffb65f.tar.bz2
mpv-2415b695724c15def54a039527ee9eb574ffb65f.tar.xz
player: more option/property consistency fixes
Some properties had a different type from their equivalent options (such as mute, volume, deinterlace, edition). This wasn't really sane, as raw option values should be always within their bounds. On the other hand, these properties use a different type to reflect runtime limits (such as range of available editions), or simply to improve the "UI" (you don't want to cycle throuhg the completely useless "auto" value when cycling the "mute" property). Handle this by making them always return the option type, but also allowing them to provide a "constricted" type, which is used for UI purposes. All M_PROPERTY_GET_CONSTRICTED_TYPE changes are related to this. One consequence is that you can set the volume property to arbitrary high values just like with the --volume option, but using the "add" command it still restricts it to the --volume-max range. Also deprecate --chapter, as it is grossly incompatible to the chapter property. We pondered renaming it to --chapters, or introducing a more powerful --range option, but concluded that --start --end is actually enough. These changes appear to take care of the last gross property/option incompatibilities, although there might still be a few lurking.
Diffstat (limited to 'player')
-rw-r--r--player/command.c61
-rw-r--r--player/core.h2
-rw-r--r--player/video.c10
3 files changed, 39 insertions, 34 deletions
diff --git a/player/command.c b/player/command.c
index 6c5b3e947d..3e677bfd37 100644
--- a/player/command.c
+++ b/player/command.c
@@ -279,10 +279,11 @@ int mp_on_set_option(void *ctx, struct m_config_option *co, void *data, int flag
// vf*, af*, chapter
// OK, is handled separately: playlist
// OK, does not conflict on low level: audio-file, sub-file, external-file
+ // OK, different value ranges, but happens to work for now: volume, edition
+ // All the other properties are deprecated in their current form.
static const char *const no_property[] = {
- "volume", // restricts to --volume-max
"demuxer", "idle", "length", "audio-samplerate", "audio-channels",
- "audio-format", "fps", "cache", "playlist-pos", // different semantics
+ "audio-format", "fps", "cache", "playlist-pos", "chapter",
NULL
};
@@ -300,10 +301,20 @@ int mp_on_set_option(void *ctx, struct m_config_option *co, void *data, int flag
name = tmp;
}
- int r = mp_property_do_silent(name, M_PROPERTY_SET, data, mpctx);
+ struct m_option type = {0};
+
+ int r = mp_property_do_silent(name, M_PROPERTY_GET_TYPE, &type, mpctx);
if (r == M_PROPERTY_UNKNOWN)
goto direct_option; // not mapped as property
if (r != M_PROPERTY_OK)
+ return M_OPT_INVALID; // shouldn't happen
+
+ assert(type.type == co->opt->type);
+ assert(type.max == co->opt->max);
+ assert(type.min == co->opt->min);
+
+ r = mp_property_do_silent(name, M_PROPERTY_SET, data, mpctx);
+ if (r != M_PROPERTY_OK)
return M_OPT_INVALID;
// The flag can't be passed through the property layer correctly.
@@ -873,7 +884,7 @@ static int mp_property_chapter(void *ctx, struct m_property *prop,
{
MPContext *mpctx = ctx;
if (!mpctx->playback_initialized)
- return mp_property_generic_option(mpctx, prop, action, arg);
+ return M_PROPERTY_UNAVAILABLE;
int chapter = get_current_chapter(mpctx);
int num = get_chapter_count(mpctx);
@@ -993,14 +1004,9 @@ static int mp_property_edition(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- if (!mpctx->playback_initialized)
- return mp_property_generic_option(mpctx, prop, action, arg);
-
struct demuxer *demuxer = mpctx->demuxer;
- if (!demuxer)
- return M_PROPERTY_UNAVAILABLE;
- if (demuxer->num_editions <= 0)
- return M_PROPERTY_UNAVAILABLE;
+ if (!mpctx->playback_initialized || !demuxer || demuxer->num_editions <= 0)
+ return mp_property_generic_option(mpctx, prop, action, arg);
int edition = demuxer->edition;
@@ -1014,22 +1020,18 @@ static int mp_property_edition(void *ctx, struct m_property *prop,
mpctx->opts->edition_id = edition;
if (!mpctx->stop_play)
mpctx->stop_play = PT_RELOAD_FILE;
- mp_wakeup_core(mpctx);;
+ mp_wakeup_core(mpctx);
+ break; // make it accessible to the demuxer via option change notify
}
return M_PROPERTY_OK;
}
- case M_PROPERTY_GET_TYPE: {
- struct m_option opt = {
- .type = CONF_TYPE_INT,
- .flags = CONF_RANGE,
- .min = 0,
- .max = demuxer->num_editions - 1,
- };
- *(struct m_option *)arg = opt;
- return M_PROPERTY_OK;
+ case M_PROPERTY_GET_CONSTRICTED_TYPE: {
+ int r = mp_property_generic_option(mpctx, prop, M_PROPERTY_GET_TYPE, arg);
+ ((struct m_option *)arg)->max = demuxer->num_editions - 1;
+ return r;
}
}
- return M_PROPERTY_NOT_IMPLEMENTED;
+ return mp_property_generic_option(mpctx, prop, action, arg);
}
static int get_edition_entry(int item, int action, void *arg, void *ctx)
@@ -1677,7 +1679,7 @@ static int mp_property_volume(void *ctx, struct m_property *prop,
struct MPOpts *opts = mpctx->opts;
switch (action) {
- case M_PROPERTY_GET_TYPE:
+ case M_PROPERTY_GET_CONSTRICTED_TYPE:
*(struct m_option *)arg = (struct m_option){
.type = CONF_TYPE_FLOAT,
.flags = M_OPT_RANGE,
@@ -1705,7 +1707,7 @@ static int mp_property_mute(void *ctx, struct m_property *prop,
{
MPContext *mpctx = ctx;
- if (action == M_PROPERTY_GET_TYPE) {
+ if (action == M_PROPERTY_GET_CONSTRICTED_TYPE) {
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_FLAG};
return M_PROPERTY_OK;
}
@@ -2373,14 +2375,14 @@ static int mp_property_deinterlace(void *ctx, struct m_property *prop,
case M_PROPERTY_GET:
*(int *)arg = get_deinterlacing(mpctx) > 0;
return M_PROPERTY_OK;
- case M_PROPERTY_GET_TYPE:
+ case M_PROPERTY_GET_CONSTRICTED_TYPE:
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_FLAG};
return M_PROPERTY_OK;
case M_PROPERTY_SET:
set_deinterlacing(mpctx, *(int *)arg);
return M_PROPERTY_OK;
}
- return M_PROPERTY_NOT_IMPLEMENTED;
+ return mp_property_generic_option(mpctx, prop, action, arg);
}
static int video_simple_refresh_property(void *ctx, struct m_property *prop,
@@ -4315,7 +4317,7 @@ static void show_property_osd(MPContext *mpctx, const char *name, int osd_mode)
}
struct m_option prop = {0};
- mp_property_do(name, M_PROPERTY_GET_TYPE, &prop, mpctx);
+ mp_property_do(name, M_PROPERTY_GET_CONSTRICTED_TYPE, &prop, mpctx);
if ((osd_mode & MP_ON_OSD_BAR) && (prop.flags & CONF_RANGE) == CONF_RANGE) {
if (prop.type == CONF_TYPE_INT) {
int n = prop.min;
@@ -4668,7 +4670,7 @@ static int mp_property_multiply(char *property, double f, struct MPContext *mpct
struct m_option opt = {0};
int r;
- r = mp_property_do(property, M_PROPERTY_GET_TYPE, &opt, mpctx);
+ r = mp_property_do(property, M_PROPERTY_GET_CONSTRICTED_TYPE, &opt, mpctx);
if (r != M_PROPERTY_OK)
return r;
assert(opt.type);
@@ -5615,7 +5617,8 @@ extern const struct m_sub_options gl_video_conf;
void mp_notify_property(struct MPContext *mpctx, const char *property)
{
- struct m_config_option *co = m_config_get_co(mpctx->mconfig, bstr0(property));
+ struct m_config_option *co =
+ m_config_get_co_raw(mpctx->mconfig, bstr0(property));
if (co) {
if (m_config_is_in_group(mpctx->mconfig, &gl_video_conf, co)) {
if (mpctx->video_out)
diff --git a/player/core.h b/player/core.h
index 0f1c8c7e17..22e19e49ef 100644
--- a/player/core.h
+++ b/player/core.h
@@ -575,7 +575,7 @@ void uninit_video_chain(struct MPContext *mpctx);
double calc_average_frame_duration(struct MPContext *mpctx);
int init_video_decoder(struct MPContext *mpctx, struct track *track);
int get_deinterlacing(struct MPContext *mpctx);
-void set_deinterlacing(struct MPContext *mpctx, bool enable);
+void set_deinterlacing(struct MPContext *mpctx, int opt_val);
// Values of MPOpts.softvol
enum {
diff --git a/player/video.c b/player/video.c
index 4c56ca1a00..3835ef5f95 100644
--- a/player/video.c
+++ b/player/video.c
@@ -264,14 +264,16 @@ int get_deinterlacing(struct MPContext *mpctx)
return enabled;
}
-void set_deinterlacing(struct MPContext *mpctx, bool enable)
+void set_deinterlacing(struct MPContext *mpctx, int opt_val)
{
- if (enable == (get_deinterlacing(mpctx) > 0))
+ if ((opt_val < 0 && mpctx->opts->deinterlace == opt_val) ||
+ (opt_val == (get_deinterlacing(mpctx) > 0)))
return;
- mpctx->opts->deinterlace = enable;
+ mpctx->opts->deinterlace = opt_val;
recreate_auto_filters(mpctx);
- mpctx->opts->deinterlace = get_deinterlacing(mpctx) > 0;
+ if (opt_val >= 0)
+ mpctx->opts->deinterlace = get_deinterlacing(mpctx) > 0;
}
static void recreate_video_filters(struct MPContext *mpctx)