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