1
mirror of https://github.com/mpv-player/mpv synced 2025-01-09 01:36:25 +01:00

cosmetics: reformat demux_lavf.c, m_option.[ch] and m_property.c

This commit is contained in:
Uoti Urpala 2011-07-03 15:42:04 +03:00
parent 1a8384401b
commit 774bb252aa
4 changed files with 2883 additions and 2688 deletions

File diff suppressed because it is too large Load Diff

3581
m_option.c

File diff suppressed because it is too large Load Diff

View File

@ -24,24 +24,13 @@
#include "config.h" #include "config.h"
/// \defgroup Options // m_option allows to parse, print and copy data of various types.
/// m_option allows to parse, print and copy data of various types.
/// It is the base of the \ref OptionsStruct, \ref Config and
/// \ref Properties APIs.
///@{
/// \file m_option.h
/// \ingroup OptionTypes
typedef struct m_option_type m_option_type_t; typedef struct m_option_type m_option_type_t;
typedef struct m_option m_option_t; typedef struct m_option m_option_t;
struct m_struct_st; struct m_struct_st;
/// \defgroup OptionTypes Options types ///////////////////////////// Options types declarations ////////////////////
/// \ingroup Options
///@{
///////////////////////////// Options types declarations ////////////////////////////
// Simple types // Simple types
extern const m_option_type_t m_option_type_flag; extern const m_option_type_t m_option_type_flag;
@ -68,16 +57,16 @@ extern const m_option_type_t m_option_type_afmt;
extern const m_option_type_t m_option_type_func_param; extern const m_option_type_t m_option_type_func_param;
extern const m_option_type_t m_option_type_func; extern const m_option_type_t m_option_type_func;
/// Callback used to reset func options. // Callback used to reset func options.
typedef void (*m_opt_default_func_t)(const m_option_t *, const char*); typedef void (*m_opt_default_func_t)(const m_option_t *, const char *);
/// Callback used by m_option_type_func_full options. // Callback used by m_option_type_func_full options.
typedef int (*m_opt_func_full_t)(const m_option_t *, const char *, const char *); typedef int (*m_opt_func_full_t)(const m_option_t *, const char *, const char *);
/// Callback used by m_option_type_func_param options. // Callback used by m_option_type_func_param options.
typedef int (*m_opt_func_param_t)(const m_option_t *, const char *); typedef int (*m_opt_func_param_t)(const m_option_t *, const char *);
/// Callback used by m_option_type_func options. // Callback used by m_option_type_func options.
typedef int (*m_opt_func_t)(const m_option_t *); typedef int (*m_opt_func_t)(const m_option_t *);
// Backwards compatibility // Backwards compatibility
@ -90,51 +79,51 @@ typedef m_opt_func_t cfg_func_t;
#define END_AT_TIME 1 #define END_AT_TIME 1
#define END_AT_SIZE 2 #define END_AT_SIZE 2
typedef struct { typedef struct {
double pos; double pos;
int type; int type;
} m_time_size_t; } m_time_size_t;
/// Extra definition needed for \ref m_option_type_obj_settings_list options. // Extra definition needed for \ref m_option_type_obj_settings_list options.
typedef struct { typedef struct {
/// Pointer to an array of pointer to some object type description struct. // Pointer to an array of pointer to some object type description struct.
void** list; void **list;
/// Offset of the object type name (char*) in the description struct. // Offset of the object type name (char*) in the description struct.
void* name_off; void *name_off;
/// Offset of the object type info string (char*) in the description struct. // Offset of the object type info string (char*) in the description struct.
void* info_off; void *info_off;
/// \brief Offset of the object type parameter description (\ref m_struct_st) // Offset of the object type parameter description (\ref m_struct_st)
/// in the description struct. // in the description struct.
void* desc_off; void *desc_off;
} m_obj_list_t; } m_obj_list_t;
/// The data type used by \ref m_option_type_obj_settings_list. // The data type used by \ref m_option_type_obj_settings_list.
typedef struct m_obj_settings { typedef struct m_obj_settings {
/// Type of the object. // Type of the object.
char* name; char *name;
/// NULL terminated array of parameter/value pairs. // NULL terminated array of parameter/value pairs.
char** attribs; char **attribs;
} m_obj_settings_t; } m_obj_settings_t;
/// A parser to set up a list of objects. // A parser to set up a list of objects.
/** It creates a NULL terminated array \ref m_obj_settings. The option priv /** It creates a NULL terminated array \ref m_obj_settings. The option priv
* field (\ref m_option::priv) must point to a \ref m_obj_list_t describing * field (\ref m_option::priv) must point to a \ref m_obj_list_t describing
* the available object types. * the available object types.
*/ */
extern const m_option_type_t m_option_type_obj_settings_list; extern const m_option_type_t m_option_type_obj_settings_list;
/// Extra definition needed for \ref m_option_type_obj_presets options. // Extra definition needed for \ref m_option_type_obj_presets options.
typedef struct { typedef struct {
/// Description of the struct holding the presets. // Description of the struct holding the presets.
const struct m_struct_st *in_desc; const struct m_struct_st *in_desc;
/// Description of the struct that should be set by the presets. // Description of the struct that should be set by the presets.
const struct m_struct_st *out_desc; const struct m_struct_st *out_desc;
/// Pointer to an array of structs defining the various presets. // Pointer to an array of structs defining the various presets.
const void *presets; const void *presets;
/// Offset of the preset's name inside the in_struct. // Offset of the preset's name inside the in_struct.
void* name_off; void *name_off;
} m_obj_presets_t; } m_obj_presets_t;
/// Set several fields in a struct at once. // Set several fields in a struct at once.
/** For this two struct descriptions are used. One for the struct holding the /** For this two struct descriptions are used. One for the struct holding the
* preset and one for the struct beeing set. Every field present in both * preset and one for the struct beeing set. Every field present in both
* structs will be copied from the preset struct to the destination one. * structs will be copied from the preset struct to the destination one.
@ -143,21 +132,21 @@ typedef struct {
*/ */
extern const m_option_type_t m_option_type_obj_presets; extern const m_option_type_t m_option_type_obj_presets;
/// Parse an URL into a struct. // Parse an URL into a struct.
/** The option priv field (\ref m_option::priv) must point to a /** The option priv field (\ref m_option::priv) must point to a
* \ref m_struct_st describing which fields of the URL must be used. * \ref m_struct_st describing which fields of the URL must be used.
*/ */
extern const m_option_type_t m_option_type_custom_url; extern const m_option_type_t m_option_type_custom_url;
/// Extra definition needed for \ref m_option_type_obj_params options. // Extra definition needed for \ref m_option_type_obj_params options.
typedef struct { typedef struct {
/// Field descriptions. // Field descriptions.
const struct m_struct_st* desc; const struct m_struct_st *desc;
/// Field separator to use. // Field separator to use.
char separator; char separator;
} m_obj_params_t; } m_obj_params_t;
/// Parse a set of parameters. // Parse a set of parameters.
/** Parameters are separated by the given separator and each one /** Parameters are separated by the given separator and each one
* successively sets a field from the struct. The option priv field * successively sets a field from the struct. The option priv field
* (\ref m_option::priv) must point to a \ref m_obj_params_t. * (\ref m_option::priv) must point to a \ref m_obj_params_t.
@ -165,10 +154,10 @@ typedef struct {
extern const m_option_type_t m_option_type_obj_params; extern const m_option_type_t m_option_type_obj_params;
typedef struct { typedef struct {
int start; int start;
int end; int end;
} m_span_t; } m_span_t;
/// Ready made settings to parse a \ref m_span_t with a start-end syntax. // Ready made settings to parse a \ref m_span_t with a start-end syntax.
extern const m_obj_params_t m_span_params_def; extern const m_obj_params_t m_span_params_def;
struct m_opt_choice_alternatives { struct m_opt_choice_alternatives {
@ -178,204 +167,186 @@ struct m_opt_choice_alternatives {
// FIXME: backward compatibility // FIXME: backward compatibility
#define CONF_TYPE_FLAG (&m_option_type_flag) #define CONF_TYPE_FLAG (&m_option_type_flag)
#define CONF_TYPE_INT (&m_option_type_int) #define CONF_TYPE_INT (&m_option_type_int)
#define CONF_TYPE_INT64 (&m_option_type_int64) #define CONF_TYPE_INT64 (&m_option_type_int64)
#define CONF_TYPE_FLOAT (&m_option_type_float) #define CONF_TYPE_FLOAT (&m_option_type_float)
#define CONF_TYPE_DOUBLE (&m_option_type_double) #define CONF_TYPE_DOUBLE (&m_option_type_double)
#define CONF_TYPE_STRING (&m_option_type_string) #define CONF_TYPE_STRING (&m_option_type_string)
#define CONF_TYPE_FUNC (&m_option_type_func) #define CONF_TYPE_FUNC (&m_option_type_func)
#define CONF_TYPE_FUNC_PARAM (&m_option_type_func_param) #define CONF_TYPE_FUNC_PARAM (&m_option_type_func_param)
#define CONF_TYPE_PRINT (&m_option_type_print) #define CONF_TYPE_PRINT (&m_option_type_print)
#define CONF_TYPE_PRINT_INDIRECT (&m_option_type_print_indirect) #define CONF_TYPE_PRINT_INDIRECT (&m_option_type_print_indirect)
#define CONF_TYPE_PRINT_FUNC (&m_option_type_print_func) #define CONF_TYPE_PRINT_FUNC (&m_option_type_print_func)
#define CONF_TYPE_SUBCONFIG (&m_option_type_subconfig) #define CONF_TYPE_SUBCONFIG (&m_option_type_subconfig)
#define CONF_TYPE_STRING_LIST (&m_option_type_string_list) #define CONF_TYPE_STRING_LIST (&m_option_type_string_list)
#define CONF_TYPE_POSITION (&m_option_type_position) #define CONF_TYPE_POSITION (&m_option_type_position)
#define CONF_TYPE_IMGFMT (&m_option_type_imgfmt) #define CONF_TYPE_IMGFMT (&m_option_type_imgfmt)
#define CONF_TYPE_AFMT (&m_option_type_afmt) #define CONF_TYPE_AFMT (&m_option_type_afmt)
#define CONF_TYPE_SPAN (&m_option_type_span) #define CONF_TYPE_SPAN (&m_option_type_span)
#define CONF_TYPE_OBJ_SETTINGS_LIST (&m_option_type_obj_settings_list) #define CONF_TYPE_OBJ_SETTINGS_LIST (&m_option_type_obj_settings_list)
#define CONF_TYPE_OBJ_PRESETS (&m_option_type_obj_presets) #define CONF_TYPE_OBJ_PRESETS (&m_option_type_obj_presets)
#define CONF_TYPE_CUSTOM_URL (&m_option_type_custom_url) #define CONF_TYPE_CUSTOM_URL (&m_option_type_custom_url)
#define CONF_TYPE_OBJ_PARAMS (&m_option_type_obj_params) #define CONF_TYPE_OBJ_PARAMS (&m_option_type_obj_params)
#define CONF_TYPE_TIME (&m_option_type_time) #define CONF_TYPE_TIME (&m_option_type_time)
#define CONF_TYPE_TIME_SIZE (&m_option_type_time_size) #define CONF_TYPE_TIME_SIZE (&m_option_type_time_size)
///////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
/// Option type description // Option type description
struct m_option_type { struct m_option_type {
const char* name; const char *name;
/// Syntax description, etc // Syntax description, etc
const char* comments; const char *comments;
/// Size needed for the data. // Size needed for the data.
unsigned int size; unsigned int size;
/// See \ref OptionTypeFlags. // See \ref OptionTypeFlags.
unsigned int flags; unsigned int flags;
/// Parse the data from a string. // Parse the data from a string.
/** It is the only required function, all others can be NULL. /** It is the only required function, all others can be NULL.
* *
* \param opt The option that is parsed. * \param opt The option that is parsed.
* \param name The full option name. * \param name The full option name.
* \param param The parameter to parse. * \param param The parameter to parse.
* \param dst Pointer to the memory where the data should be written. * \param dst Pointer to the memory where the data should be written.
* If NULL the parameter validity should still be checked. * If NULL the parameter validity should still be checked.
* \param src Source of the option, see \ref OptionParserModes. * \param src Source of the option, see \ref OptionParserModes.
* \return On error a negative value is returned, on success the number of arguments * \return On error a negative value is returned, on success the number of arguments
* consumed. For details see \ref OptionParserReturn. * consumed. For details see \ref OptionParserReturn.
*/ */
int (*parse)(const m_option_t* opt,const char *name, const char *param, void* dst, int src); int (*parse)(const m_option_t *opt, const char *name, const char *param, void *dst, int src);
/// Print back a value in string form. // Print back a value in string form.
/** \param opt The option to print. /** \param opt The option to print.
* \param val Pointer to the memory holding the data to be printed. * \param val Pointer to the memory holding the data to be printed.
* \return An allocated string containing the text value or (void*)-1 * \return An allocated string containing the text value or (void*)-1
* on error. * on error.
*/ */
char* (*print)(const m_option_t* opt, const void* val); char *(*print)(const m_option_t *opt, const void *val);
/** \name /** \name
* These functions are called to save/set/restore the status of the * These functions are called to save/set/restore the status of the
* variables. The difference between the 3 only matters for types like * variables. The difference between the 3 only matters for types like
* \ref m_option_type_func where 'setting' needs to do more than just * \ref m_option_type_func where 'setting' needs to do more than just
* copying some data. * copying some data.
*/ */
//@{ //@{
/// Update a save slot (dst) from the current value in the program (src). // Update a save slot (dst) from the current value in the program (src).
/** \param opt The option to copy. /** \param opt The option to copy.
* \param dst Pointer to the destination memory. * \param dst Pointer to the destination memory.
* \param src Pointer to the source memory. * \param src Pointer to the source memory.
*/ */
void (*save)(const m_option_t* opt,void* dst, const void* src); void (*save)(const m_option_t *opt, void *dst, const void *src);
/// Set the value in the program (dst) from a save slot. // Set the value in the program (dst) from a save slot.
/** \param opt The option to copy. /** \param opt The option to copy.
* \param dst Pointer to the destination memory. * \param dst Pointer to the destination memory.
* \param src Pointer to the source memory. * \param src Pointer to the source memory.
*/ */
void (*set)(const m_option_t* opt,void* dst, const void* src); void (*set)(const m_option_t *opt, void *dst, const void *src);
/// Copy the data between two save slots. If NULL and size is > 0 a memcpy will be used. // Copy the data between two save slots. If NULL and size is > 0 a memcpy will be used.
/** \param opt The option to copy. /** \param opt The option to copy.
* \param dst Pointer to the destination memory. * \param dst Pointer to the destination memory.
* \param src Pointer to the source memory. * \param src Pointer to the source memory.
*/ */
void (*copy)(const m_option_t* opt,void* dst, const void* src); void (*copy)(const m_option_t *opt, void *dst, const void *src);
//@} //@}
/// Free the data allocated for a save slot. // Free the data allocated for a save slot.
/** This is only needed for dynamic types like strings. /** This is only needed for dynamic types like strings.
* \param dst Pointer to the data, usually a pointer that should be freed and * \param dst Pointer to the data, usually a pointer that should be freed and
* set to NULL. * set to NULL.
*/ */
void (*free)(void* dst); void (*free)(void *dst);
}; };
///@} // Option description
/// Option description
/** \ingroup Options
*/
struct m_option { struct m_option {
/// Option name. // Option name.
const char *name; const char *name;
/// Reserved for higher level APIs, it shouldn't be used by parsers. // Reserved for higher level APIs, it shouldn't be used by parsers.
/** The suboption parser and func types do use it. They should instead /** The suboption parser and func types do use it. They should instead
* use the priv field but this was inherited from older versions of the * use the priv field but this was inherited from older versions of the
* config code. * config code.
*/ */
void *p; void *p;
/// Option type. // Option type.
const m_option_type_t* type; const m_option_type_t *type;
/// See \ref OptionFlags. // See \ref OptionFlags.
unsigned int flags; unsigned int flags;
/// \brief Mostly useful for numeric types, the \ref M_OPT_MIN flags must // \brief Mostly useful for numeric types, the \ref M_OPT_MIN flags must
/// also be set. // also be set.
double min; double min;
/// \brief Mostly useful for numeric types, the \ref M_OPT_MAX flags must // \brief Mostly useful for numeric types, the \ref M_OPT_MAX flags must
/// also be set. // also be set.
double max; double max;
/// Type dependent data (for all kinds of extended settings). // Type dependent data (for all kinds of extended settings).
/** This used to be a function pointer to hold a 'reverse to defaults' func. /** This used to be a function pointer to hold a 'reverse to defaults' func.
* Now it can be used to pass any type of extra args needed by the parser. * Now it can be used to pass any type of extra args needed by the parser.
* Passing a 'default func' is still valid for all func based option types. * Passing a 'default func' is still valid for all func based option types.
*/ */
void* priv; void *priv;
int new; int new;
int offset; int offset;
}; };
/// \defgroup OptionFlags Option flags // The option has a minimum set in \ref m_option::min.
///@{ #define M_OPT_MIN (1 << 0)
/// The option has a minimum set in \ref m_option::min. // The option has a maximum set in \ref m_option::max.
#define M_OPT_MIN (1<<0) #define M_OPT_MAX (1 << 1)
/// The option has a maximum set in \ref m_option::max. // The option has a minimum and maximum in m_option::min and m_option::max.
#define M_OPT_MAX (1<<1) #define M_OPT_RANGE (M_OPT_MIN | M_OPT_MAX)
/// The option has a minimum and maximum in \ref m_option::min and \ref m_option::max. // The option is forbidden in config files.
#define M_OPT_RANGE (M_OPT_MIN|M_OPT_MAX) #define M_OPT_NOCFG (1 << 2)
/// The option is forbidden in config files. // The option is forbidden on the command line.
#define M_OPT_NOCFG (1<<2) #define M_OPT_NOCMD (1 << 3)
/// The option is forbidden on the command line. // The option is global in the \ref Config.
#define M_OPT_NOCMD (1<<3)
/// The option is global in the \ref Config.
/** It won't be saved on push and the command line parser will set it when /** It won't be saved on push and the command line parser will set it when
* it's parsed (i.e. it won't be set later) * it's parsed (i.e. it won't be set later)
* e.g options : -v, -quiet * e.g options : -v, -quiet
*/ */
#define M_OPT_GLOBAL (1<<4) #define M_OPT_GLOBAL (1 << 4)
/// The \ref Config won't save this option on push. // The \ref Config won't save this option on push.
/** It won't be saved on push but the command line parser will add it with /** It won't be saved on push but the command line parser will add it with
* its entry (i.e. it may be set later) * its entry (i.e. it may be set later)
* e.g options : -include * e.g options : -include
*/ */
#define M_OPT_NOSAVE (1<<5) #define M_OPT_NOSAVE (1 << 5)
/// The option should be set during command line pre-parsing // The option should be set during command line pre-parsing
#define M_OPT_PRE_PARSE (1<<6) #define M_OPT_PRE_PARSE (1 << 6)
/// \defgroup OldOptionFlags Backward compatibility // These are kept for compatibility with older code.
/// #define CONF_MIN M_OPT_MIN
/// These are kept for compatibility with older code. #define CONF_MAX M_OPT_MAX
/// @{ #define CONF_RANGE M_OPT_RANGE
#define CONF_MIN M_OPT_MIN #define CONF_NOCFG M_OPT_NOCFG
#define CONF_MAX M_OPT_MAX #define CONF_NOCMD M_OPT_NOCMD
#define CONF_RANGE M_OPT_RANGE #define CONF_GLOBAL M_OPT_GLOBAL
#define CONF_NOCFG M_OPT_NOCFG #define CONF_NOSAVE M_OPT_NOSAVE
#define CONF_NOCMD M_OPT_NOCMD #define CONF_PRE_PARSE M_OPT_PRE_PARSE
#define CONF_GLOBAL M_OPT_GLOBAL
#define CONF_NOSAVE M_OPT_NOSAVE
#define CONF_PRE_PARSE M_OPT_PRE_PARSE
///@}
///@} // These flags are used to describe special parser capabilities or behavior.
/// \defgroup OptionTypeFlags Option type flags // Suboption parser flag.
/// \ingroup OptionTypes
///
/// These flags are used to describe special parser capabilities or behavior.
///
///@{
/// Suboption parser flag.
/** When this flag is set, m_option::p should point to another m_option /** When this flag is set, m_option::p should point to another m_option
* array. Only the parse function will be called. If dst is set, it should * array. Only the parse function will be called. If dst is set, it should
* create/update an array of char* containg opt/val pairs. The options in * create/update an array of char* containg opt/val pairs. The options in
@ -383,23 +354,23 @@ struct m_option {
* Also note that suboptions may be directly accessed by using * Also note that suboptions may be directly accessed by using
* -option:subopt blah. * -option:subopt blah.
*/ */
#define M_OPT_TYPE_HAS_CHILD (1<<0) #define M_OPT_TYPE_HAS_CHILD (1 << 0)
/// Wildcard matching flag. // Wildcard matching flag.
/** If set the option type has a use for option names ending with a * /** If set the option type has a use for option names ending with a *
* (used for -aa*), this only affects the option name matching. * (used for -aa*), this only affects the option name matching.
*/ */
#define M_OPT_TYPE_ALLOW_WILDCARD (1<<1) #define M_OPT_TYPE_ALLOW_WILDCARD (1 << 1)
/// Dynamic data type. // Dynamic data type.
/** This flag indicates that the data is dynamically allocated (m_option::p /** This flag indicates that the data is dynamically allocated (m_option::p
* points to a pointer). It enables a little hack in the \ref Config wich * points to a pointer). It enables a little hack in the \ref Config wich
* replaces the initial value of such variables with a dynamic copy in case * replaces the initial value of such variables with a dynamic copy in case
* the initial value is statically allocated (pretty common with strings). * the initial value is statically allocated (pretty common with strings).
*/ */
#define M_OPT_TYPE_DYNAMIC (1<<2) #define M_OPT_TYPE_DYNAMIC (1 << 2)
/// Indirect option type. // Indirect option type.
/** If this is set the parse function doesn't directly return /** If this is set the parse function doesn't directly return
* the wanted thing. Options use this if for some reasons they have to wait * the wanted thing. Options use this if for some reasons they have to wait
* until the set call to be able to correctly set the target var. * until the set call to be able to correctly set the target var.
@ -408,76 +379,58 @@ struct m_option {
* target var. It's used by the callback-based options as the callback call * target var. It's used by the callback-based options as the callback call
* may append later on. * may append later on.
*/ */
#define M_OPT_TYPE_INDIRECT (1<<3) #define M_OPT_TYPE_INDIRECT (1 << 3)
///@} ///////////////////////////// Parser flags /////////////////////////////////
///////////////////////////// Parser flags //////////////////////////////////////// // Some parsers behave differently depending on the mode passed in the src
// parameter of m_option_type::parse. For example the flag type doesn't take
// an argument when parsing from the command line.
/// \defgroup OptionParserModes Option parser modes // Set when parsing from a config file.
/// \ingroup Options
///
/// Some parsers behave differently depending on the mode passed in the src
/// parameter of m_option_type::parse. For example the flag type doesn't take
/// an argument when parsing from the command line.
///@{
/// Set when parsing from a config file.
#define M_CONFIG_FILE 0 #define M_CONFIG_FILE 0
/// Set when parsing command line arguments. // Set when parsing command line arguments.
#define M_COMMAND_LINE 1 #define M_COMMAND_LINE 1
/// Set when pre-parsing the command line // Set when pre-parsing the command line
#define M_COMMAND_LINE_PRE_PARSE 2 #define M_COMMAND_LINE_PRE_PARSE 2
///@} // On success parsers return the number of arguments consumed: 0 or 1.
//
// To indicate that MPlayer should exit without playing anything,
// parsers return M_OPT_EXIT minus the number of parameters they
// consumed: \ref M_OPT_EXIT or \ref M_OPT_EXIT-1.
//
// On error one of the following (negative) error codes is returned:
/// \defgroup OptionParserReturn Option parser return code // For use by higher level APIs when the option name is invalid.
/// \ingroup Options #define M_OPT_UNKNOWN -1
///
/// On success parsers return the number of arguments consumed: 0 or 1.
///
/// To indicate that MPlayer should exit without playing anything,
/// parsers return M_OPT_EXIT minus the number of parameters they
/// consumed: \ref M_OPT_EXIT or \ref M_OPT_EXIT-1.
///
/// On error one of the following (negative) error codes is returned:
///@{
/// For use by higher level APIs when the option name is invalid. // Returned when a parameter is needed but wasn't provided.
#define M_OPT_UNKNOWN -1 #define M_OPT_MISSING_PARAM -2
/// Returned when a parameter is needed but wasn't provided. // Returned when the given parameter couldn't be parsed.
#define M_OPT_MISSING_PARAM -2 #define M_OPT_INVALID -3
/// Returned when the given parameter couldn't be parsed. // Returned if the value is "out of range". The exact meaning may
#define M_OPT_INVALID -3 // vary from type to type.
#define M_OPT_OUT_OF_RANGE -4
/// \brief Returned if the value is "out of range". The exact meaning may // Returned if the parser failed for any other reason than a bad parameter.
/// vary from type to type. #define M_OPT_PARSER_ERR -5
#define M_OPT_OUT_OF_RANGE -4
/// Returned if the parser failed for any other reason than a bad parameter. // Returned when MPlayer should exit. Used by various help stuff.
#define M_OPT_PARSER_ERR -5
/// Returned when MPlayer should exit. Used by various help stuff.
/** M_OPT_EXIT must be the lowest number on this list. /** M_OPT_EXIT must be the lowest number on this list.
*/ */
#define M_OPT_EXIT -6 #define M_OPT_EXIT -6
/// \defgroup OldOptionParserReturn Backward compatibility // These are kept for compatibility with older code.
/// //
/// These are kept for compatibility with older code. #define ERR_NOT_AN_OPTION M_OPT_UNKNOWN
/// #define ERR_MISSING_PARAM M_OPT_MISSING_PARAM
///@{ #define ERR_OUT_OF_RANGE M_OPT_OUT_OF_RANGE
#define ERR_NOT_AN_OPTION M_OPT_UNKNOWN #define ERR_FUNC_ERR M_OPT_PARSER_ERR
#define ERR_MISSING_PARAM M_OPT_MISSING_PARAM
#define ERR_OUT_OF_RANGE M_OPT_OUT_OF_RANGE
#define ERR_FUNC_ERR M_OPT_PARSER_ERR
///@}
///@} // Find the option matching the given name in the list.
/// Find the option matching the given name in the list.
/** \ingroup Options /** \ingroup Options
* This function takes the possible wildcards into account (see * This function takes the possible wildcards into account (see
* \ref M_OPT_TYPE_ALLOW_WILDCARD). * \ref M_OPT_TYPE_ALLOW_WILDCARD).
@ -486,7 +439,7 @@ struct m_option {
* \param name Name of the option. * \param name Name of the option.
* \return The matching option or NULL. * \return The matching option or NULL.
*/ */
const m_option_t* m_option_list_find(const m_option_t* list,const char* name); const m_option_t *m_option_list_find(const m_option_t *list, const char *name);
static inline void *m_option_get_ptr(const struct m_option *opt, static inline void *m_option_get_ptr(const struct m_option *opt,
void *optstruct) void *optstruct)
@ -494,35 +447,37 @@ static inline void *m_option_get_ptr(const struct m_option *opt,
return opt->new ? (char *) optstruct + opt->offset : opt->p; return opt->new ? (char *) optstruct + opt->offset : opt->p;
} }
/// Helper to parse options, see \ref m_option_type::parse. // Helper to parse options, see \ref m_option_type::parse.
inline static int static inline int m_option_parse(const m_option_t *opt, const char *name,
m_option_parse(const m_option_t* opt,const char *name, const char *param, void* dst, int src) { const char *param, void *dst, int src)
return opt->type->parse(opt,name,param,dst,src); {
return opt->type->parse(opt, name, param, dst, src);
} }
/// Helper to print options, see \ref m_option_type::print. // Helper to print options, see \ref m_option_type::print.
inline static char* static inline char *m_option_print(const m_option_t *opt, const void *val_ptr)
m_option_print(const m_option_t* opt, const void* val_ptr) { {
if(opt->type->print) if (opt->type->print)
return opt->type->print(opt,val_ptr); return opt->type->print(opt, val_ptr);
else else
return (char*)-1; return (char *)-1;
} }
/// Helper around \ref m_option_type::copy. // Helper around \ref m_option_type::copy.
inline static void static inline void m_option_copy(const m_option_t *opt, void *dst,
m_option_copy(const m_option_t* opt,void* dst, const void* src) { const void *src)
if(opt->type->copy) {
opt->type->copy(opt,dst,src); if (opt->type->copy)
else if(opt->type->size > 0) opt->type->copy(opt, dst, src);
memcpy(dst,src,opt->type->size); else if (opt->type->size > 0)
memcpy(dst, src, opt->type->size);
} }
/// Helper around \ref m_option_type::free. // Helper around \ref m_option_type::free.
inline static void static inline void m_option_free(const m_option_t *opt, void *dst)
m_option_free(const m_option_t* opt,void* dst) { {
if(opt->type->free) if (opt->type->free)
opt->type->free(dst); opt->type->free(dst);
} }
/*@}*/ /*@}*/
@ -553,9 +508,9 @@ int parse_timestring(const char *str, double *time, char endchar);
#define OPT_STRINGLIST(optname, varname, flags) {optname, NULL, &m_option_type_string_list, flags, 0, 0, NULL, 1, offsetof(struct MPOpts, varname)} #define OPT_STRINGLIST(optname, varname, flags) {optname, NULL, &m_option_type_string_list, flags, 0, 0, NULL, 1, offsetof(struct MPOpts, varname)}
#define OPT_PATHLIST(optname, varname, flags) {optname, NULL, &m_option_type_string_list, flags, 0, 0, (void *)&(const char){OPTION_PATH_SEPARATOR}, 1, offsetof(struct MPOpts, varname)} #define OPT_PATHLIST(optname, varname, flags) {optname, NULL, &m_option_type_string_list, flags, 0, 0, (void *)&(const char){OPTION_PATH_SEPARATOR}, 1, offsetof(struct MPOpts, varname)}
#define OPT_INT(optname, varname, flags) {optname, NULL, &m_option_type_int, flags, 0, 0, NULL, 1, offsetof(struct MPOpts, varname)} #define OPT_INT(optname, varname, flags) {optname, NULL, &m_option_type_int, flags, 0, 0, NULL, 1, offsetof(struct MPOpts, varname)}
#define OPT_INTRANGE(optname, varname, flags, min, max) {optname, NULL, &m_option_type_int, (flags)|CONF_RANGE, min, max, NULL, 1, offsetof(struct MPOpts, varname)} #define OPT_INTRANGE(optname, varname, flags, min, max) {optname, NULL, &m_option_type_int, (flags) | CONF_RANGE, min, max, NULL, 1, offsetof(struct MPOpts, varname)}
#define OPT_INTPAIR(optname, varname, flags) {optname, NULL, &m_option_type_intpair, (flags), 0, 0, NULL, 1, offsetof(struct MPOpts, varname)} #define OPT_INTPAIR(optname, varname, flags) {optname, NULL, &m_option_type_intpair, (flags), 0, 0, NULL, 1, offsetof(struct MPOpts, varname)}
#define OPT_FLOATRANGE(optname, varname, flags, min, max) {optname, NULL, &m_option_type_float, (flags)|CONF_RANGE, min, max, NULL, 1, offsetof(struct MPOpts, varname)} #define OPT_FLOATRANGE(optname, varname, flags, min, max) {optname, NULL, &m_option_type_float, (flags) | CONF_RANGE, min, max, NULL, 1, offsetof(struct MPOpts, varname)}
#define OPT_STRING(optname, varname, flags) {optname, NULL, &m_option_type_string, flags, 0, 0, NULL, 1, offsetof(struct MPOpts, varname)} #define OPT_STRING(optname, varname, flags) {optname, NULL, &m_option_type_string, flags, 0, 0, NULL, 1, offsetof(struct MPOpts, varname)}
#define OPT_SETTINGSLIST(optname, varname, flags, objlist) {optname, NULL, &m_option_type_obj_settings_list, flags, 0, 0, objlist, 1, offsetof(struct MPOpts, varname)} #define OPT_SETTINGSLIST(optname, varname, flags, objlist) {optname, NULL, &m_option_type_obj_settings_list, flags, 0, 0, objlist, 1, offsetof(struct MPOpts, varname)}
#define OPT_AUDIOFORMAT(optname, varname, flags) {optname, NULL, &m_option_type_afmt, flags, 0, 0, NULL, 1, offsetof(struct MPOpts, varname)} #define OPT_AUDIOFORMAT(optname, varname, flags) {optname, NULL, &m_option_type_afmt, flags, 0, 0, NULL, 1, offsetof(struct MPOpts, varname)}

