]> code.delx.au - pulseaudio/blob - src/pulsecore/cli-text.c
some beautification updates, show msec instead of usec everywhere
[pulseaudio] / src / pulsecore / cli-text.c
1 /* $Id$ */
2
3 /***
4 This file is part of PulseAudio.
5
6 Copyright 2004-2006 Lennart Poettering
7
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
12
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 USA.
22 ***/
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <string.h>
29
30 #include <pulse/volume.h>
31 #include <pulse/xmalloc.h>
32 #include <pulse/timeval.h>
33
34 #include <pulsecore/module.h>
35 #include <pulsecore/client.h>
36 #include <pulsecore/sink.h>
37 #include <pulsecore/source.h>
38 #include <pulsecore/sink-input.h>
39 #include <pulsecore/source-output.h>
40 #include <pulsecore/strbuf.h>
41 #include <pulsecore/sample-util.h>
42 #include <pulsecore/core-scache.h>
43 #include <pulsecore/autoload.h>
44 #include <pulsecore/macro.h>
45 #include <pulsecore/core-util.h>
46
47 #include "cli-text.h"
48
49 char *pa_module_list_to_string(pa_core *c) {
50 pa_strbuf *s;
51 pa_module *m;
52 uint32_t idx = PA_IDXSET_INVALID;
53 pa_assert(c);
54
55 s = pa_strbuf_new();
56
57 pa_strbuf_printf(s, "%u module(s) loaded.\n", pa_idxset_size(c->modules));
58
59 for (m = pa_idxset_first(c->modules, &idx); m; m = pa_idxset_next(c->modules, &idx)) {
60 pa_strbuf_printf(s, " index: %u\n"
61 "\tname: <%s>\n"
62 "\targument: <%s>\n"
63 "\tused: %i\n"
64 "\tauto unload: %s\n",
65 m->index, m->name, m->argument ? m->argument : "", m->n_used,
66 pa_yes_no(m->auto_unload));
67 }
68
69 return pa_strbuf_tostring_free(s);
70 }
71
72 char *pa_client_list_to_string(pa_core *c) {
73 pa_strbuf *s;
74 pa_client *client;
75 uint32_t idx = PA_IDXSET_INVALID;
76 pa_assert(c);
77
78 s = pa_strbuf_new();
79
80 pa_strbuf_printf(s, "%u client(s) logged in.\n", pa_idxset_size(c->clients));
81
82 for (client = pa_idxset_first(c->clients, &idx); client; client = pa_idxset_next(c->clients, &idx)) {
83 char *t;
84 pa_strbuf_printf(
85 s,
86 " index: %u\n"
87 "\tdriver: <%s>\n",
88 client->index,
89 client->driver);
90
91 if (client->module)
92 pa_strbuf_printf(s, "\towner module: %u\n", client->module->index);
93
94 t = pa_proplist_to_string(client->proplist);
95 pa_strbuf_printf(s, "\tproperties:\n%s", t);
96 pa_xfree(t);
97 }
98
99 return pa_strbuf_tostring_free(s);
100 }
101
102 char *pa_sink_list_to_string(pa_core *c) {
103 pa_strbuf *s;
104 pa_sink *sink;
105 uint32_t idx = PA_IDXSET_INVALID;
106 static const char* const state_table[] = {
107 [PA_SINK_INIT] = "INIT",
108 [PA_SINK_RUNNING] = "RUNNING",
109 [PA_SINK_SUSPENDED] = "SUSPENDED",
110 [PA_SINK_IDLE] = "IDLE",
111 [PA_SINK_UNLINKED] = "UNLINKED"
112 };
113 pa_assert(c);
114
115 s = pa_strbuf_new();
116
117 pa_strbuf_printf(s, "%u sink(s) available.\n", pa_idxset_size(c->sinks));
118
119 for (sink = pa_idxset_first(c->sinks, &idx); sink; sink = pa_idxset_next(c->sinks, &idx)) {
120 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t;
121
122 pa_strbuf_printf(
123 s,
124 " %c index: %u\n"
125 "\tname: <%s>\n"
126 "\tdriver: <%s>\n"
127 "\tflags: %s%s%s%s%s%s\n"
128 "\tstate: %s\n"
129 "\tvolume: %s\n"
130 "\tmuted: %s\n"
131 "\tcurrent latency: %0.2f ms\n"
132 "\tconfigured latency: %0.2f ms; range is %0.2f .. %0.2f ms\n"
133 "\tmonitor source: %u\n"
134 "\tsample spec: %s\n"
135 "\tchannel map: %s\n"
136 "\tused by: %u\n"
137 "\tlinked by: %u\n",
138 c->default_sink_name && !strcmp(sink->name, c->default_sink_name) ? '*' : ' ',
139 sink->index,
140 sink->name,
141 sink->driver,
142 sink->flags & PA_SINK_HARDWARE ? "HARDWARE " : "",
143 sink->flags & PA_SINK_NETWORK ? "NETWORK " : "",
144 sink->flags & PA_SINK_HW_MUTE_CTRL ? "HW_MUTE_CTRL " : "",
145 sink->flags & PA_SINK_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
146 sink->flags & PA_SINK_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
147 sink->flags & PA_SINK_LATENCY ? "LATENCY " : "",
148 state_table[pa_sink_get_state(sink)],
149 pa_cvolume_snprint(cv, sizeof(cv), pa_sink_get_volume(sink)),
150 pa_yes_no(pa_sink_get_mute(sink)),
151 (double) pa_sink_get_latency(sink) / PA_USEC_PER_MSEC,
152 (double) pa_sink_get_requested_latency(sink) / PA_USEC_PER_MSEC, (double) sink->min_latency / PA_USEC_PER_MSEC, (double) sink->max_latency / PA_USEC_PER_MSEC,
153 sink->monitor_source ? sink->monitor_source->index : PA_INVALID_INDEX,
154 pa_sample_spec_snprint(ss, sizeof(ss), &sink->sample_spec),
155 pa_channel_map_snprint(cm, sizeof(cm), &sink->channel_map),
156 pa_sink_used_by(sink),
157 pa_sink_linked_by(sink));
158
159 if (sink->module)
160 pa_strbuf_printf(s, "\tmodule: %u\n", sink->module->index);
161
162 t = pa_proplist_to_string(sink->proplist);
163 pa_strbuf_printf(s, "\tproperties:\n%s", t);
164 pa_xfree(t);
165 }
166
167 return pa_strbuf_tostring_free(s);
168 }
169
170 char *pa_source_list_to_string(pa_core *c) {
171 pa_strbuf *s;
172 pa_source *source;
173 uint32_t idx = PA_IDXSET_INVALID;
174 static const char* const state_table[] = {
175 [PA_SOURCE_INIT] = "INIT",
176 [PA_SOURCE_RUNNING] = "RUNNING",
177 [PA_SOURCE_SUSPENDED] = "SUSPENDED",
178 [PA_SOURCE_IDLE] = "IDLE",
179 [PA_SOURCE_UNLINKED] = "UNLINKED"
180 };
181 pa_assert(c);
182
183 s = pa_strbuf_new();
184
185 pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_size(c->sources));
186
187 for (source = pa_idxset_first(c->sources, &idx); source; source = pa_idxset_next(c->sources, &idx)) {
188 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], *t;
189
190 pa_strbuf_printf(
191 s,
192 " %c index: %u\n"
193 "\tname: <%s>\n"
194 "\tdriver: <%s>\n"
195 "\tflags: %s%s%s%s%s%s\n"
196 "\tstate: %s\n"
197 "\tvolume: %s\n"
198 "\tmuted: %s\n"
199 "\tcurrent latency: %0.2f ms\n"
200 "\tconfigured latency: %0.2f ms; range is %0.2f .. %0.2f ms\n"
201 "\tsample spec: %s\n"
202 "\tchannel map: %s\n"
203 "\tused by: %u\n"
204 "\tlinked by: %u\n",
205 c->default_source_name && !strcmp(source->name, c->default_source_name) ? '*' : ' ',
206 source->index,
207 source->name,
208 source->driver,
209 source->flags & PA_SOURCE_HARDWARE ? "HARDWARE " : "",
210 source->flags & PA_SOURCE_NETWORK ? "NETWORK " : "",
211 source->flags & PA_SOURCE_HW_MUTE_CTRL ? "HW_MUTE_CTRL " : "",
212 source->flags & PA_SOURCE_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
213 source->flags & PA_SOURCE_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
214 source->flags & PA_SOURCE_LATENCY ? "LATENCY " : "",
215 state_table[pa_source_get_state(source)],
216 pa_cvolume_snprint(cv, sizeof(cv), pa_source_get_volume(source)),
217 pa_yes_no(pa_source_get_mute(source)),
218 (double) pa_source_get_latency(source) / PA_USEC_PER_MSEC,
219 (double) pa_source_get_requested_latency(source) / PA_USEC_PER_MSEC, (double) source->min_latency / PA_USEC_PER_MSEC, (double) source->max_latency / PA_USEC_PER_MSEC,
220 pa_sample_spec_snprint(ss, sizeof(ss), &source->sample_spec),
221 pa_channel_map_snprint(cm, sizeof(cm), &source->channel_map),
222 pa_source_used_by(source),
223 pa_source_linked_by(source));
224
225 if (source->monitor_of)
226 pa_strbuf_printf(s, "\tmonitor_of: %u\n", source->monitor_of->index);
227 if (source->module)
228 pa_strbuf_printf(s, "\tmodule: %u\n", source->module->index);
229
230 t = pa_proplist_to_string(source->proplist);
231 pa_strbuf_printf(s, "\tproperties:\n%s", t);
232 pa_xfree(t);
233 }
234
235 return pa_strbuf_tostring_free(s);
236 }
237
238
239 char *pa_source_output_list_to_string(pa_core *c) {
240 pa_strbuf *s;
241 pa_source_output *o;
242 uint32_t idx = PA_IDXSET_INVALID;
243 static const char* const state_table[] = {
244 [PA_SOURCE_OUTPUT_INIT] = "INIT",
245 [PA_SOURCE_OUTPUT_RUNNING] = "RUNNING",
246 [PA_SOURCE_OUTPUT_CORKED] = "CORKED",
247 [PA_SOURCE_OUTPUT_UNLINKED] = "UNLINKED"
248 };
249 pa_assert(c);
250
251 s = pa_strbuf_new();
252
253 pa_strbuf_printf(s, "%u source outputs(s) available.\n", pa_idxset_size(c->source_outputs));
254
255 for (o = pa_idxset_first(c->source_outputs, &idx); o; o = pa_idxset_next(c->source_outputs, &idx)) {
256 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t;
257
258 pa_assert(o->source);
259
260 pa_strbuf_printf(
261 s,
262 " index: %u\n"
263 "\tdriver: <%s>\n"
264 "\tflags: %s%s%s%s%s%s%s%s\n"
265 "\tstate: %s\n"
266 "\tsource: %u <%s>\n"
267 "\tlatency: %0.2f ms\n"
268 "\tsample spec: %s\n"
269 "\tchannel map: %s\n"
270 "\tresample method: %s\n",
271 o->index,
272 o->driver,
273 o->flags & PA_SOURCE_OUTPUT_VARIABLE_RATE ? "VARIABLE_RATE " : "",
274 o->flags & PA_SOURCE_OUTPUT_DONT_MOVE ? "DONT_MOVE " : "",
275 o->flags & PA_SOURCE_OUTPUT_START_CORKED ? "START_CORKED " : "",
276 o->flags & PA_SOURCE_OUTPUT_NO_REMAP ? "NO_REMAP " : "",
277 o->flags & PA_SOURCE_OUTPUT_NO_REMIX ? "NO_REMIX " : "",
278 o->flags & PA_SOURCE_OUTPUT_FIX_FORMAT ? "FIX_FORMAT " : "",
279 o->flags & PA_SOURCE_OUTPUT_FIX_RATE ? "FIX_RATE " : "",
280 o->flags & PA_SOURCE_OUTPUT_FIX_CHANNELS ? "FIX_CHANNELS " : "",
281 state_table[pa_source_output_get_state(o)],
282 o->source->index, o->source->name,
283 (double) pa_source_output_get_latency(o) / PA_USEC_PER_MSEC,
284 pa_sample_spec_snprint(ss, sizeof(ss), &o->sample_spec),
285 pa_channel_map_snprint(cm, sizeof(cm), &o->channel_map),
286 pa_resample_method_to_string(pa_source_output_get_resample_method(o)));
287 if (o->module)
288 pa_strbuf_printf(s, "\towner module: %u\n", o->module->index);
289 if (o->client)
290 pa_strbuf_printf(s, "\tclient: %u <%s>\n", o->client->index, pa_strnull(pa_proplist_gets(o->client->proplist, PA_PROP_APPLICATION_NAME)));
291
292 t = pa_proplist_to_string(o->proplist);
293 pa_strbuf_printf(s, "\tproperties:\n%s", t);
294 pa_xfree(t);
295 }
296
297 return pa_strbuf_tostring_free(s);
298 }
299
300 char *pa_sink_input_list_to_string(pa_core *c) {
301 pa_strbuf *s;
302 pa_sink_input *i;
303 uint32_t idx = PA_IDXSET_INVALID;
304 static const char* const state_table[] = {
305 [PA_SINK_INPUT_INIT] = "INIT",
306 [PA_SINK_INPUT_RUNNING] = "RUNNING",
307 [PA_SINK_INPUT_DRAINED] = "DRAINED",
308 [PA_SINK_INPUT_CORKED] = "CORKED",
309 [PA_SINK_INPUT_UNLINKED] = "UNLINKED"
310 };
311
312 pa_assert(c);
313 s = pa_strbuf_new();
314
315 pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_size(c->sink_inputs));
316
317 for (i = pa_idxset_first(c->sink_inputs, &idx); i; i = pa_idxset_next(c->sink_inputs, &idx)) {
318 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t;
319
320 pa_assert(i->sink);
321
322 pa_strbuf_printf(
323 s,
324 " index: %u\n"
325 "\tdriver: <%s>\n"
326 "\tflags: %s%s%s%s%s%s%s%s\n"
327 "\tstate: %s\n"
328 "\tsink: %u <%s>\n"
329 "\tvolume: %s\n"
330 "\tmuted: %s\n"
331 "\tlatency: %0.2f ms\n"
332 "\tsample spec: %s\n"
333 "\tchannel map: %s\n"
334 "\tresample method: %s\n",
335 i->index,
336 i->driver,
337 i->flags & PA_SINK_INPUT_VARIABLE_RATE ? "VARIABLE_RATE " : "",
338 i->flags & PA_SINK_INPUT_DONT_MOVE ? "DONT_MOVE " : "",
339 i->flags & PA_SINK_INPUT_START_CORKED ? "START_CORKED " : "",
340 i->flags & PA_SINK_INPUT_NO_REMAP ? "NO_REMAP " : "",
341 i->flags & PA_SINK_INPUT_NO_REMIX ? "NO_REMIX " : "",
342 i->flags & PA_SINK_INPUT_FIX_FORMAT ? "FIX_FORMAT " : "",
343 i->flags & PA_SINK_INPUT_FIX_RATE ? "FIX_RATE " : "",
344 i->flags & PA_SINK_INPUT_FIX_CHANNELS ? "FIX_CHANNELS " : "",
345 state_table[pa_sink_input_get_state(i)],
346 i->sink->index, i->sink->name,
347 pa_cvolume_snprint(cv, sizeof(cv), pa_sink_input_get_volume(i)),
348 pa_yes_no(pa_sink_input_get_mute(i)),
349 (double) pa_sink_input_get_latency(i) / PA_USEC_PER_MSEC,
350 pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec),
351 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
352 pa_resample_method_to_string(pa_sink_input_get_resample_method(i)));
353
354 if (i->module)
355 pa_strbuf_printf(s, "\tmodule: %u\n", i->module->index);
356 if (i->client)
357 pa_strbuf_printf(s, "\tclient: %u <%s>\n", i->client->index, pa_strnull(pa_proplist_gets(i->client->proplist, PA_PROP_APPLICATION_NAME)));
358
359 t = pa_proplist_to_string(i->proplist);
360 pa_strbuf_printf(s, "\tproperties:\n%s", t);
361 pa_xfree(t);
362 }
363
364 return pa_strbuf_tostring_free(s);
365 }
366
367 char *pa_scache_list_to_string(pa_core *c) {
368 pa_strbuf *s;
369 pa_assert(c);
370
371 s = pa_strbuf_new();
372
373 pa_strbuf_printf(s, "%u cache entries available.\n", c->scache ? pa_idxset_size(c->scache) : 0);
374
375 if (c->scache) {
376 pa_scache_entry *e;
377 uint32_t idx = PA_IDXSET_INVALID;
378
379 for (e = pa_idxset_first(c->scache, &idx); e; e = pa_idxset_next(c->scache, &idx)) {
380 double l = 0;
381 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX] = "n/a", cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX] = "n/a", *t;
382
383 if (e->memchunk.memblock) {
384 pa_sample_spec_snprint(ss, sizeof(ss), &e->sample_spec);
385 pa_channel_map_snprint(cm, sizeof(cm), &e->channel_map);
386 l = (double) e->memchunk.length / pa_bytes_per_second(&e->sample_spec);
387 }
388
389 pa_strbuf_printf(
390 s,
391 " name: <%s>\n"
392 "\tindex: %u\n"
393 "\tsample spec: %s\n"
394 "\tchannel map: %s\n"
395 "\tlength: %lu\n"
396 "\tduration: %0.1f s\n"
397 "\tvolume: %s\n"
398 "\tlazy: %s\n"
399 "\tfilename: <%s>\n",
400 e->name,
401 e->index,
402 ss,
403 cm,
404 (long unsigned)(e->memchunk.memblock ? e->memchunk.length : 0),
405 l,
406 pa_cvolume_snprint(cv, sizeof(cv), &e->volume),
407 pa_yes_no(e->lazy),
408 e->filename ? e->filename : "n/a");
409
410 t = pa_proplist_to_string(e->proplist);
411 pa_strbuf_printf(s, "\tproperties:\n%s", t);
412 pa_xfree(t);
413 }
414 }
415
416 return pa_strbuf_tostring_free(s);
417 }
418
419 char *pa_autoload_list_to_string(pa_core *c) {
420 pa_strbuf *s;
421 pa_assert(c);
422
423 s = pa_strbuf_new();
424
425 pa_strbuf_printf(s, "%u autoload entries available.\n", c->autoload_hashmap ? pa_hashmap_size(c->autoload_hashmap) : 0);
426
427 if (c->autoload_hashmap) {
428 pa_autoload_entry *e;
429 void *state = NULL;
430
431 while ((e = pa_hashmap_iterate(c->autoload_hashmap, &state, NULL))) {
432 pa_strbuf_printf(
433 s,
434 " name: <%s>\n"
435 "\ttype: %s\n"
436 "\tindex: %u\n"
437 "\tmodule_name: <%s>\n"
438 "\targuments: <%s>\n",
439 e->name,
440 e->type == PA_NAMEREG_SOURCE ? "source" : "sink",
441 e->index,
442 e->module,
443 e->argument ? e->argument : "");
444
445 }
446 }
447
448 return pa_strbuf_tostring_free(s);
449 }
450
451 char *pa_full_status_string(pa_core *c) {
452 pa_strbuf *s;
453 int i;
454
455 s = pa_strbuf_new();
456
457 for (i = 0; i < 8; i++) {
458 char *t = NULL;
459
460 switch (i) {
461 case 0:
462 t = pa_sink_list_to_string(c);
463 break;
464 case 1:
465 t = pa_source_list_to_string(c);
466 break;
467 case 2:
468 t = pa_sink_input_list_to_string(c);
469 break;
470 case 3:
471 t = pa_source_output_list_to_string(c);
472 break;
473 case 4:
474 t = pa_client_list_to_string(c);
475 break;
476 case 5:
477 t = pa_module_list_to_string(c);
478 break;
479 case 6:
480 t = pa_scache_list_to_string(c);
481 break;
482 case 7:
483 t = pa_autoload_list_to_string(c);
484 break;
485 }
486
487 pa_strbuf_puts(s, t);
488 pa_xfree(t);
489 }
490
491 return pa_strbuf_tostring_free(s);
492 }