2010-01-31 00:24:23 +01:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* 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
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2006-03-22 01:19:02 +01:00
|
|
|
|
2006-04-24 21:20:04 +02:00
|
|
|
/// \file
|
|
|
|
/// \ingroup Properties
|
|
|
|
|
2006-03-22 01:19:02 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2011-07-03 19:04:21 +02:00
|
|
|
#include "talloc.h"
|
2006-03-22 01:19:02 +01:00
|
|
|
#include "m_option.h"
|
|
|
|
#include "m_property.h"
|
2006-03-22 17:35:17 +01:00
|
|
|
#include "mp_msg.h"
|
2011-01-03 20:39:31 +01:00
|
|
|
#include "mpcommon.h"
|
2006-03-22 01:19:02 +01:00
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
static int do_action(const m_option_t *prop_list, const char *name,
|
|
|
|
int action, void *arg, void *ctx)
|
|
|
|
{
|
|
|
|
const char *sep;
|
|
|
|
const m_option_t *prop;
|
2007-05-29 23:49:39 +02:00
|
|
|
m_property_action_t ka;
|
|
|
|
int r;
|
2011-07-03 14:42:04 +02:00
|
|
|
if ((sep = strchr(name, '/')) && sep[1]) {
|
|
|
|
int len = sep - name;
|
|
|
|
char base[len + 1];
|
|
|
|
memcpy(base, name, len);
|
2007-05-29 23:49:39 +02:00
|
|
|
base[len] = 0;
|
|
|
|
prop = m_option_list_find(prop_list, base);
|
2011-07-03 14:42:04 +02:00
|
|
|
ka.key = sep + 1;
|
2007-05-29 23:49:39 +02:00
|
|
|
ka.action = action;
|
|
|
|
ka.arg = arg;
|
|
|
|
action = M_PROPERTY_KEY_ACTION;
|
|
|
|
arg = &ka;
|
|
|
|
} else
|
|
|
|
prop = m_option_list_find(prop_list, name);
|
2011-07-03 14:42:04 +02:00
|
|
|
if (!prop)
|
|
|
|
return M_PROPERTY_UNKNOWN;
|
|
|
|
r = ((m_property_ctrl_f)prop->p)(prop, action, arg, ctx);
|
|
|
|
if (action == M_PROPERTY_GET_TYPE && r < 0) {
|
|
|
|
if (!arg)
|
|
|
|
return M_PROPERTY_ERROR;
|
|
|
|
*(const m_option_t **)arg = prop;
|
2007-05-29 23:49:39 +02:00
|
|
|
return M_PROPERTY_OK;
|
2006-03-22 01:19:02 +01:00
|
|
|
}
|
2007-05-29 23:49:39 +02:00
|
|
|
return r;
|
2006-03-22 01:19:02 +01:00
|
|
|
}
|
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
int m_property_do(const m_option_t *prop_list, const char *name,
|
|
|
|
int action, void *arg, void *ctx)
|
|
|
|
{
|
|
|
|
const m_option_t *opt;
|
|
|
|
void *val;
|
2006-03-22 01:19:02 +01:00
|
|
|
int r;
|
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
switch (action) {
|
2007-05-29 23:49:39 +02:00
|
|
|
case M_PROPERTY_PRINT:
|
2011-07-03 14:42:04 +02:00
|
|
|
if ((r = do_action(prop_list, name, M_PROPERTY_PRINT, arg, ctx)) >= 0)
|
2007-05-29 23:49:39 +02:00
|
|
|
return r;
|
2011-07-03 14:42:04 +02:00
|
|
|
// fallback on the default print for this type
|
2007-05-29 23:49:39 +02:00
|
|
|
case M_PROPERTY_TO_STRING:
|
2011-07-03 14:42:04 +02:00
|
|
|
if ((r = do_action(prop_list, name, M_PROPERTY_TO_STRING, arg, ctx)) !=
|
|
|
|
M_PROPERTY_NOT_IMPLEMENTED)
|
2007-05-29 23:49:39 +02:00
|
|
|
return r;
|
|
|
|
// fallback on the options API. Get the type, value and print.
|
2011-07-03 14:42:04 +02:00
|
|
|
if ((r =
|
|
|
|
do_action(prop_list, name, M_PROPERTY_GET_TYPE, &opt, ctx)) <= 0)
|
2007-05-29 23:49:39 +02:00
|
|
|
return r;
|
2011-07-03 14:42:04 +02:00
|
|
|
val = calloc(1, opt->type->size);
|
|
|
|
if ((r = do_action(prop_list, name, M_PROPERTY_GET, val, ctx)) <= 0) {
|
2007-05-29 23:49:39 +02:00
|
|
|
free(val);
|
|
|
|
return r;
|
|
|
|
}
|
2011-07-03 14:42:04 +02:00
|
|
|
if (!arg)
|
|
|
|
return M_PROPERTY_ERROR;
|
2011-07-03 19:04:21 +02:00
|
|
|
char *str = m_option_print(opt, val);
|
2007-05-29 23:49:39 +02:00
|
|
|
free(val);
|
2011-07-03 19:04:21 +02:00
|
|
|
*(char **)arg = str;
|
|
|
|
return str != NULL;
|
2007-05-29 23:49:39 +02:00
|
|
|
case M_PROPERTY_PARSE:
|
|
|
|
// try the property own parsing func
|
2011-07-03 14:42:04 +02:00
|
|
|
if ((r = do_action(prop_list, name, M_PROPERTY_PARSE, arg, ctx)) !=
|
|
|
|
M_PROPERTY_NOT_IMPLEMENTED)
|
2007-05-29 23:49:39 +02:00
|
|
|
return r;
|
|
|
|
// fallback on the options API, get the type and parse.
|
2011-07-03 14:42:04 +02:00
|
|
|
if ((r =
|
|
|
|
do_action(prop_list, name, M_PROPERTY_GET_TYPE, &opt, ctx)) <= 0)
|
2007-05-29 23:49:39 +02:00
|
|
|
return r;
|
2011-07-03 14:42:04 +02:00
|
|
|
if (!arg)
|
|
|
|
return M_PROPERTY_ERROR;
|
|
|
|
val = calloc(1, opt->type->size);
|
2011-07-28 10:07:47 +02:00
|
|
|
if ((r = m_option_parse(opt, bstr(opt->name), bstr(arg), false,
|
|
|
|
val)) <= 0) {
|
2007-05-29 23:49:39 +02:00
|
|
|
free(val);
|
|
|
|
return r;
|
|
|
|
}
|
2011-07-03 14:42:04 +02:00
|
|
|
r = do_action(prop_list, name, M_PROPERTY_SET, val, ctx);
|
|
|
|
m_option_free(opt, val);
|
2006-03-22 01:19:02 +01:00
|
|
|
free(val);
|
|
|
|
return r;
|
|
|
|
}
|
2011-07-03 14:42:04 +02:00
|
|
|
return do_action(prop_list, name, action, arg, ctx);
|
2006-03-22 01:19:02 +01:00
|
|
|
}
|
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
char *m_properties_expand_string(const m_option_t *prop_list, char *str,
|
|
|
|
void *ctx)
|
|
|
|
{
|
|
|
|
int l, fr = 0, pos = 0, size = strlen(str) + 512;
|
|
|
|
char *p = NULL, *e, *ret = malloc(size), num_val;
|
2006-03-22 01:19:02 +01:00
|
|
|
int skip = 0, lvl = 0, skip_lvl = 0;
|
2009-07-07 01:26:13 +02:00
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
while (str[0]) {
|
|
|
|
if (str[0] == '\\') {
|
2006-03-22 01:19:02 +01:00
|
|
|
int sl = 1;
|
2011-07-03 14:42:04 +02:00
|
|
|
switch (str[1]) {
|
2006-03-22 01:19:02 +01:00
|
|
|
case 'e':
|
|
|
|
p = "\x1b", l = 1; break;
|
|
|
|
case 'n':
|
|
|
|
p = "\n", l = 1; break;
|
|
|
|
case 'r':
|
|
|
|
p = "\r", l = 1; break;
|
|
|
|
case 't':
|
|
|
|
p = "\t", l = 1; break;
|
2009-07-07 01:26:13 +02:00
|
|
|
case 'x':
|
2011-07-03 14:42:04 +02:00
|
|
|
if (str[2]) {
|
2006-03-22 01:19:02 +01:00
|
|
|
char num[3] = { str[2], str[3], 0 };
|
2011-07-03 14:42:04 +02:00
|
|
|
char *end = num;
|
|
|
|
num_val = strtol(num, &end, 16);
|
2011-08-01 16:19:01 +02:00
|
|
|
sl = end - num + 1;
|
2006-03-22 01:19:02 +01:00
|
|
|
l = 1;
|
|
|
|
p = &num_val;
|
|
|
|
} else
|
|
|
|
l = 0;
|
|
|
|
break;
|
|
|
|
default:
|
2011-07-03 14:42:04 +02:00
|
|
|
p = str + 1, l = 1;
|
2006-03-22 01:19:02 +01:00
|
|
|
}
|
2011-07-03 14:42:04 +02:00
|
|
|
str += 1 + sl;
|
|
|
|
} else if (lvl > 0 && str[0] == ')') {
|
|
|
|
if (skip && lvl <= skip_lvl)
|
|
|
|
skip = 0;
|
2006-03-22 01:19:02 +01:00
|
|
|
lvl--, str++, l = 0;
|
2011-07-03 14:42:04 +02:00
|
|
|
} else if (str[0] == '$' && str[1] == '{'
|
|
|
|
&& (e = strchr(str + 2, '}'))) {
|
|
|
|
int pl = e - str - 2;
|
|
|
|
char pname[pl + 1];
|
|
|
|
memcpy(pname, str + 2, pl);
|
2006-03-22 01:19:02 +01:00
|
|
|
pname[pl] = 0;
|
2011-07-03 14:42:04 +02:00
|
|
|
if (m_property_do(prop_list, pname,
|
|
|
|
M_PROPERTY_PRINT, &p, ctx) >= 0 && p)
|
2006-03-22 01:19:02 +01:00
|
|
|
l = strlen(p), fr = 1;
|
|
|
|
else
|
|
|
|
l = 0;
|
2011-07-03 14:42:04 +02:00
|
|
|
str = e + 1;
|
|
|
|
} else if (str[0] == '?' && str[1] == '('
|
|
|
|
&& (e = strchr(str + 2, ':'))) {
|
2006-03-22 01:19:02 +01:00
|
|
|
lvl++;
|
2011-07-03 14:42:04 +02:00
|
|
|
if (!skip) {
|
2007-12-26 05:15:56 +01:00
|
|
|
int is_not = str[2] == '!';
|
|
|
|
int pl = e - str - (is_not ? 3 : 2);
|
2011-07-03 14:42:04 +02:00
|
|
|
char pname[pl + 1];
|
2007-12-26 05:15:56 +01:00
|
|
|
memcpy(pname, str + (is_not ? 3 : 2), pl);
|
2006-03-22 01:19:02 +01:00
|
|
|
pname[pl] = 0;
|
2011-07-03 14:42:04 +02:00
|
|
|
if (m_property_do(prop_list, pname, M_PROPERTY_GET, NULL, ctx) < 0) {
|
2007-12-26 05:15:56 +01:00
|
|
|
if (!is_not)
|
|
|
|
skip = 1, skip_lvl = lvl;
|
2011-07-03 14:42:04 +02:00
|
|
|
} else if (is_not)
|
2006-03-22 01:19:02 +01:00
|
|
|
skip = 1, skip_lvl = lvl;
|
|
|
|
}
|
2011-07-03 14:42:04 +02:00
|
|
|
str = e + 1, l = 0;
|
2006-03-22 01:19:02 +01:00
|
|
|
} else
|
|
|
|
p = str, l = 1, str++;
|
2009-07-07 01:26:13 +02:00
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
if (skip || l <= 0)
|
|
|
|
continue;
|
2009-07-07 01:26:13 +02:00
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
if (pos + l + 1 > size) {
|
|
|
|
size = pos + l + 512;
|
|
|
|
ret = realloc(ret, size);
|
2006-03-22 01:19:02 +01:00
|
|
|
}
|
2011-07-03 14:42:04 +02:00
|
|
|
memcpy(ret + pos, p, l);
|
2006-03-22 01:19:02 +01:00
|
|
|
pos += l;
|
2011-07-03 14:42:04 +02:00
|
|
|
if (fr)
|
2011-07-03 19:04:21 +02:00
|
|
|
talloc_free(p), fr = 0;
|
2006-03-22 01:19:02 +01:00
|
|
|
}
|
2009-07-07 01:26:13 +02:00
|
|
|
|
2006-03-22 01:19:02 +01:00
|
|
|
ret[pos] = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
void m_properties_print_help_list(const m_option_t *list)
|
|
|
|
{
|
|
|
|
char min[50], max[50];
|
|
|
|
int i, count = 0;
|
2009-07-07 01:26:13 +02:00
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
mp_tmsg(MSGT_CFGPARSER, MSGL_INFO,
|
|
|
|
"\n Name Type Min Max\n\n");
|
|
|
|
for (i = 0; list[i].name; i++) {
|
|
|
|
const m_option_t *opt = &list[i];
|
|
|
|
if (opt->flags & M_OPT_MIN)
|
|
|
|
sprintf(min, "%-8.0f", opt->min);
|
2006-03-22 17:35:17 +01:00
|
|
|
else
|
2011-07-03 14:42:04 +02:00
|
|
|
strcpy(min, "No");
|
|
|
|
if (opt->flags & M_OPT_MAX)
|
|
|
|
sprintf(max, "%-8.0f", opt->max);
|
2006-03-22 17:35:17 +01:00
|
|
|
else
|
2011-07-03 14:42:04 +02:00
|
|
|
strcpy(max, "No");
|
|
|
|
mp_msg(MSGT_CFGPARSER, MSGL_INFO,
|
|
|
|
" %-20.20s %-15.15s %-10.10s %-10.10s\n",
|
2006-03-22 17:35:17 +01:00
|
|
|
opt->name,
|
|
|
|
opt->type->name,
|
|
|
|
min,
|
2006-03-23 01:41:22 +01:00
|
|
|
max);
|
2006-03-22 17:35:17 +01:00
|
|
|
count++;
|
|
|
|
}
|
2009-07-07 00:15:02 +02:00
|
|
|
mp_tmsg(MSGT_CFGPARSER, MSGL_INFO, "\nTotal: %d properties\n", count);
|
2006-03-22 17:35:17 +01:00
|
|
|
}
|
|
|
|
|
2006-03-22 01:19:02 +01:00
|
|
|
// Some generic property implementations
|
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
int m_property_int_ro(const m_option_t *prop, int action,
|
|
|
|
void *arg, int var)
|
|
|
|
{
|
|
|
|
switch (action) {
|
2006-03-22 01:19:02 +01:00
|
|
|
case M_PROPERTY_GET:
|
2011-07-03 14:42:04 +02:00
|
|
|
if (!arg)
|
|
|
|
return 0;
|
|
|
|
*(int *)arg = var;
|
2006-03-22 01:19:02 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
int m_property_int_range(const m_option_t *prop, int action,
|
|
|
|
void *arg, int *var)
|
|
|
|
{
|
|
|
|
switch (action) {
|
2006-03-22 01:19:02 +01:00
|
|
|
case M_PROPERTY_SET:
|
2011-07-03 14:42:04 +02:00
|
|
|
if (!arg)
|
|
|
|
return 0;
|
|
|
|
M_PROPERTY_CLAMP(prop, *(int *)arg);
|
|
|
|
*var = *(int *)arg;
|
2006-03-22 01:19:02 +01:00
|
|
|
return 1;
|
|
|
|
case M_PROPERTY_STEP_UP:
|
|
|
|
case M_PROPERTY_STEP_DOWN:
|
2011-07-03 14:42:04 +02:00
|
|
|
*var += (arg ? *(int *)arg : 1) *
|
|
|
|
(action == M_PROPERTY_STEP_DOWN ? -1 : 1);
|
|
|
|
M_PROPERTY_CLAMP(prop, *var);
|
2006-03-22 01:19:02 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2011-07-03 14:42:04 +02:00
|
|
|
return m_property_int_ro(prop, action, arg, *var);
|
2006-03-22 01:19:02 +01:00
|
|
|
}
|
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
int m_property_choice(const m_option_t *prop, int action,
|
|
|
|
void *arg, int *var)
|
|
|
|
{
|
|
|
|
switch (action) {
|
2006-03-22 01:19:02 +01:00
|
|
|
case M_PROPERTY_STEP_UP:
|
|
|
|
case M_PROPERTY_STEP_DOWN:
|
|
|
|
*var += action == M_PROPERTY_STEP_UP ? 1 : prop->max;
|
2011-07-03 14:42:04 +02:00
|
|
|
*var %= (int)prop->max + 1;
|
2006-03-22 01:19:02 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2011-07-03 14:42:04 +02:00
|
|
|
return m_property_int_range(prop, action, arg, var);
|
2006-03-22 01:19:02 +01:00
|
|
|
}
|
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
int m_property_flag_ro(const m_option_t *prop, int action,
|
|
|
|
void *arg, int var)
|
|
|
|
{
|
|
|
|
switch (action) {
|
2008-10-01 19:05:18 +02:00
|
|
|
case M_PROPERTY_PRINT:
|
2011-07-03 14:42:04 +02:00
|
|
|
if (!arg)
|
|
|
|
return 0;
|
2011-07-03 19:04:21 +02:00
|
|
|
*(char **)arg = talloc_strdup(NULL, (var > prop->min) ?
|
2011-07-03 14:42:04 +02:00
|
|
|
mp_gtext("enabled") : mp_gtext("disabled"));
|
2008-10-01 19:05:18 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2011-07-03 14:42:04 +02:00
|
|
|
return m_property_int_ro(prop, action, arg, var);
|
2008-10-01 19:05:18 +02:00
|
|
|
}
|
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
int m_property_flag(const m_option_t *prop, int action,
|
|
|
|
void *arg, int *var)
|
|
|
|
{
|
|
|
|
switch (action) {
|
2006-03-22 01:19:02 +01:00
|
|
|
case M_PROPERTY_STEP_UP:
|
|
|
|
case M_PROPERTY_STEP_DOWN:
|
|
|
|
*var = *var == prop->min ? prop->max : prop->min;
|
|
|
|
return 1;
|
|
|
|
case M_PROPERTY_PRINT:
|
2008-10-01 19:05:18 +02:00
|
|
|
return m_property_flag_ro(prop, action, arg, *var);
|
2006-03-22 01:19:02 +01:00
|
|
|
}
|
2011-07-03 14:42:04 +02:00
|
|
|
return m_property_int_range(prop, action, arg, var);
|
2006-03-22 01:19:02 +01:00
|
|
|
}
|
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
int m_property_float_ro(const m_option_t *prop, int action,
|
|
|
|
void *arg, float var)
|
|
|
|
{
|
|
|
|
switch (action) {
|
2006-03-22 01:19:02 +01:00
|
|
|
case M_PROPERTY_GET:
|
2011-07-03 14:42:04 +02:00
|
|
|
if (!arg)
|
|
|
|
return 0;
|
|
|
|
*(float *)arg = var;
|
2006-03-22 01:19:02 +01:00
|
|
|
return 1;
|
|
|
|
case M_PROPERTY_PRINT:
|
2011-07-03 14:42:04 +02:00
|
|
|
if (!arg)
|
|
|
|
return 0;
|
2011-07-03 19:04:21 +02:00
|
|
|
*(char **)arg = talloc_asprintf(NULL, "%.2f", var);
|
2006-03-22 01:19:02 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
int m_property_float_range(const m_option_t *prop, int action,
|
|
|
|
void *arg, float *var)
|
|
|
|
{
|
|
|
|
switch (action) {
|
2006-03-22 01:19:02 +01:00
|
|
|
case M_PROPERTY_SET:
|
2011-07-03 14:42:04 +02:00
|
|
|
if (!arg)
|
|
|
|
return 0;
|
|
|
|
M_PROPERTY_CLAMP(prop, *(float *)arg);
|
|
|
|
*var = *(float *)arg;
|
2006-03-22 01:19:02 +01:00
|
|
|
return 1;
|
|
|
|
case M_PROPERTY_STEP_UP:
|
|
|
|
case M_PROPERTY_STEP_DOWN:
|
2011-07-03 14:42:04 +02:00
|
|
|
*var += (arg ? *(float *)arg : 0.1) *
|
|
|
|
(action == M_PROPERTY_STEP_DOWN ? -1 : 1);
|
|
|
|
M_PROPERTY_CLAMP(prop, *var);
|
2006-03-22 01:19:02 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2011-07-03 14:42:04 +02:00
|
|
|
return m_property_float_ro(prop, action, arg, *var);
|
2006-03-22 01:19:02 +01:00
|
|
|
}
|
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
int m_property_delay(const m_option_t *prop, int action,
|
|
|
|
void *arg, float *var)
|
|
|
|
{
|
|
|
|
switch (action) {
|
2006-03-22 01:19:02 +01:00
|
|
|
case M_PROPERTY_PRINT:
|
2011-07-03 14:42:04 +02:00
|
|
|
if (!arg)
|
|
|
|
return 0;
|
2011-07-03 19:04:21 +02:00
|
|
|
*(char **)arg = talloc_asprintf(NULL, "%d ms", ROUND((*var) * 1000));
|
2006-03-22 01:19:02 +01:00
|
|
|
return 1;
|
|
|
|
default:
|
2011-07-03 14:42:04 +02:00
|
|
|
return m_property_float_range(prop, action, arg, var);
|
2006-03-22 01:19:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
int m_property_double_ro(const m_option_t *prop, int action,
|
|
|
|
void *arg, double var)
|
|
|
|
{
|
|
|
|
switch (action) {
|
2006-03-22 01:19:02 +01:00
|
|
|
case M_PROPERTY_GET:
|
2011-07-03 14:42:04 +02:00
|
|
|
if (!arg)
|
|
|
|
return 0;
|
|
|
|
*(double *)arg = var;
|
2006-03-22 01:19:02 +01:00
|
|
|
return 1;
|
|
|
|
case M_PROPERTY_PRINT:
|
2011-07-03 14:42:04 +02:00
|
|
|
if (!arg)
|
|
|
|
return 0;
|
2011-07-03 19:04:21 +02:00
|
|
|
*(char **)arg = talloc_asprintf(NULL, "%.2f", var);
|
2006-03-22 01:19:02 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
int m_property_time_ro(const m_option_t *prop, int action,
|
|
|
|
void *arg, double var)
|
|
|
|
{
|
|
|
|
switch (action) {
|
2007-05-31 14:42:02 +02:00
|
|
|
case M_PROPERTY_PRINT:
|
2011-07-03 14:42:04 +02:00
|
|
|
if (!arg)
|
|
|
|
return M_PROPERTY_ERROR;
|
|
|
|
else {
|
|
|
|
int h, m, s = var;
|
|
|
|
h = s / 3600;
|
|
|
|
s -= h * 3600;
|
|
|
|
m = s / 60;
|
|
|
|
s -= m * 60;
|
|
|
|
if (h > 0)
|
2011-07-03 19:04:21 +02:00
|
|
|
*(char **)arg = talloc_asprintf(NULL, "%d:%02d:%02d", h, m, s);
|
2011-07-03 14:42:04 +02:00
|
|
|
else if (m > 0)
|
2011-07-03 19:04:21 +02:00
|
|
|
*(char **)arg = talloc_asprintf(NULL, "%d:%02d", m, s);
|
2011-07-03 14:42:04 +02:00
|
|
|
else
|
2011-07-03 19:04:21 +02:00
|
|
|
*(char **)arg = talloc_asprintf(NULL, "%d", s);
|
2011-07-03 14:42:04 +02:00
|
|
|
return M_PROPERTY_OK;
|
2007-05-31 14:42:02 +02:00
|
|
|
}
|
|
|
|
}
|
2011-07-03 14:42:04 +02:00
|
|
|
return m_property_double_ro(prop, action, arg, var);
|
2007-05-31 14:42:02 +02:00
|
|
|
}
|
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
int m_property_string_ro(const m_option_t *prop, int action, void *arg,
|
|
|
|
char *str)
|
|
|
|
{
|
|
|
|
switch (action) {
|
2006-03-22 01:19:02 +01:00
|
|
|
case M_PROPERTY_GET:
|
2011-07-03 14:42:04 +02:00
|
|
|
if (!arg)
|
|
|
|
return 0;
|
|
|
|
*(char **)arg = str;
|
2006-03-22 01:19:02 +01:00
|
|
|
return 1;
|
|
|
|
case M_PROPERTY_PRINT:
|
2011-07-03 14:42:04 +02:00
|
|
|
if (!arg)
|
|
|
|
return 0;
|
2011-07-03 19:04:21 +02:00
|
|
|
*(char **)arg = talloc_strdup(NULL, str);
|
2006-03-22 01:19:02 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
|
|
|
}
|
2007-05-30 00:14:41 +02:00
|
|
|
|
2011-07-03 14:42:04 +02:00
|
|
|
int m_property_bitrate(const m_option_t *prop, int action, void *arg, int rate)
|
|
|
|
{
|
|
|
|
switch (action) {
|
2007-05-30 00:14:41 +02:00
|
|
|
case M_PROPERTY_PRINT:
|
|
|
|
if (!arg)
|
2011-07-03 14:42:04 +02:00
|
|
|
return M_PROPERTY_ERROR;
|
2011-07-03 19:04:21 +02:00
|
|
|
*(char **)arg = talloc_asprintf(NULL, "%d kbps", rate * 8 / 1000);
|
2007-05-30 00:14:41 +02:00
|
|
|
return M_PROPERTY_OK;
|
|
|
|
}
|
|
|
|
return m_property_int_ro(prop, action, arg, rate);
|
|
|
|
}
|