Mercurial > mplayer.hg
annotate m_property.c @ 36514:855d2d796453
vo_bl: cosmetics, use more readable array indexing syntax.
author | reimar |
---|---|
date | Sat, 18 Jan 2014 14:05:27 +0000 |
parents | 6d08af681d54 |
children |
rev | line source |
---|---|
30429
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
1 /* |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
2 * This file is part of MPlayer. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
3 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
7 * (at your option) any later version. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
8 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
12 * GNU General Public License for more details. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
13 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
29263
diff
changeset
|
17 */ |
18258 | 18 |
19 /// \file | |
20 /// \ingroup Properties | |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
21 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
22 #include "config.h" |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
23 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
24 #include <stdlib.h> |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
25 #include <stdio.h> |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
26 #include <string.h> |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
27 #include <inttypes.h> |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
28 #include <unistd.h> |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
29 |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
30 #include "m_option.h" |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
31 #include "m_property.h" |
17914
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
32 #include "mp_msg.h" |
32664 | 33 #include "mpcommon.h" |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
34 #include "help_mp.h" |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
35 |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
36 static int do_action(const m_option_t* prop_list, const char* name, |
23393
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
37 int action, void* arg, void *ctx) { |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
38 const char* sep; |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
39 const m_option_t* prop; |
23393
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
40 m_property_action_t ka; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
41 int r; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
42 if((sep = strchr(name,'/')) && sep[1]) { |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
43 int len = sep-name; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
44 char base[len+1]; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
45 memcpy(base,name,len); |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
46 base[len] = 0; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
47 prop = m_option_list_find(prop_list, base); |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
48 ka.key = sep+1; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
49 ka.action = action; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
50 ka.arg = arg; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
51 action = M_PROPERTY_KEY_ACTION; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
52 arg = &ka; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
53 } else |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
54 prop = m_option_list_find(prop_list, name); |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
55 if(!prop) return M_PROPERTY_UNKNOWN; |
23393
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
56 r = ((m_property_ctrl_f)prop->p)(prop,action,arg,ctx); |
23395
0ff039835f0f
Fix fallback on the default GET_TYPE for unvailable/disabled
albeu
parents:
23394
diff
changeset
|
57 if(action == M_PROPERTY_GET_TYPE && r < 0) { |
23393
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
58 if(!arg) return M_PROPERTY_ERROR; |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
59 *(const m_option_t**)arg = prop; |
23393
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
60 return M_PROPERTY_OK; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
61 } |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
62 return r; |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
63 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
64 |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
65 int m_property_do(const m_option_t* prop_list, const char* name, |
23393
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
66 int action, void* arg, void *ctx) { |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
67 const m_option_t* opt; |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
68 void* val; |
23393
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
69 char* str; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
70 int r; |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
71 |
23393
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
72 switch(action) { |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
73 case M_PROPERTY_PRINT: |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
74 if((r = do_action(prop_list,name,M_PROPERTY_PRINT,arg,ctx)) >= 0) |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
75 return r; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
76 // fallback on the default print for this type |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
77 case M_PROPERTY_TO_STRING: |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
78 if((r = do_action(prop_list,name,M_PROPERTY_TO_STRING,arg,ctx)) != |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
79 M_PROPERTY_NOT_IMPLEMENTED) |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
80 return r; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
81 // fallback on the options API. Get the type, value and print. |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
82 if((r = do_action(prop_list,name,M_PROPERTY_GET_TYPE,&opt,ctx)) <= 0) |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
83 return r; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
84 val = calloc(1,opt->type->size); |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
85 if((r = do_action(prop_list,name,M_PROPERTY_GET,val,ctx)) <= 0) { |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
86 free(val); |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
87 return r; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
88 } |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
89 if(!arg) return M_PROPERTY_ERROR; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
90 str = m_option_print(opt,val); |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
91 free(val); |
23393
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
92 *(char**)arg = str == (char*)-1 ? NULL : str; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
93 return str != (char*)-1; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
94 case M_PROPERTY_PARSE: |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
95 // try the property own parsing func |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
96 if((r = do_action(prop_list,name,M_PROPERTY_PARSE,arg,ctx)) != |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
97 M_PROPERTY_NOT_IMPLEMENTED) |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
98 return r; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
99 // fallback on the options API, get the type and parse. |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
100 if((r = do_action(prop_list,name,M_PROPERTY_GET_TYPE,&opt,ctx)) <= 0) |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
101 return r; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
102 if(!arg) return M_PROPERTY_ERROR; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
103 val = calloc(1,opt->type->size); |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
104 if((r = m_option_parse(opt,opt->name,arg,val,M_CONFIG_FILE)) <= 0) { |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
105 free(val); |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
106 return r; |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
107 } |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
108 r = do_action(prop_list,name,M_PROPERTY_SET,val,ctx); |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
109 m_option_free(opt,val); |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
110 free(val); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
111 return r; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
112 } |
23393
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
113 return do_action(prop_list,name,action,arg,ctx); |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
114 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
115 |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
116 char* m_properties_expand_string(const m_option_t* prop_list,char* str, void *ctx) { |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
117 int l,fr=0,pos=0,size=strlen(str)+512; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
118 char *p = NULL,*e,*ret = malloc(size), num_val; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
119 int skip = 0, lvl = 0, skip_lvl = 0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27647
diff
changeset
|
120 |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
121 while(str[0]) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
122 if(str[0] == '\\') { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
123 int sl = 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
124 switch(str[1]) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
125 case 'e': |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
126 p = "\x1b", l = 1; break; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
127 case 'n': |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
128 p = "\n", l = 1; break; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
129 case 'r': |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
130 p = "\r", l = 1; break; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
131 case 't': |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
132 p = "\t", l = 1; break; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27647
diff
changeset
|
133 case 'x': |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
134 if(str[2]) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
135 char num[3] = { str[2], str[3], 0 }; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
136 char* end = num; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
137 num_val = strtol(num,&end,16); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
138 sl = end-num; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
139 l = 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
140 p = &num_val; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
141 } else |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
142 l = 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
143 break; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
144 default: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
145 p = str+1, l = 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
146 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
147 str+=1+sl; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
148 } else if(lvl > 0 && str[0] == ')') { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
149 if(skip && lvl <= skip_lvl) skip = 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
150 lvl--, str++, l = 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
151 } else if(str[0] == '$' && str[1] == '{' && (e = strchr(str+2,'}'))) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
152 int pl = e-str-2; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
153 char pname[pl+1]; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
154 memcpy(pname,str+2,pl); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
155 pname[pl] = 0; |
23393
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
156 if(m_property_do(prop_list, pname, |
a5e55cb59bbc
Rework the property API to allow sub properties such as
albeu
parents:
22280
diff
changeset
|
157 M_PROPERTY_PRINT, &p, ctx) >= 0 && p) |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
158 l = strlen(p), fr = 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
159 else |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
160 l = 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
161 str = e+1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
162 } else if(str[0] == '?' && str[1] == '(' && (e = strchr(str+2,':'))) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
163 lvl++; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27647
diff
changeset
|
164 if(!skip) { |
25501
26a839637972
Support ?(!NAME:TEXT) format for expanding string by property.
ulion
parents:
25460
diff
changeset
|
165 int is_not = str[2] == '!'; |
26a839637972
Support ?(!NAME:TEXT) format for expanding string by property.
ulion
parents:
25460
diff
changeset
|
166 int pl = e - str - (is_not ? 3 : 2); |
25460
3086b6d39052
Move two variable to the scope where they are indeed used.
ulion
parents:
23416
diff
changeset
|
167 char pname[pl+1]; |
25501
26a839637972
Support ?(!NAME:TEXT) format for expanding string by property.
ulion
parents:
25460
diff
changeset
|
168 memcpy(pname, str + (is_not ? 3 : 2), pl); |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
169 pname[pl] = 0; |
25501
26a839637972
Support ?(!NAME:TEXT) format for expanding string by property.
ulion
parents:
25460
diff
changeset
|
170 if(m_property_do(prop_list,pname,M_PROPERTY_GET,NULL,ctx) < 0) { |
26a839637972
Support ?(!NAME:TEXT) format for expanding string by property.
ulion
parents:
25460
diff
changeset
|
171 if (!is_not) |
26a839637972
Support ?(!NAME:TEXT) format for expanding string by property.
ulion
parents:
25460
diff
changeset
|
172 skip = 1, skip_lvl = lvl; |
26a839637972
Support ?(!NAME:TEXT) format for expanding string by property.
ulion
parents:
25460
diff
changeset
|
173 } |
26a839637972
Support ?(!NAME:TEXT) format for expanding string by property.
ulion
parents:
25460
diff
changeset
|
174 else if (is_not) |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
175 skip = 1, skip_lvl = lvl; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
176 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
177 str = e+1, l = 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
178 } else |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
179 p = str, l = 1, str++; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27647
diff
changeset
|
180 |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
181 if(skip || l <= 0) continue; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27647
diff
changeset
|
182 |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
183 if(pos+l+1 > size) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
184 size = pos+l+512; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
185 ret = realloc(ret,size); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
186 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
187 memcpy(ret+pos,p,l); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
188 pos += l; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
189 if(fr) free(p), fr = 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
190 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27647
diff
changeset
|
191 |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
192 ret[pos] = 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
193 return ret; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
194 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
195 |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
196 void m_properties_print_help_list(const m_option_t* list) { |
17914
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
197 char min[50],max[50]; |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
198 int i,count = 0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27647
diff
changeset
|
199 |
17914
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
200 mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_PropertyListHeader); |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
201 for(i = 0 ; list[i].name ; i++) { |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
202 const m_option_t* opt = &list[i]; |
17914
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
203 if(opt->flags & M_OPT_MIN) |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
204 sprintf(min,"%-8.0f",opt->min); |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
205 else |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
206 strcpy(min,"No"); |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
207 if(opt->flags & M_OPT_MAX) |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
208 sprintf(max,"%-8.0f",opt->max); |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
209 else |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
210 strcpy(max,"No"); |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
211 mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %-20.20s %-15.15s %-10.10s %-10.10s\n", |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
212 opt->name, |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
213 opt->type->name, |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
214 min, |
17927 | 215 max); |
17914
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
216 count++; |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
217 } |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
218 mp_msg(MSGT_CFGPARSER, MSGL_INFO, MSGTR_TotalProperties, count); |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
219 } |
f9cb6fc1608a
Add an option to list the properties: -list-properties
albeu
parents:
17911
diff
changeset
|
220 |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
221 // Some generic property implementations |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
222 |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
223 int m_property_int_ro(const m_option_t* prop,int action, |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
224 void* arg,int var) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
225 switch(action) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
226 case M_PROPERTY_GET: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
227 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
228 *(int*)arg = var; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
229 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
230 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
231 return M_PROPERTY_NOT_IMPLEMENTED; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
232 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
233 |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
234 int m_property_int_range(const m_option_t* prop,int action, |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
235 void* arg,int* var) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
236 switch(action) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
237 case M_PROPERTY_SET: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
238 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
239 M_PROPERTY_CLAMP(prop,*(int*)arg); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
240 *var = *(int*)arg; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
241 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
242 case M_PROPERTY_STEP_UP: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
243 case M_PROPERTY_STEP_DOWN: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
244 *var += (arg ? *(int*)arg : 1) * |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
245 (action == M_PROPERTY_STEP_DOWN ? -1 : 1); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
246 M_PROPERTY_CLAMP(prop,*var); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
247 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
248 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
249 return m_property_int_ro(prop,action,arg,*var); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
250 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
251 |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
252 int m_property_choice(const m_option_t* prop,int action, |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
253 void* arg,int* var) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
254 switch(action) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
255 case M_PROPERTY_STEP_UP: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
256 case M_PROPERTY_STEP_DOWN: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
257 *var += action == M_PROPERTY_STEP_UP ? 1 : prop->max; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
258 *var %= (int)prop->max+1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
259 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
260 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
261 return m_property_int_range(prop,action,arg,var); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
262 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
263 |
27647
98478619a22c
Add a m_property_flag_ro function for the default behaviour of a
reimar
parents:
25716
diff
changeset
|
264 int m_property_flag_ro(const m_option_t* prop,int action, |
98478619a22c
Add a m_property_flag_ro function for the default behaviour of a
reimar
parents:
25716
diff
changeset
|
265 void* arg,int var) { |
98478619a22c
Add a m_property_flag_ro function for the default behaviour of a
reimar
parents:
25716
diff
changeset
|
266 switch(action) { |
98478619a22c
Add a m_property_flag_ro function for the default behaviour of a
reimar
parents:
25716
diff
changeset
|
267 case M_PROPERTY_PRINT: |
98478619a22c
Add a m_property_flag_ro function for the default behaviour of a
reimar
parents:
25716
diff
changeset
|
268 if(!arg) return 0; |
98478619a22c
Add a m_property_flag_ro function for the default behaviour of a
reimar
parents:
25716
diff
changeset
|
269 *(char**)arg = strdup((var > prop->min) ? MSGTR_Enabled : MSGTR_Disabled); |
98478619a22c
Add a m_property_flag_ro function for the default behaviour of a
reimar
parents:
25716
diff
changeset
|
270 return 1; |
98478619a22c
Add a m_property_flag_ro function for the default behaviour of a
reimar
parents:
25716
diff
changeset
|
271 } |
98478619a22c
Add a m_property_flag_ro function for the default behaviour of a
reimar
parents:
25716
diff
changeset
|
272 return m_property_int_ro(prop,action,arg,var); |
98478619a22c
Add a m_property_flag_ro function for the default behaviour of a
reimar
parents:
25716
diff
changeset
|
273 } |
98478619a22c
Add a m_property_flag_ro function for the default behaviour of a
reimar
parents:
25716
diff
changeset
|
274 |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
275 int m_property_flag(const m_option_t* prop,int action, |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
276 void* arg,int* var) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
277 switch(action) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
278 case M_PROPERTY_STEP_UP: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
279 case M_PROPERTY_STEP_DOWN: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
280 *var = *var == prop->min ? prop->max : prop->min; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
281 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
282 case M_PROPERTY_PRINT: |
27647
98478619a22c
Add a m_property_flag_ro function for the default behaviour of a
reimar
parents:
25716
diff
changeset
|
283 return m_property_flag_ro(prop, action, arg, *var); |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
284 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
285 return m_property_int_range(prop,action,arg,var); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
286 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
287 |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
288 int m_property_float_ro(const m_option_t* prop,int action, |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
289 void* arg,float var) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
290 switch(action) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
291 case M_PROPERTY_GET: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
292 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
293 *(float*)arg = var; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
294 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
295 case M_PROPERTY_PRINT: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
296 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
297 *(char**)arg = malloc(20); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
298 sprintf(*(char**)arg,"%.2f",var); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
299 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
300 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
301 return M_PROPERTY_NOT_IMPLEMENTED; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
302 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
303 |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
304 int m_property_float_range(const m_option_t* prop,int action, |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
305 void* arg,float* var) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
306 switch(action) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
307 case M_PROPERTY_SET: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
308 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
309 M_PROPERTY_CLAMP(prop,*(float*)arg); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
310 *var = *(float*)arg; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
311 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
312 case M_PROPERTY_STEP_UP: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
313 case M_PROPERTY_STEP_DOWN: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
314 *var += (arg ? *(float*)arg : 0.1) * |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
315 (action == M_PROPERTY_STEP_DOWN ? -1 : 1); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
316 M_PROPERTY_CLAMP(prop,*var); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
317 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
318 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
319 return m_property_float_ro(prop,action,arg,*var); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
320 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
321 |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
322 int m_property_delay(const m_option_t* prop,int action, |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
323 void* arg,float* var) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
324 switch(action) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
325 case M_PROPERTY_PRINT: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
326 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
327 *(char**)arg = malloc(20); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
328 sprintf(*(char**)arg,"%d ms",ROUND((*var)*1000)); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
329 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
330 default: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
331 return m_property_float_range(prop,action,arg,var); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
332 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
333 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
334 |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
335 int m_property_double_ro(const m_option_t* prop,int action, |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
336 void* arg,double var) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
337 switch(action) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
338 case M_PROPERTY_GET: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
339 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
340 *(double*)arg = var; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
341 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
342 case M_PROPERTY_PRINT: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
343 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
344 *(char**)arg = malloc(20); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
345 sprintf(*(char**)arg,"%.2f",var); |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
346 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
347 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
348 return M_PROPERTY_NOT_IMPLEMENTED; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
349 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
350 |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
351 int m_property_time_ro(const m_option_t* prop,int action, |
23416
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
352 void* arg,double var) { |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
353 switch(action) { |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
354 case M_PROPERTY_PRINT: |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
355 if (!arg) |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
356 return M_PROPERTY_ERROR; |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
357 else { |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
358 int h, m, s = var; |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
359 h = s / 3600; |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
360 s -= h * 3600; |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
361 m = s / 60; |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
362 s -= m * 60; |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
363 *(char **) arg = malloc(20); |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
364 if (h > 0) |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
365 sprintf(*(char **) arg, "%d:%02d:%02d", h, m, s); |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
366 else if (m > 0) |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
367 sprintf(*(char **) arg, "%d:%02d", m, s); |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
368 else |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
369 sprintf(*(char **) arg, "%d", s); |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
370 return M_PROPERTY_OK; |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
371 } |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
372 } |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
373 return m_property_double_ro(prop,action,arg,var); |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
374 } |
ae4237717601
Move the time printing code out of the length property.
albeu
parents:
23395
diff
changeset
|
375 |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
376 int m_property_string_ro(const m_option_t* prop,int action,void* arg,char* str) { |
17911
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
377 switch(action) { |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
378 case M_PROPERTY_GET: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
379 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
380 *(char**)arg = str; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
381 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
382 case M_PROPERTY_PRINT: |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
383 if(!arg) return 0; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
384 *(char**)arg = str ? strdup(str) : NULL; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
385 return 1; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
386 } |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
387 return M_PROPERTY_NOT_IMPLEMENTED; |
52f95509cd05
Add the new property API and implement a couple properties.
albeu
parents:
diff
changeset
|
388 } |
23394
d4e8613ddc95
Make all the info available via the metadata API available via properties.
albeu
parents:
23393
diff
changeset
|
389 |
25716
fc8d4bd1689a
All the m_property stuff works fine with constant m_option_t
reimar
parents:
25501
diff
changeset
|
390 int m_property_bitrate(const m_option_t* prop,int action,void* arg,int rate) { |
23394
d4e8613ddc95
Make all the info available via the metadata API available via properties.
albeu
parents:
23393
diff
changeset
|
391 switch(action) { |
d4e8613ddc95
Make all the info available via the metadata API available via properties.
albeu
parents:
23393
diff
changeset
|
392 case M_PROPERTY_PRINT: |
d4e8613ddc95
Make all the info available via the metadata API available via properties.
albeu
parents:
23393
diff
changeset
|
393 if (!arg) |
d4e8613ddc95
Make all the info available via the metadata API available via properties.
albeu
parents:
23393
diff
changeset
|
394 return M_PROPERTY_ERROR; |
d4e8613ddc95
Make all the info available via the metadata API available via properties.
albeu
parents:
23393
diff
changeset
|
395 *(char**)arg = malloc (16); |
d4e8613ddc95
Make all the info available via the metadata API available via properties.
albeu
parents:
23393
diff
changeset
|
396 sprintf(*(char**)arg, "%d kbps", rate*8/1000); |
d4e8613ddc95
Make all the info available via the metadata API available via properties.
albeu
parents:
23393
diff
changeset
|
397 return M_PROPERTY_OK; |
d4e8613ddc95
Make all the info available via the metadata API available via properties.
albeu
parents:
23393
diff
changeset
|
398 } |
d4e8613ddc95
Make all the info available via the metadata API available via properties.
albeu
parents:
23393
diff
changeset
|
399 return m_property_int_ro(prop, action, arg, rate); |
d4e8613ddc95
Make all the info available via the metadata API available via properties.
albeu
parents:
23393
diff
changeset
|
400 } |