]> code.delx.au - pulseaudio/blob - src/pulsecore/cli-text.c
9b31e97d5b5e4f6465a6fc2fb31bf90622cb100c
[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.1 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 <pulse/volume.h>
27 #include <pulse/xmalloc.h>
28 #include <pulse/timeval.h>
29
30 #include <pulsecore/module.h>
31 #include <pulsecore/client.h>
32 #include <pulsecore/sink.h>
33 #include <pulsecore/source.h>
34 #include <pulsecore/sink-input.h>
35 #include <pulsecore/source-output.h>
36 #include <pulsecore/strbuf.h>
37 #include <pulsecore/core-scache.h>
38 #include <pulsecore/macro.h>
39 #include <pulsecore/core-util.h>
40 #include <pulsecore/namereg.h>
41
42 #include "cli-text.h"
43
44 char *pa_module_list_to_string(pa_core *c) {
45 pa_strbuf *s;
46 pa_module *m;
47 uint32_t idx = PA_IDXSET_INVALID;
48 pa_assert(c);
49
50 s = pa_strbuf_new();
51
52 pa_strbuf_printf(s, "%u module(s) loaded.\n", pa_idxset_size(c->modules));
53
54 PA_IDXSET_FOREACH(m, c->modules, idx) {
55 char *t;
56
57 pa_strbuf_printf(s, " index: %u\n"
58 "\tname: <%s>\n"
59 "\targument: <%s>\n"
60 "\tused: %i\n"
61 "\tload once: %s\n",
62 m->index,
63 m->name,
64 pa_strempty(m->argument),
65 pa_module_get_n_used(m),
66 pa_yes_no(m->load_once));
67
68 t = pa_proplist_to_string_sep(m->proplist, "\n\t\t");
69 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
70 pa_xfree(t);
71 }
72
73 return pa_strbuf_tostring_free(s);
74 }
75
76 char *pa_client_list_to_string(pa_core *c) {
77 pa_strbuf *s;
78 pa_client *client;
79 uint32_t idx = PA_IDXSET_INVALID;
80 pa_assert(c);
81
82 s = pa_strbuf_new();
83
84 pa_strbuf_printf(s, "%u client(s) logged in.\n", pa_idxset_size(c->clients));
85
86 PA_IDXSET_FOREACH(client, c->clients, idx) {
87 char *t;
88 pa_strbuf_printf(
89 s,
90 " index: %u\n"
91 "\tdriver: <%s>\n",
92 client->index,
93 client->driver);
94
95 if (client->module)
96 pa_strbuf_printf(s, "\towner module: %u\n", client->module->index);
97
98 t = pa_proplist_to_string_sep(client->proplist, "\n\t\t");
99 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
100 pa_xfree(t);
101 }
102
103 return pa_strbuf_tostring_free(s);
104 }
105
106 static const char *available_to_string(pa_available_t a) {
107 switch (a) {
108 case PA_AVAILABLE_UNKNOWN:
109 return "unknown";
110 case PA_AVAILABLE_NO:
111 return "no";
112 case PA_AVAILABLE_YES:
113 return "yes";
114 default:
115 return "invalid"; /* Should never happen! */
116 }
117 }
118
119 static void append_port_list(pa_strbuf *s, pa_hashmap *ports) {
120 pa_device_port *p;
121 void *state;
122
123 pa_assert(ports);
124
125 if (pa_hashmap_isempty(ports))
126 return;
127
128 pa_strbuf_puts(s, "\tports:\n");
129 PA_HASHMAP_FOREACH(p, ports, state) {
130 char *t = pa_proplist_to_string_sep(p->proplist, "\n\t\t\t\t");
131 pa_strbuf_printf(s, "\t\t%s: %s (priority %u, latency offset %" PRId64 " usec, available: %s)\n",
132 p->name, p->description, p->priority, p->latency_offset,
133 available_to_string(p->available));
134 pa_strbuf_printf(s, "\t\t\tproperties:\n\t\t\t\t%s\n", t);
135 pa_xfree(t);
136 }
137 }
138
139 char *pa_card_list_to_string(pa_core *c) {
140 pa_strbuf *s;
141 pa_card *card;
142 uint32_t idx = PA_IDXSET_INVALID;
143 pa_assert(c);
144
145 s = pa_strbuf_new();
146
147 pa_strbuf_printf(s, "%u card(s) available.\n", pa_idxset_size(c->cards));
148
149 PA_IDXSET_FOREACH(card, c->cards, idx) {
150 char *t;
151 pa_sink *sink;
152 pa_source *source;
153 uint32_t sidx;
154 pa_card_profile *profile;
155 void *state;
156
157 pa_strbuf_printf(
158 s,
159 " index: %u\n"
160 "\tname: <%s>\n"
161 "\tdriver: <%s>\n",
162 card->index,
163 card->name,
164 card->driver);
165
166 if (card->module)
167 pa_strbuf_printf(s, "\towner module: %u\n", card->module->index);
168
169 t = pa_proplist_to_string_sep(card->proplist, "\n\t\t");
170 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
171 pa_xfree(t);
172
173 pa_strbuf_puts(s, "\tprofiles:\n");
174 PA_HASHMAP_FOREACH(profile, card->profiles, state)
175 pa_strbuf_printf(s, "\t\t%s: %s (priority %u, available: %s)\n", profile->name, profile->description,
176 profile->priority, available_to_string(profile->available));
177
178 pa_strbuf_printf(
179 s,
180 "\tactive profile: <%s>\n",
181 card->active_profile->name);
182
183 if (!pa_idxset_isempty(card->sinks)) {
184 pa_strbuf_puts(s, "\tsinks:\n");
185 PA_IDXSET_FOREACH(sink, card->sinks, sidx)
186 pa_strbuf_printf(s, "\t\t%s/#%u: %s\n", sink->name, sink->index, pa_strna(pa_proplist_gets(sink->proplist, PA_PROP_DEVICE_DESCRIPTION)));
187 }
188
189 if (!pa_idxset_isempty(card->sources)) {
190 pa_strbuf_puts(s, "\tsources:\n");
191 PA_IDXSET_FOREACH(source, card->sources, sidx)
192 pa_strbuf_printf(s, "\t\t%s/#%u: %s\n", source->name, source->index, pa_strna(pa_proplist_gets(source->proplist, PA_PROP_DEVICE_DESCRIPTION)));
193 }
194
195 append_port_list(s, card->ports);
196 }
197
198 return pa_strbuf_tostring_free(s);
199 }
200
201 static const char *sink_state_to_string(pa_sink_state_t state) {
202 switch (state) {
203 case PA_SINK_INIT:
204 return "INIT";
205 case PA_SINK_RUNNING:
206 return "RUNNING";
207 case PA_SINK_SUSPENDED:
208 return "SUSPENDED";
209 case PA_SINK_IDLE:
210 return "IDLE";
211 case PA_SINK_UNLINKED:
212 return "UNLINKED";
213 default:
214 return "INVALID";
215 }
216 }
217
218 static const char *source_state_to_string(pa_source_state_t state) {
219 switch (state) {
220 case PA_SOURCE_INIT:
221 return "INIT";
222 case PA_SOURCE_RUNNING:
223 return "RUNNING";
224 case PA_SOURCE_SUSPENDED:
225 return "SUSPENDED";
226 case PA_SOURCE_IDLE:
227 return "IDLE";
228 case PA_SOURCE_UNLINKED:
229 return "UNLINKED";
230 default:
231 return "INVALID";
232 }
233 }
234
235 char *pa_sink_list_to_string(pa_core *c) {
236 pa_strbuf *s;
237 pa_sink *sink, *default_sink;
238 uint32_t idx = PA_IDXSET_INVALID;
239 pa_assert(c);
240
241 s = pa_strbuf_new();
242
243 pa_strbuf_printf(s, "%u sink(s) available.\n", pa_idxset_size(c->sinks));
244
245 default_sink = pa_namereg_get_default_sink(c);
246
247 PA_IDXSET_FOREACH(sink, c->sinks, idx) {
248 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX],
249 cv[PA_CVOLUME_SNPRINT_MAX],
250 cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX],
251 v[PA_VOLUME_SNPRINT_MAX],
252 vdb[PA_SW_VOLUME_SNPRINT_DB_MAX],
253 cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t;
254 const char *cmn;
255
256 cmn = pa_channel_map_to_pretty_name(&sink->channel_map);
257
258
259 pa_strbuf_printf(
260 s,
261 " %c index: %u\n"
262 "\tname: <%s>\n"
263 "\tdriver: <%s>\n"
264 "\tflags: %s%s%s%s%s%s%s%s\n"
265 "\tstate: %s\n"
266 "\tsuspend cause: %s%s%s%s\n"
267 "\tpriority: %u\n"
268 "\tvolume: %s%s%s\n"
269 "\t balance %0.2f\n"
270 "\tbase volume: %s%s%s\n"
271 "\tvolume steps: %u\n"
272 "\tmuted: %s\n"
273 "\tcurrent latency: %0.2f ms\n"
274 "\tmax request: %lu KiB\n"
275 "\tmax rewind: %lu KiB\n"
276 "\tmonitor source: %u\n"
277 "\tsample spec: %s\n"
278 "\tchannel map: %s%s%s\n"
279 "\tused by: %u\n"
280 "\tlinked by: %u\n",
281 sink == default_sink ? '*' : ' ',
282 sink->index,
283 sink->name,
284 sink->driver,
285 sink->flags & PA_SINK_HARDWARE ? "HARDWARE " : "",
286 sink->flags & PA_SINK_NETWORK ? "NETWORK " : "",
287 sink->flags & PA_SINK_HW_MUTE_CTRL ? "HW_MUTE_CTRL " : "",
288 sink->flags & PA_SINK_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
289 sink->flags & PA_SINK_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
290 sink->flags & PA_SINK_LATENCY ? "LATENCY " : "",
291 sink->flags & PA_SINK_FLAT_VOLUME ? "FLAT_VOLUME " : "",
292 sink->flags & PA_SINK_DYNAMIC_LATENCY ? "DYNAMIC_LATENCY" : "",
293 sink_state_to_string(pa_sink_get_state(sink)),
294 sink->suspend_cause & PA_SUSPEND_USER ? "USER " : "",
295 sink->suspend_cause & PA_SUSPEND_APPLICATION ? "APPLICATION " : "",
296 sink->suspend_cause & PA_SUSPEND_IDLE ? "IDLE " : "",
297 sink->suspend_cause & PA_SUSPEND_SESSION ? "SESSION" : "",
298 sink->priority,
299 pa_cvolume_snprint(cv, sizeof(cv), pa_sink_get_volume(sink, FALSE)),
300 sink->flags & PA_SINK_DECIBEL_VOLUME ? "\n\t " : "",
301 sink->flags & PA_SINK_DECIBEL_VOLUME ? pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), pa_sink_get_volume(sink, FALSE)) : "",
302 pa_cvolume_get_balance(pa_sink_get_volume(sink, FALSE), &sink->channel_map),
303 pa_volume_snprint(v, sizeof(v), sink->base_volume),
304 sink->flags & PA_SINK_DECIBEL_VOLUME ? "\n\t " : "",
305 sink->flags & PA_SINK_DECIBEL_VOLUME ? pa_sw_volume_snprint_dB(vdb, sizeof(vdb), sink->base_volume) : "",
306 sink->n_volume_steps,
307 pa_yes_no(pa_sink_get_mute(sink, FALSE)),
308 (double) pa_sink_get_latency(sink) / (double) PA_USEC_PER_MSEC,
309 (unsigned long) pa_sink_get_max_request(sink) / 1024,
310 (unsigned long) pa_sink_get_max_rewind(sink) / 1024,
311 sink->monitor_source ? sink->monitor_source->index : PA_INVALID_INDEX,
312 pa_sample_spec_snprint(ss, sizeof(ss), &sink->sample_spec),
313 pa_channel_map_snprint(cm, sizeof(cm), &sink->channel_map),
314 cmn ? "\n\t " : "",
315 cmn ? cmn : "",
316 pa_sink_used_by(sink),
317 pa_sink_linked_by(sink));
318
319 if (sink->flags & PA_SINK_DYNAMIC_LATENCY) {
320 pa_usec_t min_latency, max_latency;
321 pa_sink_get_latency_range(sink, &min_latency, &max_latency);
322
323 pa_strbuf_printf(
324 s,
325 "\tconfigured latency: %0.2f ms; range is %0.2f .. %0.2f ms\n",
326 (double) pa_sink_get_requested_latency(sink) / (double) PA_USEC_PER_MSEC,
327 (double) min_latency / PA_USEC_PER_MSEC,
328 (double) max_latency / PA_USEC_PER_MSEC);
329 } else
330 pa_strbuf_printf(
331 s,
332 "\tfixed latency: %0.2f ms\n",
333 (double) pa_sink_get_fixed_latency(sink) / PA_USEC_PER_MSEC);
334
335 if (sink->card)
336 pa_strbuf_printf(s, "\tcard: %u <%s>\n", sink->card->index, sink->card->name);
337 if (sink->module)
338 pa_strbuf_printf(s, "\tmodule: %u\n", sink->module->index);
339
340 t = pa_proplist_to_string_sep(sink->proplist, "\n\t\t");
341 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
342 pa_xfree(t);
343
344 append_port_list(s, sink->ports);
345
346 if (sink->active_port)
347 pa_strbuf_printf(
348 s,
349 "\tactive port: <%s>\n",
350 sink->active_port->name);
351 }
352
353 return pa_strbuf_tostring_free(s);
354 }
355
356 char *pa_source_list_to_string(pa_core *c) {
357 pa_strbuf *s;
358 pa_source *source, *default_source;
359 uint32_t idx = PA_IDXSET_INVALID;
360 pa_assert(c);
361
362 s = pa_strbuf_new();
363
364 pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_size(c->sources));
365
366 default_source = pa_namereg_get_default_source(c);
367
368 PA_IDXSET_FOREACH(source, c->sources, idx) {
369 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX],
370 cv[PA_CVOLUME_SNPRINT_MAX],
371 cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX],
372 v[PA_VOLUME_SNPRINT_MAX],
373 vdb[PA_SW_VOLUME_SNPRINT_DB_MAX],
374 cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t;
375 const char *cmn;
376
377 cmn = pa_channel_map_to_pretty_name(&source->channel_map);
378
379 pa_strbuf_printf(
380 s,
381 " %c index: %u\n"
382 "\tname: <%s>\n"
383 "\tdriver: <%s>\n"
384 "\tflags: %s%s%s%s%s%s%s\n"
385 "\tstate: %s\n"
386 "\tsuspend cause: %s%s%s%s\n"
387 "\tpriority: %u\n"
388 "\tvolume: %s%s%s\n"
389 "\t balance %0.2f\n"
390 "\tbase volume: %s%s%s\n"
391 "\tvolume steps: %u\n"
392 "\tmuted: %s\n"
393 "\tcurrent latency: %0.2f ms\n"
394 "\tmax rewind: %lu KiB\n"
395 "\tsample spec: %s\n"
396 "\tchannel map: %s%s%s\n"
397 "\tused by: %u\n"
398 "\tlinked by: %u\n",
399 source == default_source ? '*' : ' ',
400 source->index,
401 source->name,
402 source->driver,
403 source->flags & PA_SOURCE_HARDWARE ? "HARDWARE " : "",
404 source->flags & PA_SOURCE_NETWORK ? "NETWORK " : "",
405 source->flags & PA_SOURCE_HW_MUTE_CTRL ? "HW_MUTE_CTRL " : "",
406 source->flags & PA_SOURCE_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
407 source->flags & PA_SOURCE_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
408 source->flags & PA_SOURCE_LATENCY ? "LATENCY " : "",
409 source->flags & PA_SOURCE_DYNAMIC_LATENCY ? "DYNAMIC_LATENCY" : "",
410 source_state_to_string(pa_source_get_state(source)),
411 source->suspend_cause & PA_SUSPEND_USER ? "USER " : "",
412 source->suspend_cause & PA_SUSPEND_APPLICATION ? "APPLICATION " : "",
413 source->suspend_cause & PA_SUSPEND_IDLE ? "IDLE " : "",
414 source->suspend_cause & PA_SUSPEND_SESSION ? "SESSION" : "",
415 source->priority,
416 pa_cvolume_snprint(cv, sizeof(cv), pa_source_get_volume(source, FALSE)),
417 source->flags & PA_SOURCE_DECIBEL_VOLUME ? "\n\t " : "",
418 source->flags & PA_SOURCE_DECIBEL_VOLUME ? pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), pa_source_get_volume(source, FALSE)) : "",
419 pa_cvolume_get_balance(pa_source_get_volume(source, FALSE), &source->channel_map),
420 pa_volume_snprint(v, sizeof(v), source->base_volume),
421 source->flags & PA_SOURCE_DECIBEL_VOLUME ? "\n\t " : "",
422 source->flags & PA_SOURCE_DECIBEL_VOLUME ? pa_sw_volume_snprint_dB(vdb, sizeof(vdb), source->base_volume) : "",
423 source->n_volume_steps,
424 pa_yes_no(pa_source_get_mute(source, FALSE)),
425 (double) pa_source_get_latency(source) / PA_USEC_PER_MSEC,
426 (unsigned long) pa_source_get_max_rewind(source) / 1024,
427 pa_sample_spec_snprint(ss, sizeof(ss), &source->sample_spec),
428 pa_channel_map_snprint(cm, sizeof(cm), &source->channel_map),
429 cmn ? "\n\t " : "",
430 cmn ? cmn : "",
431 pa_source_used_by(source),
432 pa_source_linked_by(source));
433
434 if (source->flags & PA_SOURCE_DYNAMIC_LATENCY) {
435 pa_usec_t min_latency, max_latency;
436 pa_source_get_latency_range(source, &min_latency, &max_latency);
437
438 pa_strbuf_printf(
439 s,
440 "\tconfigured latency: %0.2f ms; range is %0.2f .. %0.2f ms\n",
441 (double) pa_source_get_requested_latency(source) / PA_USEC_PER_MSEC,
442 (double) min_latency / PA_USEC_PER_MSEC,
443 (double) max_latency / PA_USEC_PER_MSEC);
444 } else
445 pa_strbuf_printf(
446 s,
447 "\tfixed latency: %0.2f ms\n",
448 (double) pa_source_get_fixed_latency(source) / PA_USEC_PER_MSEC);
449
450 if (source->monitor_of)
451 pa_strbuf_printf(s, "\tmonitor_of: %u\n", source->monitor_of->index);
452 if (source->card)
453 pa_strbuf_printf(s, "\tcard: %u <%s>\n", source->card->index, source->card->name);
454 if (source->module)
455 pa_strbuf_printf(s, "\tmodule: %u\n", source->module->index);
456
457 t = pa_proplist_to_string_sep(source->proplist, "\n\t\t");
458 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
459 pa_xfree(t);
460
461 append_port_list(s, source->ports);
462
463 if (source->active_port)
464 pa_strbuf_printf(
465 s,
466 "\tactive port: <%s>\n",
467 source->active_port->name);
468 }
469
470 return pa_strbuf_tostring_free(s);
471 }
472
473
474 char *pa_source_output_list_to_string(pa_core *c) {
475 pa_strbuf *s;
476 pa_source_output *o;
477 uint32_t idx = PA_IDXSET_INVALID;
478 static const char* const state_table[] = {
479 [PA_SOURCE_OUTPUT_INIT] = "INIT",
480 [PA_SOURCE_OUTPUT_RUNNING] = "RUNNING",
481 [PA_SOURCE_OUTPUT_CORKED] = "CORKED",
482 [PA_SOURCE_OUTPUT_UNLINKED] = "UNLINKED"
483 };
484 pa_assert(c);
485
486 s = pa_strbuf_new();
487
488 pa_strbuf_printf(s, "%u source output(s) available.\n", pa_idxset_size(c->source_outputs));
489
490 PA_IDXSET_FOREACH(o, c->source_outputs, idx) {
491 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t, clt[28];
492 pa_usec_t cl;
493 const char *cmn;
494 pa_cvolume v;
495 char *volume_str = NULL;
496
497 cmn = pa_channel_map_to_pretty_name(&o->channel_map);
498
499 if ((cl = pa_source_output_get_requested_latency(o)) == (pa_usec_t) -1)
500 pa_snprintf(clt, sizeof(clt), "n/a");
501 else
502 pa_snprintf(clt, sizeof(clt), "%0.2f ms", (double) cl / PA_USEC_PER_MSEC);
503
504 pa_assert(o->source);
505
506 if (pa_source_output_is_volume_readable(o)) {
507 pa_source_output_get_volume(o, &v, TRUE);
508 volume_str = pa_sprintf_malloc("%s\n\t %s\n\t balance %0.2f",
509 pa_cvolume_snprint(cv, sizeof(cv), &v),
510 pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &v),
511 pa_cvolume_get_balance(&v, &o->channel_map));
512 } else
513 volume_str = pa_xstrdup("n/a");
514
515
516 pa_strbuf_printf(
517 s,
518 " index: %u\n"
519 "\tdriver: <%s>\n"
520 "\tflags: %s%s%s%s%s%s%s%s%s%s%s%s\n"
521 "\tstate: %s\n"
522 "\tsource: %u <%s>\n"
523 "\tvolume: %s\n"
524 "\tmuted: %s\n"
525 "\tcurrent latency: %0.2f ms\n"
526 "\trequested latency: %s\n"
527 "\tsample spec: %s\n"
528 "\tchannel map: %s%s%s\n"
529 "\tresample method: %s\n",
530 o->index,
531 o->driver,
532 o->flags & PA_SOURCE_OUTPUT_VARIABLE_RATE ? "VARIABLE_RATE " : "",
533 o->flags & PA_SOURCE_OUTPUT_DONT_MOVE ? "DONT_MOVE " : "",
534 o->flags & PA_SOURCE_OUTPUT_START_CORKED ? "START_CORKED " : "",
535 o->flags & PA_SOURCE_OUTPUT_NO_REMAP ? "NO_REMAP " : "",
536 o->flags & PA_SOURCE_OUTPUT_NO_REMIX ? "NO_REMIX " : "",
537 o->flags & PA_SOURCE_OUTPUT_FIX_FORMAT ? "FIX_FORMAT " : "",
538 o->flags & PA_SOURCE_OUTPUT_FIX_RATE ? "FIX_RATE " : "",
539 o->flags & PA_SOURCE_OUTPUT_FIX_CHANNELS ? "FIX_CHANNELS " : "",
540 o->flags & PA_SOURCE_OUTPUT_DONT_INHIBIT_AUTO_SUSPEND ? "DONT_INHIBIT_AUTO_SUSPEND " : "",
541 o->flags & PA_SOURCE_OUTPUT_NO_CREATE_ON_SUSPEND ? "NO_CREATE_ON_SUSPEND " : "",
542 o->flags & PA_SOURCE_OUTPUT_KILL_ON_SUSPEND ? "KILL_ON_SUSPEND " : "",
543 o->flags & PA_SOURCE_OUTPUT_PASSTHROUGH ? "PASSTHROUGH " : "",
544 state_table[pa_source_output_get_state(o)],
545 o->source->index, o->source->name,
546 volume_str,
547 pa_yes_no(pa_source_output_get_mute(o)),
548 (double) pa_source_output_get_latency(o, NULL) / PA_USEC_PER_MSEC,
549 clt,
550 pa_sample_spec_snprint(ss, sizeof(ss), &o->sample_spec),
551 pa_channel_map_snprint(cm, sizeof(cm), &o->channel_map),
552 cmn ? "\n\t " : "",
553 cmn ? cmn : "",
554 pa_resample_method_to_string(pa_source_output_get_resample_method(o)));
555
556 pa_xfree(volume_str);
557
558 if (o->module)
559 pa_strbuf_printf(s, "\towner module: %u\n", o->module->index);
560 if (o->client)
561 pa_strbuf_printf(s, "\tclient: %u <%s>\n", o->client->index, pa_strnull(pa_proplist_gets(o->client->proplist, PA_PROP_APPLICATION_NAME)));
562 if (o->direct_on_input)
563 pa_strbuf_printf(s, "\tdirect on input: %u\n", o->direct_on_input->index);
564
565 t = pa_proplist_to_string_sep(o->proplist, "\n\t\t");
566 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
567 pa_xfree(t);
568 }
569
570 return pa_strbuf_tostring_free(s);
571 }
572
573 char *pa_sink_input_list_to_string(pa_core *c) {
574 pa_strbuf *s;
575 pa_sink_input *i;
576 uint32_t idx = PA_IDXSET_INVALID;
577 static const char* const state_table[] = {
578 [PA_SINK_INPUT_INIT] = "INIT",
579 [PA_SINK_INPUT_RUNNING] = "RUNNING",
580 [PA_SINK_INPUT_DRAINED] = "DRAINED",
581 [PA_SINK_INPUT_CORKED] = "CORKED",
582 [PA_SINK_INPUT_UNLINKED] = "UNLINKED"
583 };
584
585 pa_assert(c);
586 s = pa_strbuf_new();
587
588 pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_size(c->sink_inputs));
589
590 PA_IDXSET_FOREACH(i, c->sink_inputs, idx) {
591 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t, clt[28];
592 pa_usec_t cl;
593 const char *cmn;
594 pa_cvolume v;
595 char *volume_str = NULL;
596
597 cmn = pa_channel_map_to_pretty_name(&i->channel_map);
598
599 if ((cl = pa_sink_input_get_requested_latency(i)) == (pa_usec_t) -1)
600 pa_snprintf(clt, sizeof(clt), "n/a");
601 else
602 pa_snprintf(clt, sizeof(clt), "%0.2f ms", (double) cl / PA_USEC_PER_MSEC);
603
604 pa_assert(i->sink);
605
606 if (pa_sink_input_is_volume_readable(i)) {
607 pa_sink_input_get_volume(i, &v, TRUE);
608 volume_str = pa_sprintf_malloc("%s\n\t %s\n\t balance %0.2f",
609 pa_cvolume_snprint(cv, sizeof(cv), &v),
610 pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &v),
611 pa_cvolume_get_balance(&v, &i->channel_map));
612 } else
613 volume_str = pa_xstrdup("n/a");
614
615 pa_strbuf_printf(
616 s,
617 " index: %u\n"
618 "\tdriver: <%s>\n"
619 "\tflags: %s%s%s%s%s%s%s%s%s%s%s%s\n"
620 "\tstate: %s\n"
621 "\tsink: %u <%s>\n"
622 "\tvolume: %s\n"
623 "\tmuted: %s\n"
624 "\tcurrent latency: %0.2f ms\n"
625 "\trequested latency: %s\n"
626 "\tsample spec: %s\n"
627 "\tchannel map: %s%s%s\n"
628 "\tresample method: %s\n",
629 i->index,
630 i->driver,
631 i->flags & PA_SINK_INPUT_VARIABLE_RATE ? "VARIABLE_RATE " : "",
632 i->flags & PA_SINK_INPUT_DONT_MOVE ? "DONT_MOVE " : "",
633 i->flags & PA_SINK_INPUT_START_CORKED ? "START_CORKED " : "",
634 i->flags & PA_SINK_INPUT_NO_REMAP ? "NO_REMAP " : "",
635 i->flags & PA_SINK_INPUT_NO_REMIX ? "NO_REMIX " : "",
636 i->flags & PA_SINK_INPUT_FIX_FORMAT ? "FIX_FORMAT " : "",
637 i->flags & PA_SINK_INPUT_FIX_RATE ? "FIX_RATE " : "",
638 i->flags & PA_SINK_INPUT_FIX_CHANNELS ? "FIX_CHANNELS " : "",
639 i->flags & PA_SINK_INPUT_DONT_INHIBIT_AUTO_SUSPEND ? "DONT_INHIBIT_AUTO_SUSPEND " : "",
640 i->flags & PA_SINK_INPUT_NO_CREATE_ON_SUSPEND ? "NO_CREATE_SUSPEND " : "",
641 i->flags & PA_SINK_INPUT_KILL_ON_SUSPEND ? "KILL_ON_SUSPEND " : "",
642 i->flags & PA_SINK_INPUT_PASSTHROUGH ? "PASSTHROUGH " : "",
643 state_table[pa_sink_input_get_state(i)],
644 i->sink->index, i->sink->name,
645 volume_str,
646 pa_yes_no(pa_sink_input_get_mute(i)),
647 (double) pa_sink_input_get_latency(i, NULL) / PA_USEC_PER_MSEC,
648 clt,
649 pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec),
650 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
651 cmn ? "\n\t " : "",
652 cmn ? cmn : "",
653 pa_resample_method_to_string(pa_sink_input_get_resample_method(i)));
654
655 pa_xfree(volume_str);
656
657 if (i->module)
658 pa_strbuf_printf(s, "\tmodule: %u\n", i->module->index);
659 if (i->client)
660 pa_strbuf_printf(s, "\tclient: %u <%s>\n", i->client->index, pa_strnull(pa_proplist_gets(i->client->proplist, PA_PROP_APPLICATION_NAME)));
661
662 t = pa_proplist_to_string_sep(i->proplist, "\n\t\t");
663 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
664 pa_xfree(t);
665 }
666
667 return pa_strbuf_tostring_free(s);
668 }
669
670 char *pa_scache_list_to_string(pa_core *c) {
671 pa_strbuf *s;
672 pa_assert(c);
673
674 s = pa_strbuf_new();
675
676 pa_strbuf_printf(s, "%u cache entrie(s) available.\n", c->scache ? pa_idxset_size(c->scache) : 0);
677
678 if (c->scache) {
679 pa_scache_entry *e;
680 uint32_t idx = PA_IDXSET_INVALID;
681
682 PA_IDXSET_FOREACH(e, c->scache, idx) {
683 double l = 0;
684 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX] = "n/a", cv[PA_CVOLUME_SNPRINT_MAX], cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX] = "n/a", *t;
685 const char *cmn;
686
687 cmn = pa_channel_map_to_pretty_name(&e->channel_map);
688
689 if (e->memchunk.memblock) {
690 pa_sample_spec_snprint(ss, sizeof(ss), &e->sample_spec);
691 pa_channel_map_snprint(cm, sizeof(cm), &e->channel_map);
692 l = (double) e->memchunk.length / (double) pa_bytes_per_second(&e->sample_spec);
693 }
694
695 pa_strbuf_printf(
696 s,
697 " name: <%s>\n"
698 "\tindex: %u\n"
699 "\tsample spec: %s\n"
700 "\tchannel map: %s%s%s\n"
701 "\tlength: %lu\n"
702 "\tduration: %0.1f s\n"
703 "\tvolume: %s\n"
704 "\t %s\n"
705 "\t balance %0.2f\n"
706 "\tlazy: %s\n"
707 "\tfilename: <%s>\n",
708 e->name,
709 e->index,
710 ss,
711 cm,
712 cmn ? "\n\t " : "",
713 cmn ? cmn : "",
714 (long unsigned)(e->memchunk.memblock ? e->memchunk.length : 0),
715 l,
716 e->volume_is_set ? pa_cvolume_snprint(cv, sizeof(cv), &e->volume) : "n/a",
717 e->volume_is_set ? pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &e->volume) : "n/a",
718 (e->memchunk.memblock && e->volume_is_set) ? pa_cvolume_get_balance(&e->volume, &e->channel_map) : 0.0f,
719 pa_yes_no(e->lazy),
720 e->filename ? e->filename : "n/a");
721
722 t = pa_proplist_to_string_sep(e->proplist, "\n\t\t");
723 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
724 pa_xfree(t);
725 }
726 }
727
728 return pa_strbuf_tostring_free(s);
729 }
730
731 char *pa_full_status_string(pa_core *c) {
732 pa_strbuf *s;
733 int i;
734
735 s = pa_strbuf_new();
736
737 for (i = 0; i < 8; i++) {
738 char *t = NULL;
739
740 switch (i) {
741 case 0:
742 t = pa_sink_list_to_string(c);
743 break;
744 case 1:
745 t = pa_source_list_to_string(c);
746 break;
747 case 2:
748 t = pa_sink_input_list_to_string(c);
749 break;
750 case 3:
751 t = pa_source_output_list_to_string(c);
752 break;
753 case 4:
754 t = pa_client_list_to_string(c);
755 break;
756 case 5:
757 t = pa_card_list_to_string(c);
758 break;
759 case 6:
760 t = pa_module_list_to_string(c);
761 break;
762 case 7:
763 t = pa_scache_list_to_string(c);
764 break;
765 }
766
767 pa_strbuf_puts(s, t);
768 pa_xfree(t);
769 }
770
771 return pa_strbuf_tostring_free(s);
772 }