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
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
2010-01-30 23:24:23 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
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
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2015-04-13 07:36:54 +00:00
|
|
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2010-01-30 23:24:23 +00:00
|
|
|
*/
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#ifndef MPLAYER_M_PROPERTY_H
|
|
|
|
#define MPLAYER_M_PROPERTY_H
|
2006-03-22 00:19:02 +00:00
|
|
|
|
2012-09-22 04:15:36 +00:00
|
|
|
#include <stdbool.h>
|
2012-10-14 21:08:39 +00:00
|
|
|
#include <stdint.h>
|
2012-09-22 04:15:36 +00:00
|
|
|
|
2014-02-15 15:41:48 +00:00
|
|
|
#include "m_option.h"
|
|
|
|
|
2013-12-21 18:36:33 +00:00
|
|
|
struct mp_log;
|
2008-03-04 23:35:24 +00:00
|
|
|
|
2012-09-21 10:19:59 +00:00
|
|
|
enum mp_property_action {
|
|
|
|
// Get the property type. This defines the fundamental data type read from
|
|
|
|
// or written to the property.
|
|
|
|
// If unimplemented, the m_option entry that defines the property is used.
|
2012-09-21 12:05:52 +00:00
|
|
|
// arg: m_option*
|
2012-09-21 10:19:59 +00:00
|
|
|
M_PROPERTY_GET_TYPE,
|
|
|
|
|
|
|
|
// Get the current value.
|
|
|
|
// arg: pointer to a variable of the type according to the property type
|
|
|
|
M_PROPERTY_GET,
|
|
|
|
|
|
|
|
// Set a new value. The property wrapper will make sure that only valid
|
|
|
|
// values are set (e.g. according to the property type's min/max range).
|
|
|
|
// If unimplemented, the property is read-only.
|
|
|
|
// arg: pointer to a variable of the type according to the property type
|
|
|
|
M_PROPERTY_SET,
|
|
|
|
|
|
|
|
// Get human readable string representing the current value.
|
|
|
|
// If unimplemented, the property wrapper uses the property type as
|
|
|
|
// fallback.
|
|
|
|
// arg: char**
|
|
|
|
M_PROPERTY_PRINT,
|
|
|
|
|
|
|
|
// Switch the property up/down by a given value.
|
|
|
|
// If unimplemented, the property wrapper uses the property type as
|
|
|
|
// fallback.
|
2012-09-22 04:15:36 +00:00
|
|
|
// arg: struct m_property_switch_arg*
|
2012-09-21 10:19:59 +00:00
|
|
|
M_PROPERTY_SWITCH,
|
|
|
|
|
2012-09-22 06:04:08 +00:00
|
|
|
// Get a string containing a parsable representation.
|
|
|
|
// Can't be overridden by property implementations.
|
|
|
|
// arg: char**
|
|
|
|
M_PROPERTY_GET_STRING,
|
|
|
|
|
2012-09-21 10:19:59 +00:00
|
|
|
// Set a new value from a string. The property wrapper parses this using the
|
|
|
|
// parse function provided by the property type.
|
|
|
|
// Can't be overridden by property implementations.
|
|
|
|
// arg: char*
|
2012-09-22 06:04:08 +00:00
|
|
|
M_PROPERTY_SET_STRING,
|
2012-09-21 10:19:59 +00:00
|
|
|
|
2014-02-24 19:10:26 +00:00
|
|
|
// Set a mpv_node value.
|
|
|
|
// arg: mpv_node*
|
|
|
|
M_PROPERTY_GET_NODE,
|
|
|
|
|
|
|
|
// Get a mpv_node value.
|
|
|
|
// arg: mpv_node*
|
|
|
|
M_PROPERTY_SET_NODE,
|
|
|
|
|
2012-09-21 10:19:59 +00:00
|
|
|
// Pass down an action to a sub-property.
|
2012-09-22 06:04:08 +00:00
|
|
|
// arg: struct m_property_action_arg*
|
2012-09-21 10:19:59 +00:00
|
|
|
M_PROPERTY_KEY_ACTION,
|
2014-06-08 21:52:58 +00:00
|
|
|
|
|
|
|
// Get the (usually constant) value that indicates no change. Obscure
|
|
|
|
// special functionality for things like the volume property.
|
|
|
|
// Otherwise works like M_PROPERTY_GET.
|
|
|
|
M_PROPERTY_GET_NEUTRAL,
|
2012-09-22 04:15:36 +00:00
|
|
|
};
|
2012-09-21 12:22:23 +00:00
|
|
|
|
2012-09-22 04:15:36 +00:00
|
|
|
// Argument for M_PROPERTY_SWITCH
|
|
|
|
struct m_property_switch_arg {
|
|
|
|
double inc; // value to add to property, or cycle direction
|
|
|
|
bool wrap; // whether value should wrap around on over/underflow
|
2012-09-21 10:19:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Argument for M_PROPERTY_KEY_ACTION
|
2012-09-22 04:15:36 +00:00
|
|
|
struct m_property_action_arg {
|
2007-05-29 21:49:39 +00:00
|
|
|
const char* key;
|
|
|
|
int action;
|
|
|
|
void* arg;
|
2012-09-21 10:19:59 +00:00
|
|
|
};
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2012-09-21 10:19:59 +00:00
|
|
|
enum mp_property_return {
|
|
|
|
// Returned on success.
|
|
|
|
M_PROPERTY_OK = 1,
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2012-09-21 10:19:59 +00:00
|
|
|
// Returned on error.
|
|
|
|
M_PROPERTY_ERROR = 0,
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2012-09-21 10:19:59 +00:00
|
|
|
// Returned when the property can't be used, for example video related
|
|
|
|
// properties while playing audio only.
|
|
|
|
M_PROPERTY_UNAVAILABLE = -1,
|
2006-03-22 00:19:02 +00:00
|
|
|
|
2012-09-21 10:19:59 +00:00
|
|
|
// Returned if the requested action is not implemented.
|
|
|
|
M_PROPERTY_NOT_IMPLEMENTED = -2,
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2012-09-21 10:19:59 +00:00
|
|
|
// Returned when asking for a property that doesn't exist.
|
|
|
|
M_PROPERTY_UNKNOWN = -3,
|
2014-02-24 19:10:26 +00:00
|
|
|
|
|
|
|
// When trying to set invalid or incorrectly formatted data.
|
|
|
|
M_PROPERTY_INVALID_FORMAT = -4,
|
2012-09-21 10:19:59 +00:00
|
|
|
};
|
2006-03-22 00:19:02 +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
|
|
|
struct m_property {
|
|
|
|
const char *name;
|
|
|
|
// ctx: opaque caller context, which the property might use
|
|
|
|
// prop: pointer to this struct
|
|
|
|
// action: one of enum mp_property_action
|
|
|
|
// arg: specific to the action
|
|
|
|
// returns: one of enum mp_property_return
|
|
|
|
int (*call)(void *ctx, struct m_property *prop, int action, void *arg);
|
|
|
|
void *priv;
|
|
|
|
};
|
|
|
|
|
2012-09-21 10:19:59 +00:00
|
|
|
// Access a property.
|
|
|
|
// action: one of m_property_action
|
|
|
|
// ctx: opaque value passed through to property implementation
|
|
|
|
// returns: one of mp_property_return
|
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,
|
2013-12-21 18:36:33 +00:00
|
|
|
const char* property_name, int action, void* arg, void *ctx);
|
2006-03-22 00:19:02 +00:00
|
|
|
|
2014-03-30 11:41:03 +00:00
|
|
|
// Given a path of the form "a/b/c", this function will set *prefix to "a",
|
|
|
|
// and rem to "b/c", and return true.
|
|
|
|
// If there is no '/' in the path, set prefix to path, and rem to "", and
|
|
|
|
// return false.
|
|
|
|
bool m_property_split_path(const char *path, bstr *prefix, char **rem);
|
|
|
|
|
2012-09-21 10:19:59 +00:00
|
|
|
// Print a list of properties.
|
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);
|
2006-03-22 16:35:17 +00:00
|
|
|
|
2012-09-21 10:19:59 +00:00
|
|
|
// Expand a property string.
|
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
|
|
|
// This function allows to print strings containing property values.
|
|
|
|
// ${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.
|
|
|
|
// General syntax: "${" ["?" | "!"] ["="] NAME ":" STR "}"
|
|
|
|
// 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.
|
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 *str, void *ctx);
|
2006-04-22 14:26:30 +00:00
|
|
|
|
2012-09-21 10:19:59 +00:00
|
|
|
// Trivial helpers for implementing properties.
|
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);
|
|
|
|
int m_property_int_ro(int action, void* arg, int var);
|
|
|
|
int m_property_int64_ro(int action, void* arg, int64_t var);
|
|
|
|
int m_property_float_ro(int action, void* arg, float var);
|
|
|
|
int m_property_double_ro(int action, void* arg, double var);
|
|
|
|
int m_property_strdup_ro(int action, void* arg, const char *var);
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2014-02-15 15:41:48 +00:00
|
|
|
struct m_sub_property {
|
|
|
|
// Name of the sub-property - this will be prefixed with the parent
|
|
|
|
// property's name.
|
|
|
|
const char *name;
|
|
|
|
// Type of the data stored in the value member. See m_option.
|
2014-11-13 16:25:59 +00:00
|
|
|
struct m_option type;
|
2014-02-15 15:41:48 +00:00
|
|
|
// Data returned by the sub-property. m_property_read_sub() will make a
|
|
|
|
// copy of this if needed. It will never write or free the data.
|
|
|
|
union m_option_value value;
|
|
|
|
// This can be set to true if the property should be hidden.
|
|
|
|
bool unavailable;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Convenience macros which can be used as part of a sub_property entry.
|
|
|
|
#define SUB_PROP_INT(i) \
|
2014-11-13 16:25:59 +00:00
|
|
|
.type = {.type = CONF_TYPE_INT}, .value = {.int_ = (i)}
|
2014-02-15 15:41:48 +00:00
|
|
|
#define SUB_PROP_STR(s) \
|
2014-11-13 16:25:59 +00:00
|
|
|
.type = {.type = CONF_TYPE_STRING}, .value = {.string = (char *)(s)}
|
2014-02-15 15:41:48 +00:00
|
|
|
#define SUB_PROP_FLOAT(f) \
|
2014-11-13 16:25:59 +00:00
|
|
|
.type = {.type = CONF_TYPE_FLOAT}, .value = {.float_ = (f)}
|
2014-11-13 17:00:07 +00:00
|
|
|
#define SUB_PROP_DOUBLE(f) \
|
|
|
|
.type = {.type = CONF_TYPE_DOUBLE}, .value = {.double_ = (f)}
|
2014-02-15 15:41:48 +00:00
|
|
|
#define SUB_PROP_FLAG(f) \
|
2014-11-13 16:25:59 +00:00
|
|
|
.type = {.type = CONF_TYPE_FLAG}, .value = {.flag = (f)}
|
2014-02-15 15:41:48 +00:00
|
|
|
|
|
|
|
int m_property_read_sub(const struct m_sub_property *props, int action, void *arg);
|
|
|
|
|
2014-02-15 15:49:28 +00:00
|
|
|
|
|
|
|
// Used with m_property_read_list().
|
|
|
|
// Get an entry. item is the 0-based index of the item. This behaves like a
|
|
|
|
// top-level property request (but you must implement M_PROPERTY_GET_TYPE).
|
|
|
|
// item will be in range [0, count), for count see m_property_read_list()
|
|
|
|
// action, arg are for property access.
|
|
|
|
// ctx is userdata passed to m_property_read_list.
|
|
|
|
typedef int (*m_get_item_cb)(int item, int action, void *arg, void *ctx);
|
|
|
|
|
|
|
|
int m_property_read_list(int action, void *arg, int count,
|
|
|
|
m_get_item_cb get_item, void *ctx);
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#endif /* MPLAYER_M_PROPERTY_H */
|