]> code.delx.au - pulseaudio/blob - src/pulsecore/cli-text.c
Rework module-combine to work with glitch-free core; add new max_request field to...
[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 pa_usec_t min_latency, max_latency;
120
121 pa_sink_get_latency_range(sink, &min_latency, &max_latency);
122
123 pa_strbuf_printf(
124 s,
125 " %c index: %u\n"
126 "\tname: <%s>\n"
127 "\tdriver: <%s>\n"
128 "\tflags: %s%s%s%s%s%s\n"
129 "\tstate: %s\n"
130 "\tvolume: %s\n"
131 "\tmuted: %s\n"
132 "\tcurrent latency: %0.2f ms\n"
133 "\tconfigured latency: %0.2f ms; range is %0.2f .. %0.2f ms\n"
134 "\tmax request: %lu KiB\n"
135 "\tmax rewind: %lu KiB\n"
136 "\tmonitor source: %u\n"
137 "\tsample spec: %s\n"
138 "\tchannel map: %s\n"
139 "\tused by: %u\n"
140 "\tlinked by: %u\n",
141 c->default_sink_name && !strcmp(sink->name, c->default_sink_name) ? '*' : ' ',
142 sink->index,
143 sink->name,
144 sink->driver,
145 sink->flags & PA_SINK_HARDWARE ? "HARDWARE " : "",
146 sink->flags & PA_SINK_NETWORK ? "NETWORK " : "",
147 sink->flags & PA_SINK_HW_MUTE_CTRL ? "HW_MUTE_CTRL " : "",
148 sink->flags & PA_SINK_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
149 sink->flags & PA_SINK_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
150 sink->flags & PA_SINK_LATENCY ? "LATENCY " : "",
151 state_table[pa_sink_get_state(sink)],
152 pa_cvolume_snprint(cv, sizeof(cv), pa_sink_get_volume(sink)),
153 pa_yes_no(pa_sink_get_mute(sink)),
154 (double) pa_sink_get_latency(sink) / PA_USEC_PER_MSEC,
155 (double) pa_sink_get_requested_latency(sink) / PA_USEC_PER_MSEC, (double) min_latency / PA_USEC_PER_MSEC, (double) max_latency / PA_USEC_PER_MSEC,
156 (unsigned long) pa_sink_get_max_request(sink) / 1024,
157 (unsigned long) pa_sink_get_max_rewind(sink) / 1024,
158 sink->monitor_source ? sink->monitor_source->index : PA_INVALID_INDEX,
159 pa_sample_spec_snprint(ss, sizeof(ss), &sink->sample_spec),
160 pa_channel_map_snprint(cm, sizeof(cm), &sink->channel_map),
161 pa_sink_used_by(sink),
162 pa_sink_linked_by(sink));
163
164 if (sink->module)
165 pa_strbuf_printf(s, "\tmodule: %u\n", sink->module->index);
166
167 t = pa_proplist_to_string(sink->proplist);
168 pa_strbuf_printf(s, "\tproperties:\n%s", t);
169 pa_xfree(t);
170 }
171
172 return pa_strbuf_tostring_free(s);
173 }
174
175 char *pa_source_list_to_string(pa_core *c) {
176 pa_strbuf *s;
177 pa_source *source;
178 uint32_t idx = PA_IDXSET_INVALID;
179 static const char* const state_table[] = {
180 [PA_SOURCE_INIT] = "INIT",
181 [PA_SOURCE_RUNNING] = "RUNNING",
182 [PA_SOURCE_SUSPENDED] = "SUSPENDED",
183 [PA_SOURCE_IDLE] = "IDLE",
184 [PA_SOURCE_UNLINKED] = "UNLINKED"
185 };
186 pa_assert(c);
187
188 s = pa_strbuf_new();
189
190 pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_size(c->sources));
191
192 for (source = pa_idxset_first(c->sources, &idx); source; source = pa_idxset_next(c->sources, &idx)) {
193 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], *t;
194 pa_usec_t min_latency, max_latency;
195
196 pa_source_get_latency_range(source, &min_latency, &max_latency);
197
198 pa_strbuf_printf(
199 s,
200 " %c index: %u\n"
201 "\tname: <%s>\n"
202 "\tdriver: <%s>\n"
203 "\tflags: %s%s%s%s%s%s\n"
204 "\tstate: %s\n"
205 "\tvolume: %s\n"
206 "\tmuted: %s\n"
207 "\tcurrent latency: %0.2f ms\n"
208 "\tconfigured latency: %0.2f ms; range is %0.2f .. %0.2f ms\n"
209 "\tmax rewind: %lu KiB\n"
210 "\tsample spec: %s\n"
211 "\tchannel map: %s\n"
212 "\tused by: %u\n"
213 "\tlinked by: %u\n",
214 c->default_source_name && !strcmp(source->name, c->default_source_name) ? '*' : ' ',
215 source->index,
216 source->name,
217 source->driver,
218 source->flags & PA_SOURCE_HARDWARE ? "HARDWARE " : "",
219 source->flags & PA_SOURCE_NETWORK ? "NETWORK " : "",
220 source->flags & PA_SOURCE_HW_MUTE_CTRL ? "HW_MUTE_CTRL " : "",
221 source->flags & PA_SOURCE_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
222 source->flags & PA_SOURCE_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
223 source->flags & PA_SOURCE_LATENCY ? "LATENCY " : "",
224 state_table[pa_source_get_state(source)],
225 pa_cvolume_snprint(cv, sizeof(cv), pa_source_get_volume(source)),
226 pa_yes_no(pa_source_get_mute(source)),
227 (double) pa_source_get_latency(source) / PA_USEC_PER_MSEC,
228 (double) pa_source_get_requested_latency(source) / PA_USEC_PER_MSEC, (double) min_latency / PA_USEC_PER_MSEC, (double) max_latency / PA_USEC_PER_MSEC,
229 (unsigned long) pa_source_get_max_rewind(source) / 1024,
230 pa_sample_spec_snprint(ss, sizeof(ss), &source->sample_spec),
231 pa_channel_map_snprint(cm, sizeof(cm), &source->channel_map),
232 pa_source_used_by(source),
233 pa_source_linked_by(source));
234
235 if (source->monitor_of)
236 pa_strbuf_printf(s, "\tmonitor_of: %u\n", source->monitor_of->index);
237 if (source->module)
238 pa_strbuf_printf(s, "\tmodule: %u\n", source->module->index);
239
240 t = pa_proplist_to_string(source->proplist);
241 pa_strbuf_printf(s, "\tproperties:\n%s", t);
242 pa_xfree(t);
243 }
244
245 return pa_strbuf_tostring_free(s);
246 }
247
248
249 char *pa_source_output_list_to_string(pa_core *c) {
250 pa_strbuf *s;
251 pa_source_output *o;
252 uint32_t idx = PA_IDXSET_INVALID;
253 static const char* const state_table[] = {
254 [PA_SOURCE_OUTPUT_INIT] = "INIT",
255 [PA_SOURCE_OUTPUT_RUNNING] = "RUNNING",
256 [PA_SOURCE_OUTPUT_CORKED] = "CORKED",
257 [PA_SOURCE_OUTPUT_UNLINKED] = "UNLINKED"
258 };
259 pa_assert(c);
260
261 s = pa_strbuf_new();
262
263 pa_strbuf_printf(s, "%u source outputs(s) available.\n", pa_idxset_size(c->source_outputs));
264
265 for (o = pa_idxset_first(c->source_outputs, &idx); o; o = pa_idxset_next(c->source_outputs, &idx)) {
266 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t, clt[28];
267 pa_usec_t cl;
268
269 if ((cl = pa_source_output_get_requested_latency(o)) == (pa_usec_t) -1)
270 pa_snprintf(clt, sizeof(clt), "n/a");
271 else
272 pa_snprintf(clt, sizeof(clt), "%0.2f ms", (double) cl / PA_USEC_PER_MSEC);
273
274 pa_assert(o->source);
275
276 pa_strbuf_printf(
277 s,
278 " index: %u\n"
279 "\tdriver: <%s>\n"
280 "\tflags: %s%s%s%s%s%s%s%s\n"
281 "\tstate: %s\n"
282 "\tsource: %u <%s>\n"
283 "\tcurrent latency: %0.2f ms\n"
284 "\trequested latency: %s\n"
285 "\tsample spec: %s\n"
286 "\tchannel map: %s\n"
287 "\tresample method: %s\n",
288 o->index,
289 o->driver,
290 o->flags & PA_SOURCE_OUTPUT_VARIABLE_RATE ? "VARIABLE_RATE " : "",
291 o->flags & PA_SOURCE_OUTPUT_DONT_MOVE ? "DONT_MOVE " : "",
292 o->flags & PA_SOURCE_OUTPUT_START_CORKED ? "START_CORKED " : "",
293 o->flags & PA_SOURCE_OUTPUT_NO_REMAP ? "NO_REMAP " : "",
294 o->flags & PA_SOURCE_OUTPUT_NO_REMIX ? "NO_REMIX " : "",
295 o->flags & PA_SOURCE_OUTPUT_FIX_FORMAT ? "FIX_FORMAT " : "",
296 o->flags & PA_SOURCE_OUTPUT_FIX_RATE ? "FIX_RATE " : "",
297 o->flags & PA_SOURCE_OUTPUT_FIX_CHANNELS ? "FIX_CHANNELS " : "",
298 state_table[pa_source_output_get_state(o)],
299 o->source->index, o->source->name,
300 (double) pa_source_output_get_latency(o, NULL) / PA_USEC_PER_MSEC,
301 clt,
302 pa_sample_spec_snprint(ss, sizeof(ss), &o->sample_spec),
303 pa_channel_map_snprint(cm, sizeof(cm), &o->channel_map),
304 pa_resample_method_to_string(pa_source_output_get_resample_method(o)));
305 if (o->module)
306 pa_strbuf_printf(s, "\towner module: %u\n", o->module->index);
307 if (o->client)
308 pa_strbuf_printf(s, "\tclient: %u <%s>\n", o->client->index, pa_strnull(pa_proplist_gets(o->client->proplist, PA_PROP_APPLICATION_NAME)));
309 if (o->direct_on_input)
310 pa_strbuf_printf(s, "\tdirect on input: %u\n", o->direct_on_input->index);
311
312 t = pa_proplist_to_string(o->proplist);
313 pa_strbuf_printf(s, "\tproperties:\n%s", t);
314 pa_xfree(t);
315 }
316
317 return pa_strbuf_tostring_free(s);
318 }
319
320 char *pa_sink_input_list_to_string(pa_core *c) {
321 pa_strbuf *s;
322 pa_sink_input *i;
323 uint32_t idx = PA_IDXSET_INVALID;
324 static const char* const state_table[] = {
325 [PA_SINK_INPUT_INIT] = "INIT",
326 [PA_SINK_INPUT_RUNNING] = "RUNNING",
327 [PA_SINK_INPUT_DRAINED] = "DRAINED",
328 [PA_SINK_INPUT_CORKED] = "CORKED",
329 [PA_SINK_INPUT_UNLINKED] = "UNLINKED"
330 };
331
332 pa_assert(c);
333 s = pa_strbuf_new();
334
335 pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_size(c->sink_inputs));
336
337 for (i = pa_idxset_first(c->sink_inputs, &idx); i; i = pa_idxset_next(c->sink_inputs, &idx)) {
338 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t, clt[28];
339 pa_usec_t cl;
340
341 if ((cl = pa_sink_input_get_requested_latency(i)) == (pa_usec_t) -1)
342 pa_snprintf(clt, sizeof(clt), "n/a");
343 else
344 pa_snprintf(clt, sizeof(clt), "%0.2f ms", (double) cl / PA_USEC_PER_MSEC);
345
346 pa_assert(i->sink);
347
348 pa_strbuf_printf(
349 s,
350 " index: %u\n"
351 "\tdriver: <%s>\n"
352 "\tflags: %s%s%s%s%s%s%s%s\n"
353 "\tstate: %s\n"
354 "\tsink: %u <%s>\n"
355 "\tvolume: %s\n"
356 "\tmuted: %s\n"
357 "\tcurrent latency: %0.2f ms\n"
358 "\trequested latency: %s\n"
359 "\tsample spec: %s\n"
360 "\tchannel map: %s\n"
361 "\tresample method: %s\n",
362 i->index,
363 i->driver,
364 i->flags & PA_SINK_INPUT_VARIABLE_RATE ? "VARIABLE_RATE " : "",
365 i->flags & PA_SINK_INPUT_DONT_MOVE ? "DONT_MOVE " : "",
366 i->flags & PA_SINK_INPUT_START_CORKED ? "START_CORKED " : "",
367 i->flags & PA_SINK_INPUT_NO_REMAP ? "NO_REMAP " : "",
368 i->flags & PA_SINK_INPUT_NO_REMIX ? "NO_REMIX " : "",
369 i->flags & PA_SINK_INPUT_FIX_FORMAT ? "FIX_FORMAT " : "",
370 i->flags & PA_SINK_INPUT_FIX_RATE ? "FIX_RATE " : "",
371 i->flags & PA_SINK_INPUT_FIX_CHANNELS ? "FIX_CHANNELS " : "",
372 state_table[pa_sink_input_get_state(i)],
373 i->sink->index, i->sink->name,
374 pa_cvolume_snprint(cv, sizeof(cv), pa_sink_input_get_volume(i)),
375 pa_yes_no(pa_sink_input_get_mute(i)),
376 (double) pa_sink_input_get_latency(i, NULL) / PA_USEC_PER_MSEC,
377 clt,
378 pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec),
379 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
380 pa_resample_method_to_string(pa_sink_input_get_resample_method(i)));
381
382 if (i->module)
383 pa_strbuf_printf(s, "\tmodule: %u\n", i->module->index);
384 if (i->client)
385 pa_strbuf_printf(s, "\tclient: %u <%s>\n", i->client->index, pa_strnull(pa_proplist_gets(i->client->proplist, PA_PROP_APPLICATION_NAME)));
386
387 t = pa_proplist_to_string(i->proplist);
388 pa_strbuf_printf(s, "\tproperties:\n%s", t);
389 pa_xfree(t);
390 }
391
392 return pa_strbuf_tostring_free(s);
393 }
394
395 char *pa_scache_list_to_string(pa_core *c) {
396 pa_strbuf *s;
397 pa_assert(c);
398
399 s = pa_strbuf_new();
400
401 pa_strbuf_printf(s, "%u cache entries available.\n", c->scache ? pa_idxset_size(c->scache) : 0);
402
403 if (c->scache) {
404 pa_scache_entry *e;
405 uint32_t idx = PA_IDXSET_INVALID;
406
407 for (e = pa_idxset_first(c->scache, &idx); e; e = pa_idxset_next(c->scache, &idx)) {
408 double l = 0;
409 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX] = "n/a", cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX] = "n/a", *t;
410
411 if (e->memchunk.memblock) {
412 pa_sample_spec_snprint(ss, sizeof(ss), &e->sample_spec);
413 pa_channel_map_snprint(cm, sizeof(cm), &e->channel_map);
414 l = (double) e->memchunk.length / pa_bytes_per_second(&e->sample_spec);
415 }
416
417 pa_strbuf_printf(
418 s,
419 " name: <%s>\n"
420 "\tindex: %u\n"
421 "\tsample spec: %s\n"
422 "\tchannel map: %s\n"
423 "\tlength: %lu\n"
424 "\tduration: %0.1f s\n"
425 "\tvolume: %s\n"
426 "\tlazy: %s\n"
427 "\tfilename: <%s>\n",
428 e->name,
429 e->index,
430 ss,
431 cm,
432 (long unsigned)(e->memchunk.memblock ? e->memchunk.length : 0),
433 l,
434 pa_cvolume_snprint(cv, sizeof(cv), &e->volume),
435 pa_yes_no(e->lazy),
436 e->filename ? e->filename : "n/a");
437
438 t = pa_proplist_to_string(e->proplist);
439 pa_strbuf_printf(s, "\tproperties:\n%s", t);
440 pa_xfree(t);
441 }
442 }
443
444 return pa_strbuf_tostring_free(s);
445 }
446
447 char *pa_autoload_list_to_string(pa_core *c) {
448 pa_strbuf *s;
449 pa_assert(c);
450
451 s = pa_strbuf_new();
452
453 pa_strbuf_printf(s, "%u autoload entries available.\n", c->autoload_hashmap ? pa_hashmap_size(c->autoload_hashmap) : 0);
454
455 if (c->autoload_hashmap) {
456 pa_autoload_entry *e;
457 void *state = NULL;
458
459 while ((e = pa_hashmap_iterate(c->autoload_hashmap, &state, NULL))) {
460 pa_strbuf_printf(
461 s,
462 " name: <%s>\n"
463 "\ttype: %s\n"
464 "\tindex: %u\n"
465 "\tmodule_name: <%s>\n"
466 "\targuments: <%s>\n",
467 e->name,
468 e->type == PA_NAMEREG_SOURCE ? "source" : "sink",
469 e->index,
470 e->module,
471 e->argument ? e->argument : "");
472
473 }
474 }
475
476 return pa_strbuf_tostring_free(s);
477 }
478
479 char *pa_full_status_string(pa_core *c) {
480 pa_strbuf *s;
481 int i;
482
483 s = pa_strbuf_new();
484
485 for (i = 0; i < 8; i++) {
486 char *t = NULL;
487
488 switch (i) {
489 case 0:
490 t = pa_sink_list_to_string(c);
491 break;
492 case 1:
493 t = pa_source_list_to_string(c);
494 break;
495 case 2:
496 t = pa_sink_input_list_to_string(c);
497 break;
498 case 3:
499 t = pa_source_output_list_to_string(c);
500 break;
501 case 4:
502 t = pa_client_list_to_string(c);
503 break;
504 case 5:
505 t = pa_module_list_to_string(c);
506 break;
507 case 6:
508 t = pa_scache_list_to_string(c);
509 break;
510 case 7:
511 t = pa_autoload_list_to_string(c);
512 break;
513 }
514
515 pa_strbuf_puts(s, t);
516 pa_xfree(t);
517 }
518
519 return pa_strbuf_tostring_free(s);
520 }