2010-01-30 23:24:23 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2010-01-30 23:24:23 +00:00
|
|
|
*
|
2017-06-12 15:00:20 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2010-01-30 23:24:23 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2010-01-30 23:24:23 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2017-06-12 15:00:20 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2010-01-30 23:24:23 +00:00
|
|
|
*
|
2017-06-12 15:00:20 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2010-01-30 23:24:23 +00:00
|
|
|
*/
|
2006-03-22 00:19:02 +00:00
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// \file
|
|
|
|
/// \ingroup Properties
|
|
|
|
|
2006-03-22 00:19:02 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
2012-09-21 10:15:47 +00:00
|
|
|
#include <assert.h>
|
2006-03-22 00:19:02 +00:00
|
|
|
|
commands: change property expansion format string
This affects property format strings like they are used in the
"show_text" input command, for --playing-msg, and other places.
To quote the documentation comment on m_properties_expand_string():
${NAME} is expanded to the value of property NAME.
If NAME starts with '=', use the raw value of the property.
${NAME:STR} expands to the property, or STR if the property is not
available.
${?NAME:STR} expands to STR if the property is available.
${!NAME:STR} expands to STR if the property is not available.
STR is recursively expanded using the same rules.
"$$" can be used to escape "$", and "$}" to escape "}".
"$>" disables parsing of "$" for the rest of the string.
Most importantly, "?(property:str)" becomes "${?property:str}".
Make the simple fallback case easier, e.g. "${property:fallback}"
instead of "${property}?(!property:fallback)".
Add the ability to escape the format meta characters. "$" is used for
escaping, because escaping with "\" is taken by the commands parser in
the layer below. "$>" can be used to disable interpretation of format
strings (of course escapes by the commands parser can't be canceled).
By default, properties which are unavailable or don't exist are turned
into a string signaling the status (e.g. "(unavailable)"), instead of
an empty string. If an empty string is desired, this has to be done
explicitly: "${property:}" (the fallback part is an empty string). Raw
properties still return an empty string on error.
m_properties_expand_string() now returns a talloc'ed pointer, instead of
a malloc'ed one.
2012-09-23 21:00:54 +00:00
|
|
|
#include <libavutil/common.h>
|
|
|
|
|
2014-02-24 19:10:26 +00:00
|
|
|
#include "libmpv/client.h"
|
|
|
|
|
2016-01-11 18:03:40 +00:00
|
|
|
#include "mpv_talloc.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "m_option.h"
|
2006-03-22 00:19:02 +00:00
|
|
|
#include "m_property.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
|
|
|
#include "common/common.h"
|
2006-03-22 00:19:02 +00:00
|
|
|
|
2018-03-23 14:06:27 +00:00
|
|
|
static int m_property_multiply(struct mp_log *log,
|
|
|
|
const struct m_property *prop_list,
|
|
|
|
const char *property, double f, void *ctx)
|
|
|
|
{
|
|
|
|
union m_option_value val = {0};
|
|
|
|
struct m_option opt = {0};
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = m_property_do(log, prop_list, property, M_PROPERTY_GET_CONSTRICTED_TYPE,
|
|
|
|
&opt, ctx);
|
|
|
|
if (r != M_PROPERTY_OK)
|
|
|
|
return r;
|
|
|
|
assert(opt.type);
|
|
|
|
|
|
|
|
if (!opt.type->multiply)
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
r = m_property_do(log, prop_list, property, M_PROPERTY_GET, &val, ctx);
|
|
|
|
if (r != M_PROPERTY_OK)
|
|
|
|
return r;
|
|
|
|
opt.type->multiply(&opt, &val, f);
|
|
|
|
r = m_property_do(log, prop_list, property, M_PROPERTY_SET, &val, ctx);
|
|
|
|
m_option_free(&opt, &val);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2016-09-01 18:00:43 +00:00
|
|
|
struct m_property *m_property_list_find(const struct m_property *list,
|
|
|
|
const char *name)
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
{
|
|
|
|
for (int n = 0; list && list[n].name; n++) {
|
|
|
|
if (strcmp(list[n].name, name) == 0)
|
|
|
|
return (struct m_property *)&list[n];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_action(const struct m_property *prop_list, const char *name,
|
2011-07-03 12:42:04 +00:00
|
|
|
int action, void *arg, void *ctx)
|
|
|
|
{
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
struct m_property *prop;
|
2013-07-25 22:18:37 +00:00
|
|
|
struct m_property_action_arg ka;
|
2015-11-06 20:12:20 +00:00
|
|
|
const char *sep = strchr(name, '/');
|
|
|
|
if (sep && sep[1]) {
|
|
|
|
char base[128];
|
|
|
|
snprintf(base, sizeof(base), "%.*s", (int)(sep - name), name);
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
prop = m_property_list_find(prop_list, base);
|
2013-07-25 22:18:37 +00:00
|
|
|
ka = (struct m_property_action_arg) {
|
2012-09-21 10:19:59 +00:00
|
|
|
.key = sep + 1,
|
|
|
|
.action = action,
|
|
|
|
.arg = arg,
|
|
|
|
};
|
2007-05-29 21:49:39 +00:00
|
|
|
action = M_PROPERTY_KEY_ACTION;
|
|
|
|
arg = &ka;
|
|
|
|
} else
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
prop = m_property_list_find(prop_list, name);
|
2011-07-03 12:42:04 +00:00
|
|
|
if (!prop)
|
|
|
|
return M_PROPERTY_UNKNOWN;
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
return prop->call(ctx, prop, action, arg);
|
2006-03-22 00:19:02 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 18:36:33 +00:00
|
|
|
// (as a hack, log can be NULL on read-only paths)
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
int m_property_do(struct mp_log *log, const struct m_property *prop_list,
|
2015-05-22 18:08:04 +00:00
|
|
|
const char *name, int action, void *arg, void *ctx)
|
2011-07-03 12:42:04 +00:00
|
|
|
{
|
2012-09-18 14:08:17 +00:00
|
|
|
union m_option_value val = {0};
|
2006-03-22 00:19:02 +00:00
|
|
|
int r;
|
2012-09-21 10:15:47 +00:00
|
|
|
|
2012-09-21 12:05:52 +00:00
|
|
|
struct m_option opt = {0};
|
2012-09-21 10:15:47 +00:00
|
|
|
r = do_action(prop_list, name, M_PROPERTY_GET_TYPE, &opt, ctx);
|
|
|
|
if (r <= 0)
|
|
|
|
return r;
|
2012-09-21 12:05:52 +00:00
|
|
|
assert(opt.type);
|
2006-03-22 00:19:02 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
switch (action) {
|
2012-09-21 10:15:47 +00:00
|
|
|
case M_PROPERTY_PRINT: {
|
2011-07-03 12:42:04 +00:00
|
|
|
if ((r = do_action(prop_list, name, M_PROPERTY_PRINT, arg, ctx)) >= 0)
|
2007-05-29 21:49:39 +00:00
|
|
|
return r;
|
2012-09-18 14:08:17 +00:00
|
|
|
// Fallback to m_option
|
|
|
|
if ((r = do_action(prop_list, name, M_PROPERTY_GET, &val, ctx)) <= 0)
|
2012-09-18 13:31:46 +00:00
|
|
|
return r;
|
2012-09-21 12:05:52 +00:00
|
|
|
char *str = m_option_pretty_print(&opt, &val);
|
|
|
|
m_option_free(&opt, &val);
|
2012-09-18 13:31:46 +00:00
|
|
|
*(char **)arg = str;
|
|
|
|
return str != NULL;
|
2012-09-21 10:15:47 +00:00
|
|
|
}
|
2012-09-22 06:04:08 +00:00
|
|
|
case M_PROPERTY_GET_STRING: {
|
2012-09-18 14:08:17 +00:00
|
|
|
if ((r = do_action(prop_list, name, M_PROPERTY_GET, &val, ctx)) <= 0)
|
2007-05-29 21:49:39 +00:00
|
|
|
return r;
|
2012-09-21 12:05:52 +00:00
|
|
|
char *str = m_option_print(&opt, &val);
|
|
|
|
m_option_free(&opt, &val);
|
2011-07-03 17:04:21 +00:00
|
|
|
*(char **)arg = str;
|
|
|
|
return str != NULL;
|
2012-09-21 10:15:47 +00:00
|
|
|
}
|
2012-09-22 06:04:08 +00:00
|
|
|
case M_PROPERTY_SET_STRING: {
|
2016-04-15 09:31:24 +00:00
|
|
|
struct mpv_node node = { .format = MPV_FORMAT_STRING, .u.string = arg };
|
2016-04-15 20:10:19 +00:00
|
|
|
return m_property_do(log, prop_list, name, M_PROPERTY_SET_NODE, &node, ctx);
|
2012-09-21 10:15:47 +00:00
|
|
|
}
|
2018-03-23 14:06:27 +00:00
|
|
|
case M_PROPERTY_MULTIPLY: {
|
|
|
|
return m_property_multiply(log, prop_list, name, *(double *)arg, ctx);
|
|
|
|
}
|
2012-09-21 10:15:47 +00:00
|
|
|
case M_PROPERTY_SWITCH: {
|
2013-12-21 18:36:33 +00:00
|
|
|
if (!log)
|
|
|
|
return M_PROPERTY_ERROR;
|
2012-09-22 04:15:36 +00:00
|
|
|
struct m_property_switch_arg *sarg = arg;
|
2012-09-18 12:00:08 +00:00
|
|
|
if ((r = do_action(prop_list, name, M_PROPERTY_SWITCH, arg, ctx)) !=
|
|
|
|
M_PROPERTY_NOT_IMPLEMENTED)
|
|
|
|
return r;
|
|
|
|
// Fallback to m_option
|
2016-09-18 15:55:27 +00:00
|
|
|
r = m_property_do(log, prop_list, name, M_PROPERTY_GET_CONSTRICTED_TYPE,
|
|
|
|
&opt, ctx);
|
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.
2016-09-18 14:06:12 +00:00
|
|
|
if (r <= 0)
|
|
|
|
return r;
|
|
|
|
assert(opt.type);
|
2012-09-21 12:05:52 +00:00
|
|
|
if (!opt.type->add)
|
2012-09-18 12:00:08 +00:00
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
2012-09-18 14:08:17 +00:00
|
|
|
if ((r = do_action(prop_list, name, M_PROPERTY_GET, &val, ctx)) <= 0)
|
2012-09-18 12:00:08 +00:00
|
|
|
return r;
|
2012-09-22 04:15:36 +00:00
|
|
|
opt.type->add(&opt, &val, sarg->inc, sarg->wrap);
|
2012-09-18 14:08:17 +00:00
|
|
|
r = do_action(prop_list, name, M_PROPERTY_SET, &val, ctx);
|
2012-09-21 12:05:52 +00:00
|
|
|
m_option_free(&opt, &val);
|
2012-09-18 12:00:08 +00:00
|
|
|
return r;
|
2012-09-21 10:15:47 +00:00
|
|
|
}
|
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.
2016-09-18 14:06:12 +00:00
|
|
|
case M_PROPERTY_GET_CONSTRICTED_TYPE: {
|
|
|
|
if ((r = do_action(prop_list, name, action, arg, ctx)) >= 0)
|
|
|
|
return r;
|
|
|
|
if ((r = do_action(prop_list, name, M_PROPERTY_GET_TYPE, arg, ctx)) >= 0)
|
|
|
|
return r;
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|
2012-09-21 10:15:47 +00:00
|
|
|
case M_PROPERTY_SET: {
|
2012-09-18 15:05:11 +00:00
|
|
|
return do_action(prop_list, name, M_PROPERTY_SET, arg, ctx);
|
2006-03-22 00:19:02 +00:00
|
|
|
}
|
2014-02-24 19:10:26 +00:00
|
|
|
case M_PROPERTY_GET_NODE: {
|
|
|
|
if ((r = do_action(prop_list, name, M_PROPERTY_GET_NODE, arg, ctx)) !=
|
|
|
|
M_PROPERTY_NOT_IMPLEMENTED)
|
|
|
|
return r;
|
|
|
|
if ((r = do_action(prop_list, name, M_PROPERTY_GET, &val, ctx)) <= 0)
|
|
|
|
return r;
|
|
|
|
struct mpv_node *node = arg;
|
|
|
|
int err = m_option_get_node(&opt, NULL, node, &val);
|
|
|
|
if (err == M_OPT_UNKNOWN) {
|
|
|
|
r = M_PROPERTY_NOT_IMPLEMENTED;
|
2014-11-21 09:07:06 +00:00
|
|
|
} else if (err < 0) {
|
2014-02-24 19:10:26 +00:00
|
|
|
r = M_PROPERTY_INVALID_FORMAT;
|
|
|
|
} else {
|
|
|
|
r = M_PROPERTY_OK;
|
|
|
|
}
|
|
|
|
m_option_free(&opt, &val);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
case M_PROPERTY_SET_NODE: {
|
2016-04-15 09:31:24 +00:00
|
|
|
if (!log)
|
|
|
|
return M_PROPERTY_ERROR;
|
2014-02-24 19:10:26 +00:00
|
|
|
if ((r = do_action(prop_list, name, M_PROPERTY_SET_NODE, arg, ctx)) !=
|
|
|
|
M_PROPERTY_NOT_IMPLEMENTED)
|
|
|
|
return r;
|
2016-04-15 09:31:24 +00:00
|
|
|
int err = m_option_set_node_or_string(log, &opt, name, &val, arg);
|
2014-02-24 19:10:26 +00:00
|
|
|
if (err == M_OPT_UNKNOWN) {
|
|
|
|
r = M_PROPERTY_NOT_IMPLEMENTED;
|
2014-02-26 19:32:35 +00:00
|
|
|
} else if (err < 0) {
|
2014-02-24 19:10:26 +00:00
|
|
|
r = M_PROPERTY_INVALID_FORMAT;
|
|
|
|
} else {
|
|
|
|
r = do_action(prop_list, name, M_PROPERTY_SET, &val, ctx);
|
|
|
|
}
|
|
|
|
m_option_free(&opt, &val);
|
|
|
|
return r;
|
|
|
|
}
|
2012-09-21 10:15:47 +00:00
|
|
|
default:
|
|
|
|
return do_action(prop_list, name, action, arg, ctx);
|
|
|
|
}
|
2006-03-22 00:19:02 +00:00
|
|
|
}
|
|
|
|
|
2014-03-30 11:41:03 +00:00
|
|
|
bool m_property_split_path(const char *path, bstr *prefix, char **rem)
|
|
|
|
{
|
|
|
|
char *next = strchr(path, '/');
|
|
|
|
if (next) {
|
|
|
|
*prefix = bstr_splice(bstr0(path), 0, next - path);
|
|
|
|
*rem = next + 1;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
*prefix = bstr0(path);
|
|
|
|
*rem = "";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-30 11:50:23 +00:00
|
|
|
// If *action is M_PROPERTY_KEY_ACTION, but the associated path is "", then
|
|
|
|
// make this into a top-level action.
|
|
|
|
static void m_property_unkey(int *action, void **arg)
|
|
|
|
{
|
|
|
|
if (*action == M_PROPERTY_KEY_ACTION) {
|
|
|
|
struct m_property_action_arg *ka = *arg;
|
|
|
|
if (!ka->key[0]) {
|
|
|
|
*action = ka->action;
|
|
|
|
*arg = ka->arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
static int m_property_do_bstr(const struct m_property *prop_list, bstr name,
|
commands: change property expansion format string
This affects property format strings like they are used in the
"show_text" input command, for --playing-msg, and other places.
To quote the documentation comment on m_properties_expand_string():
${NAME} is expanded to the value of property NAME.
If NAME starts with '=', use the raw value of the property.
${NAME:STR} expands to the property, or STR if the property is not
available.
${?NAME:STR} expands to STR if the property is available.
${!NAME:STR} expands to STR if the property is not available.
STR is recursively expanded using the same rules.
"$$" can be used to escape "$", and "$}" to escape "}".
"$>" disables parsing of "$" for the rest of the string.
Most importantly, "?(property:str)" becomes "${?property:str}".
Make the simple fallback case easier, e.g. "${property:fallback}"
instead of "${property}?(!property:fallback)".
Add the ability to escape the format meta characters. "$" is used for
escaping, because escaping with "\" is taken by the commands parser in
the layer below. "$>" can be used to disable interpretation of format
strings (of course escapes by the commands parser can't be canceled).
By default, properties which are unavailable or don't exist are turned
into a string signaling the status (e.g. "(unavailable)"), instead of
an empty string. If an empty string is desired, this has to be done
explicitly: "${property:}" (the fallback part is an empty string). Raw
properties still return an empty string on error.
m_properties_expand_string() now returns a talloc'ed pointer, instead of
a malloc'ed one.
2012-09-23 21:00:54 +00:00
|
|
|
int action, void *arg, void *ctx)
|
|
|
|
{
|
|
|
|
char name0[64];
|
|
|
|
if (name.len >= sizeof(name0))
|
|
|
|
return M_PROPERTY_UNKNOWN;
|
|
|
|
snprintf(name0, sizeof(name0), "%.*s", BSTR_P(name));
|
2013-12-21 18:36:33 +00:00
|
|
|
return m_property_do(NULL, prop_list, name0, action, arg, ctx);
|
commands: change property expansion format string
This affects property format strings like they are used in the
"show_text" input command, for --playing-msg, and other places.
To quote the documentation comment on m_properties_expand_string():
${NAME} is expanded to the value of property NAME.
If NAME starts with '=', use the raw value of the property.
${NAME:STR} expands to the property, or STR if the property is not
available.
${?NAME:STR} expands to STR if the property is available.
${!NAME:STR} expands to STR if the property is not available.
STR is recursively expanded using the same rules.
"$$" can be used to escape "$", and "$}" to escape "}".
"$>" disables parsing of "$" for the rest of the string.
Most importantly, "?(property:str)" becomes "${?property:str}".
Make the simple fallback case easier, e.g. "${property:fallback}"
instead of "${property}?(!property:fallback)".
Add the ability to escape the format meta characters. "$" is used for
escaping, because escaping with "\" is taken by the commands parser in
the layer below. "$>" can be used to disable interpretation of format
strings (of course escapes by the commands parser can't be canceled).
By default, properties which are unavailable or don't exist are turned
into a string signaling the status (e.g. "(unavailable)"), instead of
an empty string. If an empty string is desired, this has to be done
explicitly: "${property:}" (the fallback part is an empty string). Raw
properties still return an empty string on error.
m_properties_expand_string() now returns a talloc'ed pointer, instead of
a malloc'ed one.
2012-09-23 21:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void append_str(char **s, int *len, bstr append)
|
|
|
|
{
|
|
|
|
MP_TARRAY_GROW(NULL, *s, *len + append.len);
|
2015-03-23 17:02:28 +00:00
|
|
|
if (append.len)
|
|
|
|
memcpy(*s + *len, append.start, append.len);
|
commands: change property expansion format string
This affects property format strings like they are used in the
"show_text" input command, for --playing-msg, and other places.
To quote the documentation comment on m_properties_expand_string():
${NAME} is expanded to the value of property NAME.
If NAME starts with '=', use the raw value of the property.
${NAME:STR} expands to the property, or STR if the property is not
available.
${?NAME:STR} expands to STR if the property is available.
${!NAME:STR} expands to STR if the property is not available.
STR is recursively expanded using the same rules.
"$$" can be used to escape "$", and "$}" to escape "}".
"$>" disables parsing of "$" for the rest of the string.
Most importantly, "?(property:str)" becomes "${?property:str}".
Make the simple fallback case easier, e.g. "${property:fallback}"
instead of "${property}?(!property:fallback)".
Add the ability to escape the format meta characters. "$" is used for
escaping, because escaping with "\" is taken by the commands parser in
the layer below. "$>" can be used to disable interpretation of format
strings (of course escapes by the commands parser can't be canceled).
By default, properties which are unavailable or don't exist are turned
into a string signaling the status (e.g. "(unavailable)"), instead of
an empty string. If an empty string is desired, this has to be done
explicitly: "${property:}" (the fallback part is an empty string). Raw
properties still return an empty string on error.
m_properties_expand_string() now returns a talloc'ed pointer, instead of
a malloc'ed one.
2012-09-23 21:00:54 +00:00
|
|
|
*len = *len + append.len;
|
|
|
|
}
|
|
|
|
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
static int expand_property(const struct m_property *prop_list, char **ret,
|
|
|
|
int *ret_len, bstr prop, bool silent_error, void *ctx)
|
2013-09-20 20:26:08 +00:00
|
|
|
{
|
|
|
|
bool cond_yes = bstr_eatstart0(&prop, "?");
|
|
|
|
bool cond_no = !cond_yes && bstr_eatstart0(&prop, "!");
|
2013-09-20 20:53:06 +00:00
|
|
|
bool test = cond_yes || cond_no;
|
2013-09-20 20:26:08 +00:00
|
|
|
bool raw = bstr_eatstart0(&prop, "=");
|
2013-09-20 20:53:06 +00:00
|
|
|
bstr comp_with = {0};
|
|
|
|
bool comp = test && bstr_split_tok(prop, "==", &prop, &comp_with);
|
|
|
|
if (test && !comp)
|
|
|
|
raw = true;
|
|
|
|
int method = raw ? M_PROPERTY_GET_STRING : M_PROPERTY_PRINT;
|
2013-09-20 20:26:08 +00:00
|
|
|
|
|
|
|
char *s = NULL;
|
|
|
|
int r = m_property_do_bstr(prop_list, prop, method, &s, ctx);
|
|
|
|
bool skip;
|
2013-09-20 20:53:06 +00:00
|
|
|
if (comp) {
|
|
|
|
skip = ((s && bstr_equals0(comp_with, s)) != cond_yes);
|
|
|
|
} else if (test) {
|
2013-09-20 20:26:08 +00:00
|
|
|
skip = (!!s != cond_yes);
|
|
|
|
} else {
|
|
|
|
skip = !!s;
|
|
|
|
char *append = s;
|
|
|
|
if (!s && !silent_error && !raw)
|
|
|
|
append = (r == M_PROPERTY_UNAVAILABLE) ? "(unavailable)" : "(error)";
|
|
|
|
append_str(ret, ret_len, bstr0(append));
|
|
|
|
}
|
|
|
|
talloc_free(s);
|
|
|
|
return skip;
|
|
|
|
}
|
|
|
|
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
char *m_properties_expand_string(const struct m_property *prop_list,
|
2013-09-20 21:33:38 +00:00
|
|
|
const char *str0, void *ctx)
|
2011-07-03 12:42:04 +00:00
|
|
|
{
|
commands: change property expansion format string
This affects property format strings like they are used in the
"show_text" input command, for --playing-msg, and other places.
To quote the documentation comment on m_properties_expand_string():
${NAME} is expanded to the value of property NAME.
If NAME starts with '=', use the raw value of the property.
${NAME:STR} expands to the property, or STR if the property is not
available.
${?NAME:STR} expands to STR if the property is available.
${!NAME:STR} expands to STR if the property is not available.
STR is recursively expanded using the same rules.
"$$" can be used to escape "$", and "$}" to escape "}".
"$>" disables parsing of "$" for the rest of the string.
Most importantly, "?(property:str)" becomes "${?property:str}".
Make the simple fallback case easier, e.g. "${property:fallback}"
instead of "${property}?(!property:fallback)".
Add the ability to escape the format meta characters. "$" is used for
escaping, because escaping with "\" is taken by the commands parser in
the layer below. "$>" can be used to disable interpretation of format
strings (of course escapes by the commands parser can't be canceled).
By default, properties which are unavailable or don't exist are turned
into a string signaling the status (e.g. "(unavailable)"), instead of
an empty string. If an empty string is desired, this has to be done
explicitly: "${property:}" (the fallback part is an empty string). Raw
properties still return an empty string on error.
m_properties_expand_string() now returns a talloc'ed pointer, instead of
a malloc'ed one.
2012-09-23 21:00:54 +00:00
|
|
|
char *ret = NULL;
|
|
|
|
int ret_len = 0;
|
|
|
|
bool skip = false;
|
|
|
|
int level = 0, skip_level = 0;
|
|
|
|
bstr str = bstr0(str0);
|
|
|
|
|
|
|
|
while (str.len) {
|
|
|
|
if (level > 0 && bstr_eatstart0(&str, "}")) {
|
|
|
|
if (skip && level <= skip_level)
|
|
|
|
skip = false;
|
|
|
|
level--;
|
|
|
|
} else if (bstr_startswith0(str, "${") && bstr_find0(str, "}") >= 0) {
|
|
|
|
str = bstr_cut(str, 2);
|
|
|
|
level++;
|
|
|
|
|
|
|
|
// Assume ":" and "}" can't be part of the property name
|
|
|
|
// => if ":" comes before "}", it must be for the fallback
|
|
|
|
int term_pos = bstrcspn(str, ":}");
|
|
|
|
bstr name = bstr_splice(str, 0, term_pos < 0 ? str.len : term_pos);
|
|
|
|
str = bstr_cut(str, term_pos);
|
|
|
|
bool have_fallback = bstr_eatstart0(&str, ":");
|
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
if (!skip) {
|
2013-09-20 20:26:08 +00:00
|
|
|
skip = expand_property(prop_list, &ret, &ret_len, name,
|
|
|
|
have_fallback, ctx);
|
commands: change property expansion format string
This affects property format strings like they are used in the
"show_text" input command, for --playing-msg, and other places.
To quote the documentation comment on m_properties_expand_string():
${NAME} is expanded to the value of property NAME.
If NAME starts with '=', use the raw value of the property.
${NAME:STR} expands to the property, or STR if the property is not
available.
${?NAME:STR} expands to STR if the property is available.
${!NAME:STR} expands to STR if the property is not available.
STR is recursively expanded using the same rules.
"$$" can be used to escape "$", and "$}" to escape "}".
"$>" disables parsing of "$" for the rest of the string.
Most importantly, "?(property:str)" becomes "${?property:str}".
Make the simple fallback case easier, e.g. "${property:fallback}"
instead of "${property}?(!property:fallback)".
Add the ability to escape the format meta characters. "$" is used for
escaping, because escaping with "\" is taken by the commands parser in
the layer below. "$>" can be used to disable interpretation of format
strings (of course escapes by the commands parser can't be canceled).
By default, properties which are unavailable or don't exist are turned
into a string signaling the status (e.g. "(unavailable)"), instead of
an empty string. If an empty string is desired, this has to be done
explicitly: "${property:}" (the fallback part is an empty string). Raw
properties still return an empty string on error.
m_properties_expand_string() now returns a talloc'ed pointer, instead of
a malloc'ed one.
2012-09-23 21:00:54 +00:00
|
|
|
if (skip)
|
|
|
|
skip_level = level;
|
2006-03-22 00:19:02 +00:00
|
|
|
}
|
commands: change property expansion format string
This affects property format strings like they are used in the
"show_text" input command, for --playing-msg, and other places.
To quote the documentation comment on m_properties_expand_string():
${NAME} is expanded to the value of property NAME.
If NAME starts with '=', use the raw value of the property.
${NAME:STR} expands to the property, or STR if the property is not
available.
${?NAME:STR} expands to STR if the property is available.
${!NAME:STR} expands to STR if the property is not available.
STR is recursively expanded using the same rules.
"$$" can be used to escape "$", and "$}" to escape "}".
"$>" disables parsing of "$" for the rest of the string.
Most importantly, "?(property:str)" becomes "${?property:str}".
Make the simple fallback case easier, e.g. "${property:fallback}"
instead of "${property}?(!property:fallback)".
Add the ability to escape the format meta characters. "$" is used for
escaping, because escaping with "\" is taken by the commands parser in
the layer below. "$>" can be used to disable interpretation of format
strings (of course escapes by the commands parser can't be canceled).
By default, properties which are unavailable or don't exist are turned
into a string signaling the status (e.g. "(unavailable)"), instead of
an empty string. If an empty string is desired, this has to be done
explicitly: "${property:}" (the fallback part is an empty string). Raw
properties still return an empty string on error.
m_properties_expand_string() now returns a talloc'ed pointer, instead of
a malloc'ed one.
2012-09-23 21:00:54 +00:00
|
|
|
} else if (level == 0 && bstr_eatstart0(&str, "$>")) {
|
|
|
|
append_str(&ret, &ret_len, str);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
char c;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
commands: change property expansion format string
This affects property format strings like they are used in the
"show_text" input command, for --playing-msg, and other places.
To quote the documentation comment on m_properties_expand_string():
${NAME} is expanded to the value of property NAME.
If NAME starts with '=', use the raw value of the property.
${NAME:STR} expands to the property, or STR if the property is not
available.
${?NAME:STR} expands to STR if the property is available.
${!NAME:STR} expands to STR if the property is not available.
STR is recursively expanded using the same rules.
"$$" can be used to escape "$", and "$}" to escape "}".
"$>" disables parsing of "$" for the rest of the string.
Most importantly, "?(property:str)" becomes "${?property:str}".
Make the simple fallback case easier, e.g. "${property:fallback}"
instead of "${property}?(!property:fallback)".
Add the ability to escape the format meta characters. "$" is used for
escaping, because escaping with "\" is taken by the commands parser in
the layer below. "$>" can be used to disable interpretation of format
strings (of course escapes by the commands parser can't be canceled).
By default, properties which are unavailable or don't exist are turned
into a string signaling the status (e.g. "(unavailable)"), instead of
an empty string. If an empty string is desired, this has to be done
explicitly: "${property:}" (the fallback part is an empty string). Raw
properties still return an empty string on error.
m_properties_expand_string() now returns a talloc'ed pointer, instead of
a malloc'ed one.
2012-09-23 21:00:54 +00:00
|
|
|
// Other combinations, e.g. "$x", are added verbatim
|
|
|
|
if (bstr_eatstart0(&str, "$$")) {
|
|
|
|
c = '$';
|
|
|
|
} else if (bstr_eatstart0(&str, "$}")) {
|
|
|
|
c = '}';
|
|
|
|
} else {
|
|
|
|
c = str.start[0];
|
|
|
|
str = bstr_cut(str, 1);
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
commands: change property expansion format string
This affects property format strings like they are used in the
"show_text" input command, for --playing-msg, and other places.
To quote the documentation comment on m_properties_expand_string():
${NAME} is expanded to the value of property NAME.
If NAME starts with '=', use the raw value of the property.
${NAME:STR} expands to the property, or STR if the property is not
available.
${?NAME:STR} expands to STR if the property is available.
${!NAME:STR} expands to STR if the property is not available.
STR is recursively expanded using the same rules.
"$$" can be used to escape "$", and "$}" to escape "}".
"$>" disables parsing of "$" for the rest of the string.
Most importantly, "?(property:str)" becomes "${?property:str}".
Make the simple fallback case easier, e.g. "${property:fallback}"
instead of "${property}?(!property:fallback)".
Add the ability to escape the format meta characters. "$" is used for
escaping, because escaping with "\" is taken by the commands parser in
the layer below. "$>" can be used to disable interpretation of format
strings (of course escapes by the commands parser can't be canceled).
By default, properties which are unavailable or don't exist are turned
into a string signaling the status (e.g. "(unavailable)"), instead of
an empty string. If an empty string is desired, this has to be done
explicitly: "${property:}" (the fallback part is an empty string). Raw
properties still return an empty string on error.
m_properties_expand_string() now returns a talloc'ed pointer, instead of
a malloc'ed one.
2012-09-23 21:00:54 +00:00
|
|
|
if (!skip)
|
|
|
|
MP_TARRAY_APPEND(NULL, ret, ret_len, c);
|
2006-03-22 00:19:02 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
commands: change property expansion format string
This affects property format strings like they are used in the
"show_text" input command, for --playing-msg, and other places.
To quote the documentation comment on m_properties_expand_string():
${NAME} is expanded to the value of property NAME.
If NAME starts with '=', use the raw value of the property.
${NAME:STR} expands to the property, or STR if the property is not
available.
${?NAME:STR} expands to STR if the property is available.
${!NAME:STR} expands to STR if the property is not available.
STR is recursively expanded using the same rules.
"$$" can be used to escape "$", and "$}" to escape "}".
"$>" disables parsing of "$" for the rest of the string.
Most importantly, "?(property:str)" becomes "${?property:str}".
Make the simple fallback case easier, e.g. "${property:fallback}"
instead of "${property}?(!property:fallback)".
Add the ability to escape the format meta characters. "$" is used for
escaping, because escaping with "\" is taken by the commands parser in
the layer below. "$>" can be used to disable interpretation of format
strings (of course escapes by the commands parser can't be canceled).
By default, properties which are unavailable or don't exist are turned
into a string signaling the status (e.g. "(unavailable)"), instead of
an empty string. If an empty string is desired, this has to be done
explicitly: "${property:}" (the fallback part is an empty string). Raw
properties still return an empty string on error.
m_properties_expand_string() now returns a talloc'ed pointer, instead of
a malloc'ed one.
2012-09-23 21:00:54 +00:00
|
|
|
MP_TARRAY_APPEND(NULL, ret, ret_len, '\0');
|
2006-03-22 00:19:02 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-12-21 18:36:33 +00:00
|
|
|
void m_properties_print_help_list(struct mp_log *log,
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
const struct m_property *list)
|
2011-07-03 12:42:04 +00:00
|
|
|
{
|
2014-04-10 23:27:57 +00:00
|
|
|
int count = 0;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2014-04-10 23:27:57 +00:00
|
|
|
mp_info(log, "Name\n\n");
|
|
|
|
for (int i = 0; list[i].name; i++) {
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
const struct m_property *p = &list[i];
|
|
|
|
mp_info(log, " %s\n", p->name);
|
2006-03-22 16:35:17 +00:00
|
|
|
count++;
|
|
|
|
}
|
2013-12-21 18:36:33 +00:00
|
|
|
mp_info(log, "\nTotal: %d properties\n", count);
|
2006-03-22 16:35:17 +00:00
|
|
|
}
|
|
|
|
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
int m_property_flag_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};
|
|
|
|
return M_PROPERTY_OK;
|
|
|
|
}
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
int m_property_int_ro(int action, void *arg, int var)
|
2011-07-03 12:42:04 +00:00
|
|
|
{
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
switch (action) {
|
|
|
|
case M_PROPERTY_GET:
|
2011-07-03 12:42:04 +00:00
|
|
|
*(int *)arg = var;
|
2012-09-18 18:07:24 +00:00
|
|
|
return M_PROPERTY_OK;
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
case M_PROPERTY_GET_TYPE:
|
|
|
|
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_INT};
|
|
|
|
return M_PROPERTY_OK;
|
2006-03-22 00:19:02 +00:00
|
|
|
}
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
int m_property_int64_ro(int action, void* arg, int64_t var)
|
2012-10-14 21:08:39 +00:00
|
|
|
{
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
switch (action) {
|
|
|
|
case M_PROPERTY_GET:
|
2012-10-14 21:08:39 +00:00
|
|
|
*(int64_t *)arg = var;
|
|
|
|
return M_PROPERTY_OK;
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
case M_PROPERTY_GET_TYPE:
|
|
|
|
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_INT64};
|
|
|
|
return M_PROPERTY_OK;
|
2012-10-14 21:08:39 +00:00
|
|
|
}
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
int m_property_float_ro(int action, void *arg, float var)
|
2011-07-03 12:42:04 +00:00
|
|
|
{
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
switch (action) {
|
|
|
|
case M_PROPERTY_GET:
|
2011-07-03 12:42:04 +00:00
|
|
|
*(float *)arg = var;
|
2012-09-18 18:07:24 +00:00
|
|
|
return M_PROPERTY_OK;
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
case M_PROPERTY_GET_TYPE:
|
|
|
|
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_FLOAT};
|
|
|
|
return M_PROPERTY_OK;
|
2006-03-22 00:19:02 +00:00
|
|
|
}
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
int m_property_double_ro(int action, void *arg, double var)
|
2011-07-03 12:42:04 +00:00
|
|
|
{
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
switch (action) {
|
|
|
|
case M_PROPERTY_GET:
|
2011-07-03 12:42:04 +00:00
|
|
|
*(double *)arg = var;
|
2012-09-18 18:07:24 +00:00
|
|
|
return M_PROPERTY_OK;
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
case M_PROPERTY_GET_TYPE:
|
|
|
|
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_DOUBLE};
|
|
|
|
return M_PROPERTY_OK;
|
2006-03-22 00:19:02 +00:00
|
|
|
}
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|
2012-10-14 21:08:39 +00:00
|
|
|
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
int m_property_strdup_ro(int action, void* arg, const char *var)
|
2012-10-14 21:08:39 +00:00
|
|
|
{
|
2014-09-01 19:50:54 +00:00
|
|
|
if (!var)
|
|
|
|
return M_PROPERTY_UNAVAILABLE;
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
switch (action) {
|
|
|
|
case M_PROPERTY_GET:
|
2012-10-14 21:08:39 +00:00
|
|
|
*(char **)arg = talloc_strdup(NULL, var);
|
|
|
|
return M_PROPERTY_OK;
|
command: redo the property type
Instead of absuing m_option to store the property list, introduce a
separate type for properties. m_option is still used to handle data
types. The property declaration itself now never contains the option
type, and instead it's always queried with M_PROPERTY_GET_TYPE. (This
was already done with some properties, now all properties use it.)
This also fixes that the function signatures did not match the function
type with which these functions were called. They were called as:
int (*)(const m_option_t*, int, void*, void*)
but the actual function signatures were:
int (*)(m_option_t*, int, void*, MPContext *)
Two arguments were mismatched.
This adds one line per property implementation. With additional the
reordering of the parameters, this makes most of the changes in this
commit.
2014-06-13 00:11:39 +00:00
|
|
|
case M_PROPERTY_GET_TYPE:
|
|
|
|
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_STRING};
|
|
|
|
return M_PROPERTY_OK;
|
2012-10-14 21:08:39 +00:00
|
|
|
}
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|
2014-02-15 15:41:48 +00:00
|
|
|
|
|
|
|
// This allows you to make a list of values (like from a struct) available
|
|
|
|
// as a number of sub-properties. The property list is set up with the current
|
|
|
|
// property values on the stack before calling this function.
|
|
|
|
// This does not support write access.
|
|
|
|
int m_property_read_sub(const struct m_sub_property *props, int action, void *arg)
|
|
|
|
{
|
2014-11-13 16:25:04 +00:00
|
|
|
m_property_unkey(&action, &arg);
|
2014-02-15 15:41:48 +00:00
|
|
|
switch (action) {
|
|
|
|
case M_PROPERTY_GET_TYPE:
|
2014-02-24 19:18:06 +00:00
|
|
|
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_NODE};
|
2014-02-15 15:41:48 +00:00
|
|
|
return M_PROPERTY_OK;
|
2014-02-24 19:18:06 +00:00
|
|
|
case M_PROPERTY_GET: {
|
|
|
|
struct mpv_node node;
|
|
|
|
node.format = MPV_FORMAT_NODE_MAP;
|
|
|
|
node.u.list = talloc_zero(NULL, mpv_node_list);
|
|
|
|
mpv_node_list *list = node.u.list;
|
|
|
|
for (int n = 0; props && props[n].name; n++) {
|
|
|
|
const struct m_sub_property *prop = &props[n];
|
|
|
|
if (prop->unavailable)
|
|
|
|
continue;
|
|
|
|
MP_TARRAY_GROW(list, list->values, list->num);
|
|
|
|
MP_TARRAY_GROW(list, list->keys, list->num);
|
|
|
|
mpv_node *val = &list->values[list->num];
|
2014-11-13 16:25:59 +00:00
|
|
|
if (m_option_get_node(&prop->type, list, val, (void*)&prop->value) < 0)
|
|
|
|
{
|
|
|
|
char *s = m_option_print(&prop->type, &prop->value);
|
2014-02-24 19:18:06 +00:00
|
|
|
val->format = MPV_FORMAT_STRING;
|
|
|
|
val->u.string = talloc_steal(list, s);
|
|
|
|
}
|
|
|
|
list->keys[list->num] = (char *)prop->name;
|
|
|
|
list->num++;
|
|
|
|
}
|
|
|
|
*(struct mpv_node *)arg = node;
|
|
|
|
return M_PROPERTY_OK;
|
|
|
|
}
|
2014-02-15 15:41:48 +00:00
|
|
|
case M_PROPERTY_PRINT: {
|
|
|
|
// Output "something" - what it really should return is not yet decided.
|
|
|
|
// It should probably be something that is easy to consume by slave
|
|
|
|
// mode clients. (M_PROPERTY_PRINT on the other hand can return this
|
|
|
|
// as human readable version just fine).
|
|
|
|
char *res = NULL;
|
|
|
|
for (int n = 0; props && props[n].name; n++) {
|
|
|
|
const struct m_sub_property *prop = &props[n];
|
|
|
|
if (prop->unavailable)
|
|
|
|
continue;
|
2014-11-13 16:25:59 +00:00
|
|
|
char *s = m_option_print(&prop->type, &prop->value);
|
2014-02-15 15:41:48 +00:00
|
|
|
ta_xasprintf_append(&res, "%s=%s\n", prop->name, s);
|
|
|
|
talloc_free(s);
|
|
|
|
}
|
|
|
|
*(char **)arg = res;
|
|
|
|
return M_PROPERTY_OK;
|
|
|
|
}
|
|
|
|
case M_PROPERTY_KEY_ACTION: {
|
|
|
|
struct m_property_action_arg *ka = arg;
|
|
|
|
const struct m_sub_property *prop = NULL;
|
|
|
|
for (int n = 0; props && props[n].name; n++) {
|
|
|
|
if (strcmp(props[n].name, ka->key) == 0) {
|
|
|
|
prop = &props[n];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!prop)
|
|
|
|
return M_PROPERTY_UNKNOWN;
|
|
|
|
if (prop->unavailable)
|
|
|
|
return M_PROPERTY_UNAVAILABLE;
|
|
|
|
switch (ka->action) {
|
|
|
|
case M_PROPERTY_GET: {
|
2014-11-13 16:25:59 +00:00
|
|
|
memset(ka->arg, 0, prop->type.type->size);
|
|
|
|
m_option_copy(&prop->type, ka->arg, &prop->value);
|
2014-02-15 15:41:48 +00:00
|
|
|
return M_PROPERTY_OK;
|
|
|
|
}
|
|
|
|
case M_PROPERTY_GET_TYPE:
|
2014-11-13 16:25:59 +00:00
|
|
|
*(struct m_option *)ka->arg = prop->type;
|
2014-02-15 15:41:48 +00:00
|
|
|
return M_PROPERTY_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|
2014-02-15 15:49:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Make a list of items available as indexed sub-properties. E.g. you can access
|
|
|
|
// item 0 as "property/0", item 1 as "property/1", etc., where each of these
|
|
|
|
// properties is redirected to the get_item(0, ...), get_item(1, ...), callback.
|
|
|
|
// Additionally, the number of entries is made available as "property/count".
|
|
|
|
// action, arg: property access.
|
|
|
|
// count: number of items.
|
|
|
|
// get_item: callback to access a single item.
|
|
|
|
// ctx: userdata passed to get_item.
|
|
|
|
int m_property_read_list(int action, void *arg, int count,
|
|
|
|
m_get_item_cb get_item, void *ctx)
|
|
|
|
{
|
2014-03-30 11:50:23 +00:00
|
|
|
m_property_unkey(&action, &arg);
|
2014-02-15 15:49:28 +00:00
|
|
|
switch (action) {
|
|
|
|
case M_PROPERTY_GET_TYPE:
|
2014-02-24 19:18:06 +00:00
|
|
|
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_NODE};
|
2014-02-15 15:49:28 +00:00
|
|
|
return M_PROPERTY_OK;
|
2014-02-24 19:18:06 +00:00
|
|
|
case M_PROPERTY_GET: {
|
|
|
|
struct mpv_node node;
|
|
|
|
node.format = MPV_FORMAT_NODE_ARRAY;
|
|
|
|
node.u.list = talloc_zero(NULL, mpv_node_list);
|
|
|
|
node.u.list->num = count;
|
|
|
|
node.u.list->values = talloc_array(node.u.list, mpv_node, count);
|
|
|
|
for (int n = 0; n < count; n++) {
|
|
|
|
struct mpv_node *sub = &node.u.list->values[n];
|
|
|
|
sub->format = MPV_FORMAT_NONE;
|
|
|
|
int r;
|
|
|
|
r = get_item(n, M_PROPERTY_GET_NODE, sub, ctx);
|
|
|
|
if (r == M_PROPERTY_NOT_IMPLEMENTED) {
|
|
|
|
struct m_option opt = {0};
|
|
|
|
r = get_item(n, M_PROPERTY_GET_TYPE, &opt, ctx);
|
|
|
|
if (r != M_PROPERTY_OK)
|
|
|
|
goto err;
|
|
|
|
union m_option_value val = {0};
|
|
|
|
r = get_item(n, M_PROPERTY_GET, &val, ctx);
|
|
|
|
if (r != M_PROPERTY_OK)
|
|
|
|
goto err;
|
|
|
|
m_option_get_node(&opt, node.u.list, sub, &val);
|
|
|
|
m_option_free(&opt, &val);
|
|
|
|
err: ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*(struct mpv_node *)arg = node;
|
|
|
|
return M_PROPERTY_OK;
|
|
|
|
}
|
2014-02-15 15:49:28 +00:00
|
|
|
case M_PROPERTY_PRINT: {
|
|
|
|
// See m_property_read_sub() remarks.
|
|
|
|
char *res = NULL;
|
|
|
|
for (int n = 0; n < count; n++) {
|
|
|
|
char *s = NULL;
|
|
|
|
int r = get_item(n, M_PROPERTY_PRINT, &s, ctx);
|
|
|
|
if (r != M_PROPERTY_OK) {
|
|
|
|
talloc_free(res);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
ta_xasprintf_append(&res, "%d: %s\n", n, s);
|
|
|
|
talloc_free(s);
|
|
|
|
}
|
|
|
|
*(char **)arg = res;
|
|
|
|
return M_PROPERTY_OK;
|
|
|
|
}
|
|
|
|
case M_PROPERTY_KEY_ACTION: {
|
|
|
|
struct m_property_action_arg *ka = arg;
|
|
|
|
if (strcmp(ka->key, "count") == 0) {
|
|
|
|
switch (ka->action) {
|
|
|
|
case M_PROPERTY_GET_TYPE: {
|
2014-02-21 12:18:50 +00:00
|
|
|
struct m_option opt = {.type = CONF_TYPE_INT};
|
2014-02-15 15:49:28 +00:00
|
|
|
*(struct m_option *)ka->arg = opt;
|
|
|
|
return M_PROPERTY_OK;
|
|
|
|
}
|
|
|
|
case M_PROPERTY_GET:
|
|
|
|
*(int *)ka->arg = MPMAX(0, count);
|
|
|
|
return M_PROPERTY_OK;
|
|
|
|
}
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
// This is expected of the form "123" or "123/rest"
|
|
|
|
char *next = strchr(ka->key, '/');
|
|
|
|
char *end = NULL;
|
2014-03-30 11:29:56 +00:00
|
|
|
const char *key_end = ka->key + strlen(ka->key);
|
2014-02-15 15:49:28 +00:00
|
|
|
long int item = strtol(ka->key, &end, 10);
|
|
|
|
// not a number, trailing characters, etc.
|
2014-03-30 11:29:56 +00:00
|
|
|
if ((end != key_end || ka->key == key_end) && end != next)
|
2014-02-15 15:49:28 +00:00
|
|
|
return M_PROPERTY_UNKNOWN;
|
|
|
|
if (item < 0 || item >= count)
|
|
|
|
return M_PROPERTY_UNKNOWN;
|
|
|
|
if (next) {
|
|
|
|
// Sub-path
|
|
|
|
struct m_property_action_arg n_ka = *ka;
|
|
|
|
n_ka.key = next + 1;
|
|
|
|
return get_item(item, M_PROPERTY_KEY_ACTION, &n_ka, ctx);
|
|
|
|
} else {
|
|
|
|
// Direct query
|
|
|
|
return get_item(item, ka->action, ka->arg, ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|