|
1 |
/*
|
|
2 |
* Copyright (C) 2012 Nicolas Bouillot (http://www.nicolasbouillot.net)
|
|
3 |
*
|
|
4 |
* This file is part of switcher.
|
|
5 |
*
|
|
6 |
* switcher is free software: you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation, either version 3 of the License, or
|
|
9 |
* (at your option) any later version.
|
|
10 |
*
|
|
11 |
* switcher is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with switcher. If not, see <http://www.gnu.org/licenses/>.
|
|
18 |
*/
|
|
19 |
|
|
20 |
/**
|
|
21 |
* The Param class
|
|
22 |
*/
|
|
23 |
|
|
24 |
#include "switcher/property.h"
|
|
25 |
namespace switcher
|
|
26 |
{
|
|
27 |
|
|
28 |
|
|
29 |
//should not be used because it is writing a name property
|
|
30 |
Property::Property (GObject *object, GParamSpec *pspec) :
|
|
31 |
property_ (pspec),
|
|
32 |
object_ (object)
|
|
33 |
{
|
|
34 |
}
|
|
35 |
|
|
36 |
|
|
37 |
//from gst-inspect
|
|
38 |
void
|
|
39 |
Property::print()
|
|
40 |
{
|
|
41 |
|
|
42 |
guint i;
|
|
43 |
gboolean readable;
|
|
44 |
gboolean first_flag;
|
|
45 |
|
|
46 |
|
|
47 |
GValue value = { 0, };
|
|
48 |
|
|
49 |
GObject * element = (GObject *) g_param_spec_get_qdata (property_,
|
|
50 |
g_quark_from_static_string("origin_object"));
|
|
51 |
|
|
52 |
readable = FALSE;
|
|
53 |
|
|
54 |
g_value_init (&value, property_->value_type);
|
|
55 |
|
|
56 |
g_print (" %-20s: %s\n", g_param_spec_get_name (property_),
|
|
57 |
g_param_spec_get_blurb (property_));
|
|
58 |
|
|
59 |
// first_flag = TRUE;
|
|
60 |
// g_print ("%-23.23s flags: ", "");
|
|
61 |
// if (property_->flags & G_PARAM_READABLE) {
|
|
62 |
// g_object_get_property (G_OBJECT (element), property_->name, &value);
|
|
63 |
// readable = TRUE;
|
|
64 |
// g_print ("%s%s", (first_flag) ? "" : ", ", ("readable"));
|
|
65 |
// first_flag = FALSE;
|
|
66 |
// } else {
|
|
67 |
// /* if we can't read the property value, assume it's set to the default
|
|
68 |
// * (which might not be entirely true for sub-classes, but that's an
|
|
69 |
// * unlikely corner-case anyway) */
|
|
70 |
// g_param_value_set_default (property_, &value);
|
|
71 |
// }
|
|
72 |
// if (property_->flags & G_PARAM_WRITABLE) {
|
|
73 |
// g_print ("%s%s", (first_flag) ? "" : ", ", ("writable"));
|
|
74 |
// first_flag = FALSE;
|
|
75 |
// }
|
|
76 |
// if (property_->flags & GST_PARAM_CONTROLLABLE) {
|
|
77 |
// g_print (", %s", ("controllable"));
|
|
78 |
// first_flag = FALSE;
|
|
79 |
// }
|
|
80 |
// if (property_->flags & GST_PARAM_MUTABLE_PLAYING) {
|
|
81 |
// g_print (", %s", ("changeable in NULL, READY, PAUSED or PLAYING state"));
|
|
82 |
// } else if (property_->flags & GST_PARAM_MUTABLE_PAUSED) {
|
|
83 |
// g_print (", %s", ("changeable only in NULL, READY or PAUSED state"));
|
|
84 |
// } else if (property_->flags & GST_PARAM_MUTABLE_READY) {
|
|
85 |
// g_print (", %s", ("changeable only in NULL or READY state"));
|
|
86 |
// }
|
|
87 |
// if (property_->flags & ~KNOWN_PARAM_FLAGS) {
|
|
88 |
// g_print ("%s0x%0x", (first_flag) ? "" : ", ",
|
|
89 |
// property_->flags & ~KNOWN_PARAM_FLAGS);
|
|
90 |
// }
|
|
91 |
// g_print ("\n");
|
|
92 |
|
|
93 |
switch (G_VALUE_TYPE (&value)) {
|
|
94 |
case G_TYPE_STRING:
|
|
95 |
{
|
|
96 |
const char *string_val = g_value_get_string (&value);
|
|
97 |
|
|
98 |
g_print ("%-23.23s String. ", "");
|
|
99 |
|
|
100 |
if (string_val == NULL)
|
|
101 |
g_print ("Default: null");
|
|
102 |
else
|
|
103 |
g_print ("Default: \"%s\"", string_val);
|
|
104 |
break;
|
|
105 |
}
|
|
106 |
case G_TYPE_BOOLEAN:
|
|
107 |
{
|
|
108 |
gboolean bool_val = g_value_get_boolean (&value);
|
|
109 |
|
|
110 |
g_print ("%-23.23s Boolean. ", "");
|
|
111 |
|
|
112 |
g_print ("Default: %s", bool_val ? "true" : "false");
|
|
113 |
break;
|
|
114 |
}
|
|
115 |
case G_TYPE_ULONG:
|
|
116 |
{
|
|
117 |
GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (property_);
|
|
118 |
|
|
119 |
g_print ("%-23.23s Unsigned Long. ", "");
|
|
120 |
g_print ("Range: %lu - %lu Default: %lu ",
|
|
121 |
pulong->minimum, pulong->maximum, g_value_get_ulong (&value));
|
|
122 |
break;
|
|
123 |
}
|
|
124 |
case G_TYPE_LONG:
|
|
125 |
{
|
|
126 |
GParamSpecLong *plong = G_PARAM_SPEC_LONG (property_);
|
|
127 |
|
|
128 |
g_print ("%-23.23s Long. ", "");
|
|
129 |
g_print ("Range: %ld - %ld Default: %ld ",
|
|
130 |
plong->minimum, plong->maximum, g_value_get_long (&value));
|
|
131 |
break;
|
|
132 |
}
|
|
133 |
case G_TYPE_UINT:
|
|
134 |
{
|
|
135 |
GParamSpecUInt *puint = G_PARAM_SPEC_UINT (property_);
|
|
136 |
|
|
137 |
g_print ("%-23.23s Unsigned Integer. ", "");
|
|
138 |
g_print ("Range: %u - %u Default: %u ",
|
|
139 |
puint->minimum, puint->maximum, g_value_get_uint (&value));
|
|
140 |
break;
|
|
141 |
}
|
|
142 |
case G_TYPE_INT:
|
|
143 |
{
|
|
144 |
GParamSpecInt *pint = G_PARAM_SPEC_INT (property_);
|
|
145 |
|
|
146 |
g_print ("%-23.23s Integer. ", "");
|
|
147 |
g_print ("Range: %d - %d Default: %d ",
|
|
148 |
pint->minimum, pint->maximum, g_value_get_int (&value));
|
|
149 |
break;
|
|
150 |
}
|
|
151 |
case G_TYPE_UINT64:
|
|
152 |
{
|
|
153 |
GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (property_);
|
|
154 |
|
|
155 |
g_print ("%-23.23s Unsigned Integer64. ", "");
|
|
156 |
g_print ("Range: %" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT
|
|
157 |
" Default: %" G_GUINT64_FORMAT " ",
|
|
158 |
puint64->minimum, puint64->maximum, g_value_get_uint64 (&value));
|
|
159 |
break;
|
|
160 |
}
|
|
161 |
case G_TYPE_INT64:
|
|
162 |
{
|
|
163 |
GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (property_);
|
|
164 |
|
|
165 |
g_print ("%-23.23s Integer64. ", "");
|
|
166 |
g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
|
|
167 |
" Default: %" G_GINT64_FORMAT " ",
|
|
168 |
pint64->minimum, pint64->maximum, g_value_get_int64 (&value));
|
|
169 |
break;
|
|
170 |
}
|
|
171 |
case G_TYPE_FLOAT:
|
|
172 |
{
|
|
173 |
GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (property_);
|
|
174 |
|
|
175 |
g_print ("%-23.23s Float. ", "");
|
|
176 |
g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
|
|
177 |
pfloat->minimum, pfloat->maximum, g_value_get_float (&value));
|
|
178 |
break;
|
|
179 |
}
|
|
180 |
case G_TYPE_DOUBLE:
|
|
181 |
{
|
|
182 |
GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (property_);
|
|
183 |
|
|
184 |
g_print ("%-23.23s Double. ", "");
|
|
185 |
g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
|
|
186 |
pdouble->minimum, pdouble->maximum, g_value_get_double (&value));
|
|
187 |
break;
|
|
188 |
}
|
|
189 |
default:
|
|
190 |
if (property_->value_type == GST_TYPE_CAPS) {
|
|
191 |
const GstCaps *caps = gst_value_get_caps (&value);
|
|
192 |
|
|
193 |
if (!caps)
|
|
194 |
g_print ("%-23.23s Caps (NULL)", "");
|
|
195 |
else {
|
|
196 |
g_print ("%-23.23s Caps (%s)", "", gst_caps_to_string (caps));
|
|
197 |
}
|
|
198 |
} else if (G_IS_PARAM_SPEC_ENUM (property_)) {
|
|
199 |
GEnumValue *values;
|
|
200 |
guint j = 0;
|
|
201 |
gint enum_value;
|
|
202 |
const gchar *value_nick = "";
|
|
203 |
|
|
204 |
values = G_ENUM_CLASS (g_type_class_ref (property_->value_type))->values;
|
|
205 |
enum_value = g_value_get_enum (&value);
|
|
206 |
|
|
207 |
while (values[j].value_name) {
|
|
208 |
if (values[j].value == enum_value)
|
|
209 |
value_nick = values[j].value_nick;
|
|
210 |
j++;
|
|
211 |
}
|
|
212 |
|
|
213 |
g_print ("%-23.23s Enum \"%s\" Default: %d, \"%s\"", "",
|
|
214 |
g_type_name (G_VALUE_TYPE (&value)), enum_value, value_nick);
|
|
215 |
|
|
216 |
j = 0;
|
|
217 |
while (values[j].value_name) {
|
|
218 |
g_print ("\n");
|
|
219 |
// if (_name)
|
|
220 |
// g_print ("%s", _name);
|
|
221 |
g_print ("%-23.23s (%d): %-16s - %s", "",
|
|
222 |
values[j].value, values[j].value_nick, values[j].value_name);
|
|
223 |
j++;
|
|
224 |
}
|
|
225 |
/* g_type_class_unref (ec); */
|
|
226 |
} else if (G_IS_PARAM_SPEC_FLAGS (property_)) {
|
|
227 |
// GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (property_);
|
|
228 |
// GFlagsValue *vals;
|
|
229 |
// gchar *cur;
|
|
230 |
|
|
231 |
// vals = pflags->flags_class->values;
|
|
232 |
|
|
233 |
// cur = flags_to_string (vals, g_value_get_flags (&value));
|
|
234 |
|
|
235 |
// g_print ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\"", "",
|
|
236 |
// g_type_name (G_VALUE_TYPE (&value)),
|
|
237 |
// g_value_get_flags (&value), cur);
|
|
238 |
|
|
239 |
// while (vals[0].value_name) {
|
|
240 |
// g_print ("\n");
|
|
241 |
// if (_name)
|
|
242 |
// g_print ("%s", _name);
|
|
243 |
// g_print ("%-23.23s (0x%08x): %-16s - %s", "",
|
|
244 |
// vals[0].value, vals[0].value_nick, vals[0].value_name);
|
|
245 |
// ++vals;
|
|
246 |
// }
|
|
247 |
|
|
248 |
// g_free (cur);
|
|
249 |
} else if (G_IS_PARAM_SPEC_OBJECT (property_)) {
|
|
250 |
g_print ("%-23.23s Object of type \"%s\"", "",
|
|
251 |
g_type_name (property_->value_type));
|
|
252 |
} else if (G_IS_PARAM_SPEC_BOXED (property_)) {
|
|
253 |
g_print ("%-23.23s Boxed pointer of type \"%s\"", "",
|
|
254 |
g_type_name (property_->value_type));
|
|
255 |
} else if (G_IS_PARAM_SPEC_POINTER (property_)) {
|
|
256 |
if (property_->value_type != G_TYPE_POINTER) {
|
|
257 |
g_print ("%-23.23s Pointer of type \"%s\".", "",
|
|
258 |
g_type_name (property_->value_type));
|
|
259 |
} else {
|
|
260 |
g_print ("%-23.23s Pointer.", "");
|
|
261 |
}
|
|
262 |
} else if (property_->value_type == G_TYPE_VALUE_ARRAY) {
|
|
263 |
GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (property_);
|
|
264 |
|
|
265 |
if (pvarray->element_spec) {
|
|
266 |
g_print ("%-23.23s Array of GValues of type \"%s\"", "",
|
|
267 |
g_type_name (pvarray->element_spec->value_type));
|
|
268 |
} else {
|
|
269 |
g_print ("%-23.23s Array of GValues", "");
|
|
270 |
}
|
|
271 |
} else if (GST_IS_PARAM_SPEC_FRACTION (property_)) {
|
|
272 |
GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (property_);
|
|
273 |
|
|
274 |
g_print ("%-23.23s Fraction. ", "");
|
|
275 |
|
|
276 |
g_print ("Range: %d/%d - %d/%d Default: %d/%d ",
|
|
277 |
pfraction->min_num, pfraction->min_den,
|
|
278 |
pfraction->max_num, pfraction->max_den,
|
|
279 |
gst_value_get_fraction_numerator (&value),
|
|
280 |
gst_value_get_fraction_denominator (&value));
|
|
281 |
} else if (GST_IS_PARAM_SPEC_MINI_OBJECT (property_)) {
|
|
282 |
g_print ("%-23.23s MiniObject of type \"%s\"", "",
|
|
283 |
g_type_name (property_->value_type));
|
|
284 |
} else {
|
|
285 |
g_print ("%-23.23s Unknown type %ld \"%s\"", "", property_->value_type,
|
|
286 |
g_type_name (property_->value_type));
|
|
287 |
}
|
|
288 |
break;
|
|
289 |
}
|
|
290 |
if (!readable)
|
|
291 |
g_print (" Write only\n");
|
|
292 |
else
|
|
293 |
g_print ("\n");
|
|
294 |
|
|
295 |
g_value_reset (&value);
|
|
296 |
}
|
|
297 |
|
|
298 |
|
|
299 |
}
|