View File

@ -32,95 +32,106 @@
#include "mp_msg.h" #include "mp_msg.h"
#include "mpcommon.h" #include "mpcommon.h"
static int do_action(const m_option_t* prop_list, const char* name, static int do_action(const m_option_t *prop_list, const char *name,
int action, void* arg, void *ctx) { int action, void *arg, void *ctx)
const char* sep; {
const m_option_t* prop; const char *sep;
const m_option_t *prop;
m_property_action_t ka; m_property_action_t ka;
int r; int r;
if((sep = strchr(name,'/')) && sep[1]) { if ((sep = strchr(name, '/')) && sep[1]) {
int len = sep-name; int len = sep - name;
char base[len+1]; char base[len + 1];
memcpy(base,name,len); memcpy(base, name, len);
base[len] = 0; base[len] = 0;
prop = m_option_list_find(prop_list, base); prop = m_option_list_find(prop_list, base);
ka.key = sep+1; ka.key = sep + 1;
ka.action = action; ka.action = action;
ka.arg = arg; ka.arg = arg;
action = M_PROPERTY_KEY_ACTION; action = M_PROPERTY_KEY_ACTION;
arg = &ka; arg = &ka;
} else } else
prop = m_option_list_find(prop_list, name); prop = m_option_list_find(prop_list, name);
if(!prop) return M_PROPERTY_UNKNOWN; if (!prop)
r = ((m_property_ctrl_f)prop->p)(prop,action,arg,ctx); return M_PROPERTY_UNKNOWN;
if(action == M_PROPERTY_GET_TYPE && r < 0) { r = ((m_property_ctrl_f)prop->p)(prop, action, arg, ctx);
if(!arg) return M_PROPERTY_ERROR; if (action == M_PROPERTY_GET_TYPE && r < 0) {
*(const m_option_t**)arg = prop; if (!arg)
return M_PROPERTY_ERROR;
*(const m_option_t **)arg = prop;
return M_PROPERTY_OK; return M_PROPERTY_OK;
} }
return r; return r;
} }
int m_property_do(const m_option_t* prop_list, const char* name, int m_property_do(const m_option_t *prop_list, const char *name,
int action, void* arg, void *ctx) { int action, void *arg, void *ctx)
const m_option_t* opt; {
void* val; const m_option_t *opt;
char* str; void *val;
char *str;
int r; int r;
switch(action) { switch (action) {
case M_PROPERTY_PRINT: case M_PROPERTY_PRINT:
if((r = do_action(prop_list,name,M_PROPERTY_PRINT,arg,ctx)) >= 0) if ((r = do_action(prop_list, name, M_PROPERTY_PRINT, arg, ctx)) >= 0)
return r; return r;
// fallback on the default print for this type // fallback on the default print for this type
case M_PROPERTY_TO_STRING: case M_PROPERTY_TO_STRING:
if((r = do_action(prop_list,name,M_PROPERTY_TO_STRING,arg,ctx)) != if ((r = do_action(prop_list, name, M_PROPERTY_TO_STRING, arg, ctx)) !=
M_PROPERTY_NOT_IMPLEMENTED) M_PROPERTY_NOT_IMPLEMENTED)
return r; return r;
// fallback on the options API. Get the type, value and print. // fallback on the options API. Get the type, value and print.
if((r = do_action(prop_list,name,M_PROPERTY_GET_TYPE,&opt,ctx)) <= 0) if ((r =
do_action(prop_list, name, M_PROPERTY_GET_TYPE, &opt, ctx)) <= 0)
return r; return r;
val = calloc(1,opt->type->size); val = calloc(1, opt->type->size);
if((r = do_action(prop_list,name,M_PROPERTY_GET,val,ctx)) <= 0) { if ((r = do_action(prop_list, name, M_PROPERTY_GET, val, ctx)) <= 0) {
free(val); free(val);
return r; return r;
} }
if(!arg) return M_PROPERTY_ERROR; if (!arg)
str = m_option_print(opt,val); return M_PROPERTY_ERROR;
str = m_option_print(opt, val);
free(val); free(val);
*(char**)arg = str == (char*)-1 ? NULL : str; *(char **)arg = str == (char *)-1 ? NULL : str;
return str != (char*)-1; return str != (char *)-1;
case M_PROPERTY_PARSE: case M_PROPERTY_PARSE:
// try the property own parsing func // try the property own parsing func
if((r = do_action(prop_list,name,M_PROPERTY_PARSE,arg,ctx)) != if ((r = do_action(prop_list, name, M_PROPERTY_PARSE, arg, ctx)) !=
M_PROPERTY_NOT_IMPLEMENTED) M_PROPERTY_NOT_IMPLEMENTED)
return r; return r;
// fallback on the options API, get the type and parse. // fallback on the options API, get the type and parse.
if((r = do_action(prop_list,name,M_PROPERTY_GET_TYPE,&opt,ctx)) <= 0) if ((r =
do_action(prop_list, name, M_PROPERTY_GET_TYPE, &opt, ctx)) <= 0)
return r; return r;
if(!arg) return M_PROPERTY_ERROR; if (!arg)
val = calloc(1,opt->type->size); return M_PROPERTY_ERROR;
if((r = m_option_parse(opt,opt->name,arg,val,M_CONFIG_FILE)) <= 0) { val = calloc(1, opt->type->size);
if ((r =
m_option_parse(opt, opt->name, arg, val, M_CONFIG_FILE)) <= 0) {
free(val); free(val);
return r; return r;
} }
r = do_action(prop_list,name,M_PROPERTY_SET,val,ctx); r = do_action(prop_list, name, M_PROPERTY_SET, val, ctx);
m_option_free(opt,val); m_option_free(opt, val);
free(val); free(val);
return r; return r;
} }
return do_action(prop_list,name,action,arg,ctx); return do_action(prop_list, name, action, arg, ctx);
} }
char* m_properties_expand_string(const m_option_t* prop_list,char* str, void *ctx) { char *m_properties_expand_string(const m_option_t *prop_list, char *str,
int l,fr=0,pos=0,size=strlen(str)+512; void *ctx)
char *p = NULL,*e,*ret = malloc(size), num_val; {
int l, fr = 0, pos = 0, size = strlen(str) + 512;
char *p = NULL, *e, *ret = malloc(size), num_val;
int skip = 0, lvl = 0, skip_lvl = 0; int skip = 0, lvl = 0, skip_lvl = 0;
while(str[0]) { while (str[0]) {
if(str[0] == '\\') { if (str[0] == '\\') {
int sl = 1; int sl = 1;
switch(str[1]) { switch (str[1]) {
case 'e': case 'e':
p = "\x1b", l = 1; break; p = "\x1b", l = 1; break;
case 'n': case 'n':
@ -130,84 +141,91 @@ char* m_properties_expand_string(const m_option_t* prop_list,char* str, void *ct
case 't': case 't':
p = "\t", l = 1; break; p = "\t", l = 1; break;
case 'x': case 'x':
if(str[2]) { if (str[2]) {
char num[3] = { str[2], str[3], 0 }; char num[3] = { str[2], str[3], 0 };
char* end = num; char *end = num;
num_val = strtol(num,&end,16); num_val = strtol(num, &end, 16);
sl = end-num; sl = end - num;
l = 1; l = 1;
p = &num_val; p = &num_val;
} else } else
l = 0; l = 0;
break; break;
default: default:
p = str+1, l = 1; p = str + 1, l = 1;
} }
str+=1+sl; str += 1 + sl;
} else if(lvl > 0 && str[0] == ')') { } else if (lvl > 0 && str[0] == ')') {
if(skip && lvl <= skip_lvl) skip = 0; if (skip && lvl <= skip_lvl)
skip = 0;
lvl--, str++, l = 0; lvl--, str++, l = 0;
} else if(str[0] == '$' && str[1] == '{' && (e = strchr(str+2,'}'))) { } else if (str[0] == '$' && str[1] == '{'
int pl = e-str-2; && (e = strchr(str + 2, '}'))) {
char pname[pl+1]; int pl = e - str - 2;
memcpy(pname,str+2,pl); char pname[pl + 1];
memcpy(pname, str + 2, pl);
pname[pl] = 0; pname[pl] = 0;
if(m_property_do(prop_list, pname, if (m_property_do(prop_list, pname,
M_PROPERTY_PRINT, &p, ctx) >= 0 && p) M_PROPERTY_PRINT, &p, ctx) >= 0 && p)
l = strlen(p), fr = 1; l = strlen(p), fr = 1;
else else
l = 0; l = 0;
str = e+1; str = e + 1;
} else if(str[0] == '?' && str[1] == '(' && (e = strchr(str+2,':'))) { } else if (str[0] == '?' && str[1] == '('
&& (e = strchr(str + 2, ':'))) {
lvl++; lvl++;
if(!skip) { if (!skip) {
int is_not = str[2] == '!'; int is_not = str[2] == '!';
int pl = e - str - (is_not ? 3 : 2); int pl = e - str - (is_not ? 3 : 2);
char pname[pl+1]; char pname[pl + 1];
memcpy(pname, str + (is_not ? 3 : 2), pl); memcpy(pname, str + (is_not ? 3 : 2), pl);
pname[pl] = 0; pname[pl] = 0;
if(m_property_do(prop_list,pname,M_PROPERTY_GET,NULL,ctx) < 0) { if (m_property_do(prop_list, pname, M_PROPERTY_GET, NULL, ctx) < 0) {
if (!is_not) if (!is_not)
skip = 1, skip_lvl = lvl; skip = 1, skip_lvl = lvl;
} } else if (is_not)
else if (is_not)
skip = 1, skip_lvl = lvl; skip = 1, skip_lvl = lvl;
} }
str = e+1, l = 0; str = e + 1, l = 0;
} else } else
p = str, l = 1, str++; p = str, l = 1, str++;
if(skip || l <= 0) continue; if (skip || l <= 0)
continue;
if(pos+l+1 > size) { if (pos + l + 1 > size) {
size = pos+l+512; size = pos + l + 512;
ret = realloc(ret,size); ret = realloc(ret, size);
} }
memcpy(ret+pos,p,l); memcpy(ret + pos, p, l);
pos += l; pos += l;
if(fr) free(p), fr = 0; if (fr)
free(p), fr = 0;
} }
ret[pos] = 0; ret[pos] = 0;
return ret; return ret;
} }
void m_properties_print_help_list(const m_option_t* list) { void m_properties_print_help_list(const m_option_t *list)
char min[50],max[50]; {
int i,count = 0; char min[50], max[50];
int i, count = 0;
mp_tmsg(MSGT_CFGPARSER, MSGL_INFO, "\n Name Type Min Max\n\n"); mp_tmsg(MSGT_CFGPARSER, MSGL_INFO,
for(i = 0 ; list[i].name ; i++) { "\n Name Type Min Max\n\n");
const m_option_t* opt = &list[i]; for (i = 0; list[i].name; i++) {
if(opt->flags & M_OPT_MIN) const m_option_t *opt = &list[i];
sprintf(min,"%-8.0f",opt->min); if (opt->flags & M_OPT_MIN)
sprintf(min, "%-8.0f", opt->min);
else else
strcpy(min,"No"); strcpy(min, "No");
if(opt->flags & M_OPT_MAX) if (opt->flags & M_OPT_MAX)
sprintf(max,"%-8.0f",opt->max); sprintf(max, "%-8.0f", opt->max);
else else
strcpy(max,"No"); strcpy(max, "No");
mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %-20.20s %-15.15s %-10.10s %-10.10s\n", mp_msg(MSGT_CFGPARSER, MSGL_INFO,
" %-20.20s %-15.15s %-10.10s %-10.10s\n",
opt->name, opt->name,
opt->type->name, opt->type->name,
min, min,
@ -219,62 +237,70 @@ void m_properties_print_help_list(const m_option_t* list) {
// Some generic property implementations // Some generic property implementations
int m_property_int_ro(const m_option_t* prop,int action, int m_property_int_ro(const m_option_t *prop, int action,
void* arg,int var) { void *arg, int var)
switch(action) { {
switch (action) {
case M_PROPERTY_GET: case M_PROPERTY_GET:
if(!arg) return 0; if (!arg)
*(int*)arg = var; return 0;
*(int *)arg = var;
return 1; return 1;
} }
return M_PROPERTY_NOT_IMPLEMENTED; return M_PROPERTY_NOT_IMPLEMENTED;
} }
int m_property_int_range(const m_option_t* prop,int action, int m_property_int_range(const m_option_t *prop, int action,
void* arg,int* var) { void *arg, int *var)
switch(action) { {
switch (action) {
case M_PROPERTY_SET: case M_PROPERTY_SET:
if(!arg) return 0; if (!arg)
M_PROPERTY_CLAMP(prop,*(int*)arg); return 0;
*var = *(int*)arg; M_PROPERTY_CLAMP(prop, *(int *)arg);
*var = *(int *)arg;
return 1; return 1;
case M_PROPERTY_STEP_UP: case M_PROPERTY_STEP_UP:
case M_PROPERTY_STEP_DOWN: case M_PROPERTY_STEP_DOWN:
*var += (arg ? *(int*)arg : 1) * *var += (arg ? *(int *)arg : 1) *
(action == M_PROPERTY_STEP_DOWN ? -1 : 1); (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
M_PROPERTY_CLAMP(prop,*var); M_PROPERTY_CLAMP(prop, *var);
return 1; return 1;
} }
return m_property_int_ro(prop,action,arg,*var); return m_property_int_ro(prop, action, arg, *var);
} }
int m_property_choice(const m_option_t* prop,int action, int m_property_choice(const m_option_t *prop, int action,
void* arg,int* var) { void *arg, int *var)
switch(action) { {
switch (action) {
case M_PROPERTY_STEP_UP: case M_PROPERTY_STEP_UP:
case M_PROPERTY_STEP_DOWN: case M_PROPERTY_STEP_DOWN:
*var += action == M_PROPERTY_STEP_UP ? 1 : prop->max; *var += action == M_PROPERTY_STEP_UP ? 1 : prop->max;
*var %= (int)prop->max+1; *var %= (int)prop->max + 1;
return 1; return 1;
} }
return m_property_int_range(prop,action,arg,var); return m_property_int_range(prop, action, arg, var);
} }
int m_property_flag_ro(const m_option_t* prop,int action, int m_property_flag_ro(const m_option_t *prop, int action,
void* arg,int var) { void *arg, int var)
switch(action) { {
switch (action) {
case M_PROPERTY_PRINT: case M_PROPERTY_PRINT:
if(!arg) return 0; if (!arg)
*(char**)arg = strdup((var > prop->min) ? return 0;
mp_gtext("enabled") : mp_gtext("disabled")); *(char **)arg = strdup((var > prop->min) ?
mp_gtext("enabled") : mp_gtext("disabled"));
return 1; return 1;
} }
return m_property_int_ro(prop,action,arg,var); return m_property_int_ro(prop, action, arg, var);
} }
int m_property_flag(const m_option_t* prop,int action, int m_property_flag(const m_option_t *prop, int action,
void* arg,int* var) { void *arg, int *var)
switch(action) { {
switch (action) {
case M_PROPERTY_STEP_UP: case M_PROPERTY_STEP_UP:
case M_PROPERTY_STEP_DOWN: case M_PROPERTY_STEP_DOWN:
*var = *var == prop->min ? prop->max : prop->min; *var = *var == prop->min ? prop->max : prop->min;
@ -282,118 +308,134 @@ int m_property_flag(const m_option_t* prop,int action,
case M_PROPERTY_PRINT: case M_PROPERTY_PRINT:
return m_property_flag_ro(prop, action, arg, *var); return m_property_flag_ro(prop, action, arg, *var);
} }
return m_property_int_range(prop,action,arg,var); return m_property_int_range(prop, action, arg, var);
} }
int m_property_float_ro(const m_option_t* prop,int action, int m_property_float_ro(const m_option_t *prop, int action,
void* arg,float var) { void *arg, float var)
switch(action) { {
switch (action) {
case M_PROPERTY_GET: case M_PROPERTY_GET:
if(!arg) return 0; if (!arg)
*(float*)arg = var; return 0;
*(float *)arg = var;
return 1; return 1;
case M_PROPERTY_PRINT: case M_PROPERTY_PRINT:
if(!arg) return 0; if (!arg)
*(char**)arg = malloc(20); return 0;
sprintf(*(char**)arg,"%.2f",var); *(char **)arg = malloc(20);
sprintf(*(char **)arg, "%.2f", var);
return 1; return 1;
} }
return M_PROPERTY_NOT_IMPLEMENTED; return M_PROPERTY_NOT_IMPLEMENTED;
} }
int m_property_float_range(const m_option_t* prop,int action, int m_property_float_range(const m_option_t *prop, int action,
void* arg,float* var) { void *arg, float *var)
switch(action) { {
switch (action) {
case M_PROPERTY_SET: case M_PROPERTY_SET:
if(!arg) return 0; if (!arg)
M_PROPERTY_CLAMP(prop,*(float*)arg); return 0;
*var = *(float*)arg; M_PROPERTY_CLAMP(prop, *(float *)arg);
*var = *(float *)arg;
return 1; return 1;
case M_PROPERTY_STEP_UP: case M_PROPERTY_STEP_UP:
case M_PROPERTY_STEP_DOWN: case M_PROPERTY_STEP_DOWN:
*var += (arg ? *(float*)arg : 0.1) * *var += (arg ? *(float *)arg : 0.1) *
(action == M_PROPERTY_STEP_DOWN ? -1 : 1); (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
M_PROPERTY_CLAMP(prop,*var); M_PROPERTY_CLAMP(prop, *var);
return 1; return 1;
} }
return m_property_float_ro(prop,action,arg,*var); return m_property_float_ro(prop, action, arg, *var);
} }
int m_property_delay(const m_option_t* prop,int action, int m_property_delay(const m_option_t *prop, int action,
void* arg,float* var) { void *arg, float *var)
switch(action) { {
case M_PROPERTY_PRINT: switch (action) {
if(!arg) return 0;
*(char**)arg = malloc(20);
sprintf(*(char**)arg,"%d ms",ROUND((*var)*1000));
return 1;
default:
return m_property_float_range(prop,action,arg,var);
}
}
int m_property_double_ro(const m_option_t* prop,int action,
void* arg,double var) {
switch(action) {
case M_PROPERTY_GET:
if(!arg) return 0;
*(double*)arg = var;
return 1;
case M_PROPERTY_PRINT:
if(!arg) return 0;
*(char**)arg = malloc(20);
sprintf(*(char**)arg,"%.2f",var);
return 1;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
int m_property_time_ro(const m_option_t* prop,int action,
void* arg,double var) {
switch(action) {
case M_PROPERTY_PRINT:
if (!arg)
return M_PROPERTY_ERROR;
else {
int h, m, s = var;
h = s / 3600;
s -= h * 3600;
m = s / 60;
s -= m * 60;
*(char **) arg = malloc(20);
if (h > 0)
sprintf(*(char **) arg, "%d:%02d:%02d", h, m, s);
else if (m > 0)
sprintf(*(char **) arg, "%d:%02d", m, s);
else
sprintf(*(char **) arg, "%d", s);
return M_PROPERTY_OK;
}
}
return m_property_double_ro(prop,action,arg,var);
}
int m_property_string_ro(const m_option_t* prop,int action,void* arg,char* str) {
switch(action) {
case M_PROPERTY_GET:
if(!arg) return 0;
*(char**)arg = str;
return 1;
case M_PROPERTY_PRINT:
if(!arg) return 0;
*(char**)arg = str ? strdup(str) : NULL;
return 1;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
int m_property_bitrate(const m_option_t* prop,int action,void* arg,int rate) {
switch(action) {
case M_PROPERTY_PRINT: case M_PROPERTY_PRINT:
if (!arg) if (!arg)
return M_PROPERTY_ERROR; return 0;
*(char**)arg = malloc (16); *(char **)arg = malloc(20);
sprintf(*(char**)arg, "%d kbps", rate*8/1000); sprintf(*(char **)arg, "%d ms", ROUND((*var) * 1000));
return 1;
default:
return m_property_float_range(prop, action, arg, var);
}
}
int m_property_double_ro(const m_option_t *prop, int action,
void *arg, double var)
{
switch (action) {
case M_PROPERTY_GET:
if (!arg)
return 0;
*(double *)arg = var;
return 1;
case M_PROPERTY_PRINT:
if (!arg)
return 0;
*(char **)arg = malloc(20);
sprintf(*(char **)arg, "%.2f", var);
return 1;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
int m_property_time_ro(const m_option_t *prop, int action,
void *arg, double var)
{
switch (action) {
case M_PROPERTY_PRINT:
if (!arg)
return M_PROPERTY_ERROR;
else {
int h, m, s = var;
h = s / 3600;
s -= h * 3600;
m = s / 60;
s -= m * 60;
*(char **) arg = malloc(20);
if (h > 0)
sprintf(*(char **) arg, "%d:%02d:%02d", h, m, s);
else if (m > 0)
sprintf(*(char **) arg, "%d:%02d", m, s);
else
sprintf(*(char **) arg, "%d", s);
return M_PROPERTY_OK;
}
}
return m_property_double_ro(prop, action, arg, var);
}
int m_property_string_ro(const m_option_t *prop, int action, void *arg,
char *str)
{
switch (action) {
case M_PROPERTY_GET:
if (!arg)
return 0;
*(char **)arg = str;
return 1;
case M_PROPERTY_PRINT:
if (!arg)
return 0;
*(char **)arg = str ? strdup(str) : NULL;
return 1;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
int m_property_bitrate(const m_option_t *prop, int action, void *arg, int rate)
{
switch (action) {
case M_PROPERTY_PRINT:
if (!arg)
return M_PROPERTY_ERROR;
*(char **)arg = malloc(16);
sprintf(*(char **)arg, "%d kbps", rate * 8 / 1000);
return M_PROPERTY_OK; return M_PROPERTY_OK;
} }
return m_property_int_ro(prop, action, arg, rate); return m_property_int_ro(prop, action, arg, rate);