summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c1105
1 files changed, 599 insertions, 506 deletions
diff --git a/player/command.c b/player/command.c
index 87c91f295e..85823371f3 100644
--- a/player/command.c
+++ b/player/command.c
@@ -129,11 +129,12 @@ static char *format_delay(double time)
return talloc_asprintf(NULL, "%d ms", ROUND(time * 1000));
}
-// Property-option bridge.
-static int mp_property_generic_option(struct m_option *prop, int action,
- void *arg, MPContext *mpctx)
+// Property-option bridge. (Maps the property to the option with the same name.)
+static int mp_property_generic_option(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
- char *optname = prop->priv;
+ MPContext *mpctx = ctx;
+ const char *optname = prop->name;
struct m_config_option *opt = m_config_get_co(mpctx->mconfig,
bstr0(optname));
void *valptr = opt->data;
@@ -153,9 +154,10 @@ static int mp_property_generic_option(struct m_option *prop, int action,
}
/// Playback speed (RW)
-static int mp_property_playback_speed(m_option_t *prop, int action,
- void *arg, MPContext *mpctx)
+static int mp_property_playback_speed(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
struct MPOpts *opts = mpctx->opts;
double orig_speed = opts->playback_speed;
switch (action) {
@@ -171,34 +173,36 @@ static int mp_property_playback_speed(m_option_t *prop, int action,
*(char **)arg = talloc_asprintf(NULL, "x %6.2f", orig_speed);
return M_PROPERTY_OK;
}
- return mp_property_generic_option(prop, action, arg, mpctx);
+ return mp_property_generic_option(mpctx, prop, action, arg);
}
/// filename with path (RO)
-static int mp_property_path(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_path(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
if (!mpctx->filename)
return M_PROPERTY_UNAVAILABLE;
- return m_property_strdup_ro(prop, action, arg, mpctx->filename);
+ return m_property_strdup_ro(action, arg, mpctx->filename);
}
-static int mp_property_filename(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_filename(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
if (!mpctx->filename)
return M_PROPERTY_UNAVAILABLE;
char *filename = talloc_strdup(NULL, mpctx->filename);
if (mp_is_url(bstr0(filename)))
mp_url_unescape_inplace(filename);
char *f = (char *)mp_basename(filename);
- int r = m_property_strdup_ro(prop, action, arg, f[0] ? f : filename);
+ int r = m_property_strdup_ro(action, arg, f[0] ? f : filename);
talloc_free(filename);
return r;
}
-static int mp_property_file_size(m_option_t *prop, int action, void *arg,
- void *ctx)
+static int mp_property_file_size(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
MPContext *mpctx = ctx;
if (!mpctx->stream)
@@ -208,54 +212,51 @@ static int mp_property_file_size(m_option_t *prop, int action, void *arg,
if (stream_control(mpctx->stream, STREAM_CTRL_GET_SIZE, &size) != STREAM_OK)
return M_PROPERTY_UNAVAILABLE;
- switch (action) {
- case M_PROPERTY_GET: {
- *(int64_t *)arg = size;
- return M_PROPERTY_OK;
- }
- case M_PROPERTY_PRINT: {
+ if (action == M_PROPERTY_PRINT) {
*(char **)arg = format_file_size(size);
return M_PROPERTY_OK;
}
- }
- return M_PROPERTY_NOT_IMPLEMENTED;
+ return m_property_int64_ro(action, arg, size);
}
-static int mp_property_media_title(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_media_title(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
char *name = NULL;
if (mpctx->resolve_result)
name = mpctx->resolve_result->title;
if (name && name[0])
- return m_property_strdup_ro(prop, action, arg, name);
+ return m_property_strdup_ro(action, arg, name);
if (mpctx->master_demuxer) {
name = demux_info_get(mpctx->master_demuxer, "title");
if (name && name[0])
- return m_property_strdup_ro(prop, action, arg, name);
+ return m_property_strdup_ro(action, arg, name);
struct stream *stream = mpctx->master_demuxer->stream;
if (stream_control(stream, STREAM_CTRL_GET_DISC_NAME, &name) > 0
&& name) {
- int r = m_property_strdup_ro(prop, action, arg, name);
+ int r = m_property_strdup_ro(action, arg, name);
talloc_free(name);
return r;
}
}
- return mp_property_filename(prop, action, arg, mpctx);
+ return mp_property_filename(ctx, prop, action, arg);
}
-static int mp_property_stream_path(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_stream_path(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
struct stream *stream = mpctx->stream;
if (!stream || !stream->url)
return M_PROPERTY_UNAVAILABLE;
- return m_property_strdup_ro(prop, action, arg, stream->url);
+ return m_property_strdup_ro(action, arg, stream->url);
}
-static int mp_property_stream_capture(m_option_t *prop, int action,
- void *arg, MPContext *mpctx)
+static int mp_property_stream_capture(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
if (!mpctx->stream)
return M_PROPERTY_UNAVAILABLE;
@@ -264,52 +265,54 @@ static int mp_property_stream_capture(m_option_t *prop, int action,
stream_set_capture_file(mpctx->stream, filename);
// fall through to mp_property_generic_option
}
- return mp_property_generic_option(prop, action, arg, mpctx);
+ return mp_property_generic_option(mpctx, prop, action, arg);
}
/// Demuxer name (RO)
-static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_demuxer(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
struct demuxer *demuxer = mpctx->master_demuxer;
if (!demuxer)
return M_PROPERTY_UNAVAILABLE;
- return m_property_strdup_ro(prop, action, arg, demuxer->desc->name);
+ return m_property_strdup_ro(action, arg, demuxer->desc->name);
}
/// Position in the stream (RW)
-static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_stream_pos(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
struct stream *stream = mpctx->stream;
if (!stream)
return M_PROPERTY_UNAVAILABLE;
- switch (action) {
- case M_PROPERTY_GET:
- *(int64_t *) arg = stream_tell(stream);
- return M_PROPERTY_OK;
- case M_PROPERTY_SET:
+ if (action == M_PROPERTY_SET) {
stream_seek(stream, *(int64_t *) arg);
return M_PROPERTY_OK;
}
- return M_PROPERTY_NOT_IMPLEMENTED;
+ return m_property_int64_ro(action, arg, stream_tell(stream));
}
/// Stream end offset (RO)
-static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_stream_end(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
- return mp_property_file_size(prop, action, arg, mpctx);
+ return mp_property_file_size(ctx, prop, action, arg);
}
// Does some magic to handle "<name>/full" as time formatted with milliseconds.
// Assumes prop is the type of the actual property.
-static int property_time(m_option_t *prop, int action, void *arg, double time)
+static int property_time(int action, void *arg, double time)
{
+ const struct m_option time_type = {.type = CONF_TYPE_TIME};
switch (action) {
case M_PROPERTY_GET:
*(double *)arg = time;
return M_PROPERTY_OK;
+ case M_PROPERTY_GET_TYPE:
+ *(struct m_option *)arg = time_type;
+ return M_PROPERTY_OK;
case M_PROPERTY_KEY_ACTION: {
struct m_property_action_arg *ka = arg;
@@ -324,7 +327,7 @@ static int property_time(m_option_t *prop, int action, void *arg, double time)
*(char **)ka->arg = mp_format_time(time, true);
return M_PROPERTY_OK;
case M_PROPERTY_GET_TYPE:
- *(struct m_option *)ka->arg = *prop;
+ *(struct m_option *)ka->arg = time_type;
return M_PROPERTY_OK;
}
}
@@ -333,9 +336,10 @@ static int property_time(m_option_t *prop, int action, void *arg, double time)
}
/// Current stream position in seconds (RO)
-static int mp_property_stream_time_pos(m_option_t *prop, int action,
- void *arg, MPContext *mpctx)
+static int mp_property_stream_time_pos(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
struct demuxer *demuxer = mpctx->demuxer;
if (!demuxer)
return M_PROPERTY_UNAVAILABLE;
@@ -343,57 +347,62 @@ static int mp_property_stream_time_pos(m_option_t *prop, int action,
if (pts == MP_NOPTS_VALUE)
return M_PROPERTY_UNAVAILABLE;
- return property_time(prop, action, arg, pts);
+ return property_time(action, arg, pts);
}
/// Media length in seconds (RO)
-static int mp_property_length(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_length(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
double len;
if (!(int) (len = get_time_length(mpctx)))
return M_PROPERTY_UNAVAILABLE;
- return property_time(prop, action, arg, len);
+ return property_time(action, arg, len);
}
-static int mp_property_avsync(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_avsync(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
if (!mpctx->d_audio || !mpctx->d_video)
return M_PROPERTY_UNAVAILABLE;
if (mpctx->last_av_difference == MP_NOPTS_VALUE)
return M_PROPERTY_UNAVAILABLE;
- return m_property_double_ro(prop, action, arg, mpctx->last_av_difference);
+ return m_property_double_ro(action, arg, mpctx->last_av_difference);
}
-static int mp_property_total_avsync_change(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_total_avsync_change(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
if (!mpctx->d_audio || !mpctx->d_video)
return M_PROPERTY_UNAVAILABLE;
if (mpctx->total_avsync_change == MP_NOPTS_VALUE)
return M_PROPERTY_UNAVAILABLE;
- return m_property_double_ro(prop, action, arg, mpctx->total_avsync_change);
+ return m_property_double_ro(action, arg, mpctx->total_avsync_change);
}
/// Late frames
-static int mp_property_drop_frame_cnt(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_drop_frame_cnt(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
if (!mpctx->d_video)
return M_PROPERTY_UNAVAILABLE;
- return m_property_int_ro(prop, action, arg, mpctx->drop_frame_cnt);
+ return m_property_int_ro(action, arg, mpctx->drop_frame_cnt);
}
/// Current position in percent (RW)
-static int mp_property_percent_pos(m_option_t *prop, int action,
- void *arg, MPContext *mpctx)
+static int mp_property_percent_pos(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
if (!mpctx->num_sources)
return M_PROPERTY_UNAVAILABLE;
@@ -410,6 +419,14 @@ static int mp_property_percent_pos(m_option_t *prop, int action,
*(double *)arg = pos;
return M_PROPERTY_OK;
}
+ case M_PROPERTY_GET_TYPE:
+ *(struct m_option *)arg = (struct m_option){
+ .type = CONF_TYPE_DOUBLE,
+ .flags = M_OPT_RANGE,
+ .min = 0,
+ .max = 100,
+ };
+ return M_PROPERTY_OK;
case M_PROPERTY_PRINT:
*(char **)arg = talloc_asprintf(NULL, "%d", get_percent_pos(mpctx));
return M_PROPERTY_OK;
@@ -417,19 +434,21 @@ static int mp_property_percent_pos(m_option_t *prop, int action,
return M_PROPERTY_NOT_IMPLEMENTED;
}
-static int mp_property_time_start(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_time_start(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
double start = get_start_time(mpctx);
if (start < 0)
return M_PROPERTY_UNAVAILABLE;
- return property_time(prop, action, arg, start);
+ return property_time(action, arg, start);
}
/// Current position in seconds (RW)
-static int mp_property_time_pos(m_option_t *prop, int action,
- void *arg, MPContext *mpctx)
+static int mp_property_time_pos(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
if (!mpctx->num_sources)
return M_PROPERTY_UNAVAILABLE;
@@ -437,7 +456,7 @@ static int mp_property_time_pos(m_option_t *prop, int action,
queue_seek(mpctx, MPSEEK_ABSOLUTE, *(double *)arg, 0, true);
return M_PROPERTY_OK;
}
- return property_time(prop, action, arg, get_current_time(mpctx));
+ return property_time(action, arg, get_current_time(mpctx));
}
static bool time_remaining(MPContext *mpctx, double *remaining)
@@ -451,31 +470,33 @@ static bool time_remaining(MPContext *mpctx, double *remaining)
return len > 0;
}
-static int mp_property_remaining(m_option_t *prop, int action,
- void *arg, MPContext *mpctx)
+static int mp_property_remaining(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
double remaining;
- if (!time_remaining(mpctx, &remaining))
+ if (!time_remaining(ctx, &remaining))
return M_PROPERTY_UNAVAILABLE;
- return property_time(prop, action, arg, remaining);
+ return property_time(action, arg, remaining);
}
-static int mp_property_playtime_remaining(m_option_t *prop, int action,
- void *arg, MPContext *mpctx)
+static int mp_property_playtime_remaining(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
double remaining;
if (!time_remaining(mpctx, &remaining))
return M_PROPERTY_UNAVAILABLE;
double speed = mpctx->opts->playback_speed;
- return property_time(prop, action, arg, remaining / speed);
+ return property_time(action, arg, remaining / speed);
}
/// Current BD/DVD title (RW)
-static int mp_property_disc_title(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_disc_title(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
struct demuxer *demuxer = mpctx->master_demuxer;
if (!demuxer || !demuxer->stream)
return M_PROPERTY_UNAVAILABLE;
@@ -487,29 +508,37 @@ static int mp_property_disc_title(m_option_t *prop, int action, void *arg,
return M_PROPERTY_UNAVAILABLE;
*(int*)arg = title;
return M_PROPERTY_OK;
+ case M_PROPERTY_GET_TYPE:
+ *(struct m_option *)arg = (struct m_option){
+ .type = CONF_TYPE_INT,
+ .flags = M_OPT_MIN,
+ .min = -1,
+ };
+ return M_PROPERTY_OK;
case M_PROPERTY_SET:
title = *(int*)arg;
if (stream_control(stream, STREAM_CTRL_SET_CURRENT_TITLE, &title) <= 0)
return M_PROPERTY_NOT_IMPLEMENTED;
return M_PROPERTY_OK;
- default:
- return M_PROPERTY_NOT_IMPLEMENTED;
}
+ return M_PROPERTY_NOT_IMPLEMENTED;
}
-static int mp_property_disc_menu(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_disc_menu(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
int state = mp_nav_in_menu(mpctx);
if (state < 0)
return M_PROPERTY_UNAVAILABLE;
- return m_property_int_ro(prop, action, arg, !!state);
+ return m_property_flag_ro(action, arg, !!state);
}
/// Current chapter (RW)
-static int mp_property_chapter(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_chapter(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
int chapter = get_current_chapter(mpctx);
if (chapter < -1)
return M_PROPERTY_UNAVAILABLE;
@@ -518,6 +547,14 @@ static int mp_property_chapter(m_option_t *prop, int action, void *arg,
case M_PROPERTY_GET:
*(int *) arg = chapter;
return M_PROPERTY_OK;
+ case M_PROPERTY_GET_TYPE:
+ *(struct m_option *)arg = (struct m_option){
+ .type = CONF_TYPE_INT,
+ .flags = M_OPT_MIN | M_OPT_MAX,
+ .min = -1,
+ .max = get_chapter_count(mpctx) - 1,
+ };
+ return M_PROPERTY_OK;
case M_PROPERTY_PRINT: {
*(char **) arg = chapter_display_name(mpctx, chapter);
return M_PROPERTY_OK;
@@ -571,9 +608,10 @@ static int get_chapter_entry(int item, int action, void *arg, void *ctx)
return r;
}
-static int mp_property_list_chapters(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_list_chapters(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
int count = get_chapter_count(mpctx);
if (action == M_PROPERTY_PRINT) {
int cur = mpctx->num_sources ? get_current_chapter(mpctx) : -1;
@@ -603,9 +641,10 @@ static int mp_property_list_chapters(m_option_t *prop, int action, void *arg,
return m_property_read_list(action, arg, count, get_chapter_entry, mpctx);
}
-static int mp_property_edition(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_edition(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
struct MPOpts *opts = mpctx->opts;
struct demuxer *demuxer = mpctx->master_demuxer;
if (!demuxer)
@@ -661,9 +700,10 @@ static int get_edition_entry(int item, int action, void *arg, void *ctx)
return m_property_read_sub(props, action, arg);
}
-static int property_list_editions(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int property_list_editions(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
struct demuxer *demuxer = mpctx->master_demuxer;
if (!demuxer)
return M_PROPERTY_UNAVAILABLE;
@@ -721,9 +761,10 @@ static struct mp_resolve_src *find_source(struct mp_resolve_result *res,
return res->srcs[src];
}
-static int mp_property_quvi_format(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_quvi_format(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
struct MPOpts *opts = mpctx->opts;
struct mp_resolve_result *res = mpctx->resolve_result;
if (!res || !res->num_srcs)
@@ -766,49 +807,53 @@ static int mp_property_quvi_format(m_option_t *prop, int action, void *arg,
}
}
char *fmt = res->srcs[pos]->encid;
- return mp_property_quvi_format(prop, M_PROPERTY_SET, &fmt, mpctx);
+ return mp_property_quvi_format(mpctx, prop, M_PROPERTY_SET, &fmt);
}
}
- return mp_property_generic_option(prop, action, arg, mpctx);
+ return mp_property_generic_option(mpctx, prop, action, arg);
}
/// Number of titles in BD/DVD
-static int mp_property_disc_titles(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_disc_titles(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
struct demuxer *demuxer = mpctx->master_demuxer;
unsigned int num_titles;
if (!demuxer || stream_control(demuxer->stream, STREAM_CTRL_GET_NUM_TITLES,
&num_titles) < 1)
return M_PROPERTY_UNAVAILABLE;
- return m_property_int_ro(prop, action, arg, num_titles);
+ return m_property_int_ro(action, arg, num_titles);
}
/// Number of chapters in file
-static int mp_property_chapters(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_chapters(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
if (!mpctx->num_sources)
return M_PROPERTY_UNAVAILABLE;
int count = get_chapter_count(mpctx);
- return m_property_int_ro(prop, action, arg, count);
+ return m_property_int_ro(action, arg, count);
}
-static int mp_property_editions(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_editions(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
struct demuxer *demuxer = mpctx->master_demuxer;
if (!demuxer)
return M_PROPERTY_UNAVAILABLE;
if (demuxer->num_editions <= 0)
return M_PROPERTY_UNAVAILABLE;
- return m_property_int_ro(prop, action, arg, demuxer->num_editions);
+ return m_property_int_ro(action, arg, demuxer->num_editions);
}
/// Current dvd angle (RW)
-static int mp_property_angle(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_angle(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
struct demuxer *demuxer = mpctx->master_demuxer;
int angle = -1;
int angles;
@@ -866,8 +911,7 @@ static int get_tag_entry(int item, int action, void *arg, void *ctx)
return m_property_read_sub(props, action, arg);
}
-static int tag_property(m_option_t *prop, int action, void *arg,
- struct mp_tags *tags)
+static int tag_property(int action, void *arg, struct mp_tags *tags)
{
switch (action) {
case M_PROPERTY_GET: {
@@ -935,30 +979,33 @@ static int tag_property(m_option_t *prop, int action, void *arg,
}
/// Demuxer meta data
-static int mp_property_metadata(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_metadata(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
struct demuxer *demuxer = mpctx->master_demuxer;
if (!demuxer)
return M_PROPERTY_UNAVAILABLE;
- return tag_property(prop, action, arg, demuxer->metadata);
+ return tag_property(action, arg, demuxer->metadata);
}
-static int mp_property_chapter_metadata(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_chapter_metadata(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
struct demuxer *demuxer = mpctx->master_demuxer;
int chapter = get_current_chapter(mpctx);
if (!demuxer || chapter < 0 || chapter >= demuxer->num_chapters)
return M_PROPERTY_UNAVAILABLE;
- return tag_property(prop, action, arg, demuxer->chapters[chapter].metadata);
+ return tag_property(action, arg, demuxer->chapters[chapter].metadata);
}
-static int mp_property_vf_metadata(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_vf_metadata(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
if (!(mpctx->d_video && mpctx->d_video->vfilter))
return M_PROPERTY_UNAVAILABLE;
struct vf_chain *vf = mpctx->d_video->vfilter;
@@ -983,10 +1030,9 @@ static int mp_property_vf_metadata(m_option_t *prop, int action, void *arg,
if (strlen(rem)) {
struct m_property_action_arg next_ka = *ka;
next_ka.key = rem;
- return tag_property(prop, M_PROPERTY_KEY_ACTION, &next_ka,
- &vf_metadata);
+ return tag_property(M_PROPERTY_KEY_ACTION, &next_ka, &vf_metadata);
} else {
- return tag_property(prop, ka->action, ka->arg, &vf_metadata);
+ return tag_property(ka->action, ka->arg, &vf_metadata);
}
return M_PROPERTY_OK;
default:
@@ -997,8 +1043,8 @@ static int mp_property_vf_metadata(m_option_t *prop, int action, void *arg,
return M_PROPERTY_NOT_IMPLEMENTED;
}
-static int mp_property_pause(m_option_t *prop, int action, void *arg,
- void *ctx)
+static int mp_property_pause(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
MPContext *mpctx = ctx;
@@ -1010,35 +1056,35 @@ static int mp_property_pause(m_option_t *prop, int action, void *arg,
}
return M_PROPERTY_OK;
}
- return mp_property_generic_option(prop, action, arg, ctx);
+ return mp_property_generic_option(mpctx, prop, action, arg);
}
-static int mp_property_core_idle(m_option_t *prop, int action, void *arg,
- void *ctx)
+static int mp_property_core_idle(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
MPContext *mpctx = ctx;
- return m_property_int_ro(prop, action, arg, mpctx->paused);
+ return m_property_flag_ro(action, arg, mpctx->paused);
}
-static int mp_property_eof_reached(m_option_t *prop, int action, void *arg,
- void *ctx)
+static int mp_property_eof_reached(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
MPContext *mpctx = ctx;
- return m_property_int_ro(prop, action, arg, mpctx->eof_reached);
+ return m_property_flag_ro(action, arg, mpctx->eof_reached);
}
-static int mp_property_cache(m_option_t *prop, int action, void *arg,
- void *ctx)
+static int mp_property_cache(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
MPContext *mpctx = ctx;
int cache = mp_get_cache_percent(mpctx);
if (cache < 0)
return M_PROPERTY_UNAVAILABLE;
- return m_property_int_ro(prop, action, arg, cache);
+ return m_property_int_ro(action, arg, cache);
}
-static int mp_property_cache_size(m_option_t *prop, int action, void *arg,
- void *ctx)
+static int mp_property_cache_size(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
MPContext *mpctx = ctx;
if (!mpctx->stream)
@@ -1052,6 +1098,13 @@ static int mp_property_cache_size(m_option_t *prop, int action, void *arg,
*(int *)arg = size / 1024;
return M_PROPERTY_OK;
}
+ case M_PROPERTY_GET_TYPE:
+ *(struct m_option *)arg = (struct m_option){
+ .type = CONF_TYPE_INT,
+ .flags = M_OPT_MIN,
+ .min = 0,
+ };
+ return M_PROPERTY_OK;
case M_PROPERTY_SET: {
int64_t size = *(int *)arg * 1024LL;
int r = stream_control(mpctx->stream, STREAM_CTRL_SET_CACHE_SIZE, &size);
@@ -1065,40 +1118,51 @@ static int mp_property_cache_size(m_option_t *prop, int action, void *arg,
return M_PROPERTY_NOT_IMPLEMENTED;
}
-static int mp_property_paused_for_cache(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_paused_for_cache(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
- return m_property_int_ro(prop, action, arg, mpctx->paused_for_cache);
+ MPContext *mpctx = ctx;
+ return m_property_flag_ro(action, arg, mpctx->paused_for_cache);
}
-static int mp_property_clock(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_clock(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
char outstr[6];
time_t t = time(NULL);
struct tm *tmp = localtime(&t);
if ((tmp != NULL) && (strftime(outstr, sizeof(outstr), "%H:%M", tmp) == 5))
- return m_property_strdup_ro(prop, action, arg, outstr);
+ return m_property_strdup_ro(action, arg, outstr);
return M_PROPERTY_UNAVAILABLE;
}
-static int mp_property_seekable(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_seekable(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
if (!mpctx->demuxer)
return M_PROPERTY_UNAVAILABLE;
- return m_property_int_ro(prop, action, arg, !!mpctx->demuxer->seekable);
+ return m_property_flag_ro(action, arg, mpctx->demuxer->seekable);
}
/// Volume (RW)
-static int mp_property_volume(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_volume(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
switch (action) {
case M_PROPERTY_GET:
mixer_getbothvolume(mpctx->mixer, arg);
return M_PROPERTY_OK;
+ case M_PROPERTY_GET_TYPE:
+ *(struct m_option *)arg = (struct m_option){
+ .type = CONF_TYPE_FLOAT,
+ .flags = M_OPT_RANGE,
+ .min = 0,
+ .max = 100,
+ };
+ return M_PROPERTY_OK;
case M_PROPERTY_GET_NEUTRAL:
*(float *)arg = mixer_getneutralvolume(mpctx->mixer);
return M_PROPERTY_OK;
@@ -1125,9 +1189,10 @@ static int mp_property_volume(m_option_t *prop, int action, void *arg,
}
/// Mute (RW)
-static int mp_property_mute(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_mute(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
switch (action) {
case M_PROPERTY_SET:
if (!mixer_audio_initialized(mpctx->mixer))
@@ -1137,13 +1202,17 @@ static int mp_property_mute(m_option_t *prop, int action, void *arg,
case M_PROPERTY_GET:
*(int *)arg = mixer_getmute(mpctx->mixer);
return M_PROPERTY_OK;
+ case M_PROPERTY_GET_TYPE:
+ *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_FLAG};
+ return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
-static int mp_property_volrestore(m_option_t *prop, int action,
- void *arg, MPContext *mpctx)
+static int mp_property_volrestore(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
switch (action) {
case M_PROPERTY_GET: {
char *s = mixer_get_volume_restore_data(mpctx->mixer);
@@ -1153,13 +1222,14 @@ static int mp_property_volrestore(m_option_t *prop, int action,
case M_PROPERTY_SET:
return M_PROPERTY_NOT_IMPLEMENTED;
}
- return mp_property_generic_option(prop, action, arg, mpctx);
+ return mp_property_generic_option(mpctx, prop, action, arg);
}
/// Audio delay (RW)
-static int mp_property_audio_delay(m_option_t *prop, int action,
- void *arg, MPContext *mpctx)
+static int mp_property_audio_delay(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
if (!(mpctx->d_audio && mpctx->d_video))
return M_PROPERTY_UNAVAILABLE;
float delay = mpctx->opts->audio_delay;
@@ -1172,66 +1242,63 @@ static int mp_property_audio_delay(m_option_t *prop, int action,
mpctx->delay += mpctx->audio_delay - delay;
return M_PROPERTY_OK;
}
- return mp_property_generic_option(prop, action, arg, mpctx);
+ return mp_property_generic_option(mpctx, prop, action, arg);
}
/// Audio codec tag (RO)
-static int mp_property_audio_format(m_option_t *prop, int action,
- void *arg, MPContext *mpctx)
+static int mp_property_audio_format(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
const char *c = mpctx->d_audio ? mpctx->d_audio->header->codec : NULL;
- return m_property_strdup_ro(prop, action, arg, c);
+ return m_property_strdup_ro(action, arg, c);
}
/// Audio codec name (RO)
-static int mp_property_audio_codec(m_option_t *prop, int action,
- void *arg, MPContext *mpctx)
+static int mp_property_audio_codec(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
const char *c = mpctx->d_audio ? mpctx->d_audio->decoder_desc : NULL;
- return m_property_strdup_ro(prop, action, arg, c);
+ return m_property_strdup_ro(action, arg, c);
}
/// Audio bitrate (RO)
-static int mp_property_audio_bitrate(m_option_t *prop, int action,
- void *arg, MPContext *mpctx)
+static int mp_property_audio_bitrate(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
if (!mpctx->d_audio)
return M_PROPERTY_UNAVAILABLE;
- switch (action) {
- case M_PROPERTY_PRINT:
+ if (action == M_PROPERTY_PRINT) {
*(char **)arg = format_bitrate(mpctx->d_audio->bitrate);
return M_PROPERTY_OK;
- case M_PROPERTY_GET:
- *(int *)arg = mpctx->d_audio->bitrate;
- return M_PROPERTY_OK;
}
- return M_PROPERTY_NOT_IMPLEMENTED;
+ return m_property_int_ro(action, arg, mpctx->d_audio->bitrate);
}
/// Samplerate (RO)
-static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_samplerate(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
struct mp_audio fmt = {0};
if (mpctx->d_audio)
mp_audio_buffer_get_format(mpctx->d_audio->decode_buffer, &fmt);
if (!fmt.rate)
return M_PROPERTY_UNAVAILABLE;
- switch (action) {
- case M_PROPERTY_PRINT:
+ if (action == M_PROPERTY_PRINT) {
*(char **)arg = talloc_asprintf(NULL, "%d kHz", fmt.rate / 1000);
return M_PROPERTY_OK;
- case M_PROPERTY_GET:
- *(int *)arg = fmt.rate;
- return M_PROPERTY_OK;
}
- return M_PROPERTY_NOT_IMPLEMENTED;
+ return m_property_int_ro(action, arg, fmt.rate);
}
/// Number of channels (RO)
-static int mp_property_channels(m_option_t *prop, int action, void *arg,
- MPContext *mpctx)
+static int mp_property_channels(void *ctx, struct m_property *prop,
+ int action, void *arg)
{