]> code.delx.au - pulseaudio/blob - src/pulsecore/cli-text.c
c7db0a6a0e8b104a4271da9e64bc72b17ce2cbe2
[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_VERBOSE_MAX],
250 v[PA_VOLUME_SNPRINT_VERBOSE_MAX],
251 cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t;
252 const char *cmn;
253
254 cmn = pa_channel_map_to_pretty_name(&sink->channel_map);
255
256 pa_strbuf_printf(
257 s,
258 " %c index: %u\n"
259 "\tname: <%s>\n"
260 "\tdriver: <%s>\n"
261 "\tflags: %s%s%s%s%s%s%s%s\n"
262 "\tstate: %s\n"
263 "\tsuspend cause: %s%s%s%s\n"
264 "\tpriority: %u\n"
265 "\tvolume: %s\n"
266 "\t balance %0.2f\n"
267 "\tbase volume: %s\n"
268 "\tvolume steps: %u\n"
269 "\tmuted: %s\n"
270 "\tcurrent latency: %0.2f ms\n"
271 "\tmax request: %lu KiB\n"
272 "\tmax rewind: %lu KiB\n"
273 "\tmonitor source: %u\n"
274 "\tsample spec: %s\n"
275 "\tchannel map: %s%s%s\n"
276 "\tused by: %u\n"
277 "\tlinked by: %u\n",
278 sink == default_sink ? '*' : ' ',
279 sink->index,
280 sink->name,
281 sink->driver,
282 sink->flags & PA_SINK_HARDWARE ? "HARDWARE " : "",
283 sink->flags & PA_SINK_NETWORK ? "NETWORK " : "",
284 sink->flags & PA_SINK_HW_MUTE_CTRL ? "HW_MUTE_CTRL " : "",
285 sink->flags & PA_SINK_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
286 sink->flags & PA_SINK_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
287 sink->flags & PA_SINK_LATENCY ? "LATENCY " : "",
288 sink->flags & PA_SINK_FLAT_VOLUME ? "FLAT_VOLUME " : "",
289 sink->flags & PA_SINK_DYNAMIC_LATENCY ? "DYNAMIC_LATENCY" : "",
290 sink_state_to_string(pa_sink_get_state(sink)),
291 sink->suspend_cause & PA_SUSPEND_USER ? "USER " : "",
292 sink->suspend_cause & PA_SUSPEND_APPLICATION ? "APPLICATION " : "",
293 sink->suspend_cause & PA_SUSPEND_IDLE ? "IDLE " : "",
294 sink->suspend_cause & PA_SUSPEND_SESSION ? "SESSION" : "",
295 sink->priority,
296 pa_cvolume_snprint_verbose(cv,
297 sizeof(cv),
298 pa_sink_get_volume(sink, false),
299 &sink->channel_map,
300 sink->flags & PA_SINK_DECIBEL_VOLUME),
301 pa_cvolume_get_balance(pa_sink_get_volume(sink, false), &sink->channel_map),
302 pa_volume_snprint_verbose(v, sizeof(v), sink->base_volume, sink->flags & PA_SINK_DECIBEL_VOLUME),
303 sink->n_volume_steps,
304 pa_yes_no(pa_sink_get_mute(sink, false)),
305 (double) pa_sink_get_latency(sink) / (double) PA_USEC_PER_MSEC,
306 (unsigned long) pa_sink_get_max_request(sink) / 1024,
307 (unsigned long) pa_sink_get_max_rewind(sink) / 1024,
308 sink->monitor_source ? sink->monitor_source->index : PA_INVALID_INDEX,
309 pa_sample_spec_snprint(ss, sizeof(ss), &sink->sample_spec),
310 pa_channel_map_snprint(cm, sizeof(cm), &sink->channel_map),
311 cmn ? "\n\t " : "",
312 cmn ? cmn : "",
313 pa_sink_used_by(sink),
314 pa_sink_linked_by(sink));
315
316 if (sink->flags & PA_SINK_DYNAMIC_LATENCY) {
317 pa_usec_t min_latency, max_latency;
318 pa_sink_get_latency_range(sink, &min_latency, &max_latency);
319
320 pa_strbuf_printf(
321 s,
322 "\tconfigured latency: %0.2f ms; range is %0.2f .. %0.2f ms\n",
323 (double) pa_sink_get_requested_latency(sink) / (double) PA_USEC_PER_MSEC,
324 (double) min_latency / PA_USEC_PER_MSEC,
325 (double) max_latency / PA_USEC_PER_MSEC);
326 } else
327 pa_strbuf_printf(
328 s,
329 "\tfixed latency: %0.2f ms\n",
330 (double) pa_sink_get_fixed_latency(sink) / PA_USEC_PER_MSEC);
331
332 if (sink->card)
333 pa_strbuf_printf(s, "\tcard: %u <%s>\n", sink->card->index, sink->card->name);
334 if (sink->module)
335 pa_strbuf_printf(s, "\tmodule: %u\n", sink->module->index);
336
337 t = pa_proplist_to_string_sep(sink->proplist, "\n\t\t");
338 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
339 pa_xfree(t);
340
341 append_port_list(s, sink->ports);
342
343 if (sink->active_port)
344 pa_strbuf_printf(
345 s,
346 "\tactive port: <%s>\n",
347 sink->active_port->name);
348 }
349
350 return pa_strbuf_tostring_free(s);
351 }
352
353 char *pa_source_list_to_string(pa_core *c) {
354 pa_strbuf *s;
355 pa_source *source, *default_source;
356 uint32_t idx = PA_IDXSET_INVALID;
357 pa_assert(c);
358
359 s = pa_strbuf_new();
360
361 pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_size(c->sources));
362
363 default_source = pa_namereg_get_default_source(c);
364
365 PA_IDXSET_FOREACH(source, c->sources, idx) {
366 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX],
367 cv[PA_CVOLUME_SNPRINT_VERBOSE_MAX],
368 v[PA_VOLUME_SNPRINT_VERBOSE_MAX],
369 cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t;
370 const char *cmn;
371
372 cmn = pa_channel_map_to_pretty_name(&source->channel_map);
373
374 pa_strbuf_printf(
375 s,
376 " %c index: %u\n"
377 "\tname: <%s>\n"
378 "\tdriver: <%s>\n"
379 "\tflags: %s%s%s%s%s%s%s\n"
380 "\tstate: %s\n"
381 "\tsuspend cause: %s%s%s%s\n"
382 "\tpriority: %u\n"
383 "\tvolume: %s\n"
384 "\t balance %0.2f\n"
385 "\tbase volume: %s\n"
386 "\tvolume steps: %u\n"
387 "\tmuted: %s\n"
388 "\tcurrent latency: %0.2f ms\n"
389 "\tmax rewind: %lu KiB\n"
390 "\tsample spec: %s\n"
391 "\tchannel map: %s%s%s\n"
392 "\tused by: %u\n"
393 "\tlinked by: %u\n",
394 source == default_source ? '*' : ' ',
395 source->index,
396 source->name,
397 source->driver,
398 source->flags & PA_SOURCE_HARDWARE ? "HARDWARE " : "",
399 source->flags & PA_SOURCE_NETWORK ? "NETWORK " : "",
400 source->flags & PA_SOURCE_HW_MUTE_CTRL ? "HW_MUTE_CTRL " : "",
401 source->flags & PA_SOURCE_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
402 source->flags & PA_SOURCE_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
403 source->flags & PA_SOURCE_LATENCY ? "LATENCY " : "",
404 source->flags & PA_SOURCE_DYNAMIC_LATENCY ? "DYNAMIC_LATENCY" : "",
405 source_state_to_string(pa_source_get_state(source)),
406 source->suspend_cause & PA_SUSPEND_USER ? "USER " : "",
407 source->suspend_cause & PA_SUSPEND_APPLICATION ? "APPLICATION " : "",
408 source->suspend_cause & PA_SUSPEND_IDLE ? "IDLE " : "",
409 source->suspend_cause & PA_SUSPEND_SESSION ? "SESSION" : "",
410 source->priority,
411 pa_cvolume_snprint_verbose(cv,
412 sizeof(cv),
413 pa_source_get_volume(source, false),
414 &source->channel_map,
415 source->flags & PA_SOURCE_DECIBEL_VOLUME),
416 pa_cvolume_get_balance(pa_source_get_volume(source, false), &source->channel_map),
417 pa_volume_snprint_verbose(v, sizeof(v), source->base_volume, source->flags & PA_SOURCE_DECIBEL_VOLUME),
418 source->n_volume_steps,
419 pa_yes_no(pa_source_get_mute(source, false)),
420 (double) pa_source_get_latency(source) / PA_USEC_PER_MSEC,
421 (unsigned long) pa_source_get_max_rewind(source) / 1024,
422 pa_sample_spec_snprint(ss, sizeof(ss), &source->sample_spec),
423 pa_channel_map_snprint(cm, sizeof(cm), &source->channel_map),
424 cmn ? "\n\t " : "",
425 cmn ? cmn : "",
426 pa_source_used_by(source),
427 pa_source_linked_by(source));
428
429 if (source->flags & PA_SOURCE_DYNAMIC_LATENCY) {
430 pa_usec_t min_latency, max_latency;
431 pa_source_get_latency_range(source, &min_latency, &max_latency);
432
433 pa_strbuf_printf(
434 s,
435 "\tconfigured latency: %0.2f ms; range is %0.2f .. %0.2f ms\n",
436 (double) pa_source_get_requested_latency(source) / PA_USEC_PER_MSEC,
437 (double) min_latency / PA_USEC_PER_MSEC,
438 (double) max_latency / PA_USEC_PER_MSEC);
439 } else
440 pa_strbuf_printf(
441 s,
442 "\tfixed latency: %0.2f ms\n",
443 (double) pa_source_get_fixed_latency(source) / PA_USEC_PER_MSEC);
444
445 if (source->monitor_of)
446 pa_strbuf_printf(s, "\tmonitor_of: %u\n", source->monitor_of->index);
447 if (source->card)
448 pa_strbuf_printf(s, "\tcard: %u <%s>\n", source->card->index, source->card->name);
449 if (source->module)
450 pa_strbuf_printf(s, "\tmodule: %u\n", source->module->index);
451
452 t = pa_proplist_to_string_sep(source->proplist, "\n\t\t");
453 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
454 pa_xfree(t);
455
456 append_port_list(s, source->ports);
457
458 if (source->active_port)
459 pa_strbuf_printf(
460 s,
461 "\tactive port: <%s>\n",
462 source->active_port->name);
463 }
464
465 return pa_strbuf_tostring_free(s);
466 }
467
468 char *pa_source_output_list_to_string(pa_core *c) {
469 pa_strbuf *s;
470 pa_source_output *o;
471 uint32_t idx = PA_IDXSET_INVALID;
472 static const char* const state_table[] = {
473 [PA_SOURCE_OUTPUT_INIT] = "INIT",
474 [PA_SOURCE_OUTPUT_RUNNING] = "RUNNING",
475 [PA_SOURCE_OUTPUT_CORKED] = "CORKED",
476 [PA_SOURCE_OUTPUT_UNLINKED] = "UNLINKED"
477 };
478 pa_assert(c);
479
480 s = pa_strbuf_new();
481
482 pa_strbuf_printf(s, "%u source output(s) available.\n", pa_idxset_size(c->source_outputs));
483
484 PA_IDXSET_FOREACH(o, c->source_outputs, idx) {
485 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_VERBOSE_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t, clt[28];
486 pa_usec_t cl;
487 const char *cmn;
488 pa_cvolume v;
489 char *volume_str = NULL;
490
491 cmn = pa_channel_map_to_pretty_name(&o->channel_map);
492
493 if ((cl = pa_source_output_get_requested_latency(o)) == (pa_usec_t) -1)
494 pa_snprintf(clt, sizeof(clt), "n/a");
495 else
496 pa_snprintf(clt, sizeof(clt), "%0.2f ms", (double) cl / PA_USEC_PER_MSEC);
497
498 pa_assert(o->source);
499
500 if (pa_source_output_is_volume_readable(o)) {
501 pa_source_output_get_volume(o, &v, true);
502 volume_str = pa_sprintf_malloc("%s\n\t balance %0.2f",
503 pa_cvolume_snprint_verbose(cv, sizeof(cv), &v, &o->channel_map, true),
504 pa_cvolume_get_balance(&v, &o->channel_map));
505 } else
506 volume_str = pa_xstrdup("n/a");
507
508 pa_strbuf_printf(
509 s,
510 " index: %u\n"
511 "\tdriver: <%s>\n"
512 "\tflags: %s%s%s%s%s%s%s%s%s%s%s%s\n"
513 "\tstate: %s\n"
514 "\tsource: %u <%s>\n"
515 "\tvolume: %s\n"
516 "\tmuted: %s\n"
517 "\tcurrent latency: %0.2f ms\n"
518 "\trequested latency: %s\n"
519 "\tsample spec: %s\n"
520 "\tchannel map: %s%s%s\n"
521 "\tresample method: %s\n",
522 o->index,
523 o->driver,
524 o->flags & PA_SOURCE_OUTPUT_VARIABLE_RATE ? "VARIABLE_RATE " : "",
525 o->flags & PA_SOURCE_OUTPUT_DONT_MOVE ? "DONT_MOVE " : "",
526 o->flags & PA_SOURCE_OUTPUT_START_CORKED ? "START_CORKED " : "",
527 o->flags & PA_SOURCE_OUTPUT_NO_REMAP ? "NO_REMAP " : "",
528 o->flags & PA_SOURCE_OUTPUT_NO_REMIX ? "NO_REMIX " : "",
529 o->flags & PA_SOURCE_OUTPUT_FIX_FORMAT ? "FIX_FORMAT " : "",
530 o->flags & PA_SOURCE_OUTPUT_FIX_RATE ? "FIX_RATE " : "",
531 o->flags & PA_SOURCE_OUTPUT_FIX_CHANNELS ? "FIX_CHANNELS " : "",
532 o->flags & PA_SOURCE_OUTPUT_DONT_INHIBIT_AUTO_SUSPEND ? "DONT_INHIBIT_AUTO_SUSPEND " : "",
533 o->flags & PA_SOURCE_OUTPUT_NO_CREATE_ON_SUSPEND ? "NO_CREATE_ON_SUSPEND " : "",
534 o->flags & PA_SOURCE_OUTPUT_KILL_ON_SUSPEND ? "KILL_ON_SUSPEND " : "",
535 o->flags & PA_SOURCE_OUTPUT_PASSTHROUGH ? "PASSTHROUGH " : "",
536 state_table[pa_source_output_get_state(o)],
537 o->source->index, o->source->name,
538 volume_str,
539 pa_yes_no(pa_source_output_get_mute(o)),
540 (double) pa_source_output_get_latency(o, NULL) / PA_USEC_PER_MSEC,
541 clt,
542 pa_sample_spec_snprint(ss, sizeof(ss), &o->sample_spec),
543 pa_channel_map_snprint(cm, sizeof(cm), &o->channel_map),
544 cmn ? "\n\t " : "",
545 cmn ? cmn : "",
546 pa_resample_method_to_string(pa_source_output_get_resample_method(o)));
547
548 pa_xfree(volume_str);
549
550 if (o->module)
551 pa_strbuf_printf(s, "\towner module: %u\n", o->module->index);
552 if (o->client)
553 pa_strbuf_printf(s, "\tclient: %u <%s>\n", o->client->index, pa_strnull(pa_proplist_gets(o->client->proplist, PA_PROP_APPLICATION_NAME)));
554 if (o->direct_on_input)
555 pa_strbuf_printf(s, "\tdirect on input: %u\n", o->direct_on_input->index);
556
557 t = pa_proplist_to_string_sep(o->proplist, "\n\t\t");
558 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
559 pa_xfree(t);
560 }
561
562 return pa_strbuf_tostring_free(s);
563 }
564
565 char *pa_sink_input_list_to_string(pa_core *c) {
566 pa_strbuf *s;
567 pa_sink_input *i;
568 uint32_t idx = PA_IDXSET_INVALID;
569 static const char* const state_table[] = {
570 [PA_SINK_INPUT_INIT] = "INIT",
571 [PA_SINK_INPUT_RUNNING] = "RUNNING",
572 [PA_SINK_INPUT_DRAINED] = "DRAINED",
573 [PA_SINK_INPUT_CORKED] = "CORKED",
574 [PA_SINK_INPUT_UNLINKED] = "UNLINKED"
575 };
576
577 pa_assert(c);
578 s = pa_strbuf_new();
579
580 pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_size(c->sink_inputs));
581
582 PA_IDXSET_FOREACH(i, c->sink_inputs, idx) {
583 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t, clt[28];
584 pa_usec_t cl;
585 const char *cmn;
586 pa_cvolume v;
587 char *volume_str = NULL;
588
589 cmn = pa_channel_map_to_pretty_name(&i->channel_map);
590
591 if ((cl = pa_sink_input_get_requested_latency(i)) == (pa_usec_t) -1)
592 pa_snprintf(clt, sizeof(clt), "n/a");
593 else
594 pa_snprintf(clt, sizeof(clt), "%0.2f ms", (double) cl / PA_USEC_PER_MSEC);
595
596 pa_assert(i->sink);
597
598 if (pa_sink_input_is_volume_readable(i)) {
599 pa_sink_input_get_volume(i, &v, true);
600 volume_str = pa_sprintf_malloc("%s\n\t balance %0.2f",
601 pa_cvolume_snprint_verbose(cv, sizeof(cv), &v, &i->channel_map, true),
602 pa_cvolume_get_balance(&v, &i->channel_map));
603 } else
604 volume_str = pa_xstrdup("n/a");
605
606 pa_strbuf_printf(
607 s,
608 " index: %u\n"
609 "\tdriver: <%s>\n"
610 "\tflags: %s%s%s%s%s%s%s%s%s%s%s%s\n"
611 "\tstate: %s\n"
612 "\tsink: %u <%s>\n"
613 "\tvolume: %s\n"
614 "\tmuted: %s\n"
615 "\tcurrent latency: %0.2f ms\n"
616 "\trequested latency: %s\n"
617 "\tsample spec: %s\n"
618 "\tchannel map: %s%s%s\n"
619 "\tresample method: %s\n",
620 i->index,
621 i->driver,
622 i->flags & PA_SINK_INPUT_VARIABLE_RATE ? "VARIABLE_RATE " : "",
623 i->flags & PA_SINK_INPUT_DONT_MOVE ? "DONT_MOVE " : "",
624 i->flags & PA_SINK_INPUT_START_CORKED ? "START_CORKED " : "",
625 i->flags & PA_SINK_INPUT_NO_REMAP ? "NO_REMAP " : "",
626 i->flags & PA_SINK_INPUT_NO_REMIX ? "NO_REMIX " : "",
627 i->flags & PA_SINK_INPUT_FIX_FORMAT ? "FIX_FORMAT " : "",
628 i->flags & PA_SINK_INPUT_FIX_RATE ? "FIX_RATE " : "",
629 i->flags & PA_SINK_INPUT_FIX_CHANNELS ? "FIX_CHANNELS " : "",
630 i->flags & PA_SINK_INPUT_DONT_INHIBIT_AUTO_SUSPEND ? "DONT_INHIBIT_AUTO_SUSPEND " : "",
631 i->flags & PA_SINK_INPUT_NO_CREATE_ON_SUSPEND ? "NO_CREATE_SUSPEND " : "",
632 i->flags & PA_SINK_INPUT_KILL_ON_SUSPEND ? "KILL_ON_SUSPEND " : "",
633 i->flags & PA_SINK_INPUT_PASSTHROUGH ? "PASSTHROUGH " : "",
634 state_table[pa_sink_input_get_state(i)],
635 i->sink->index, i->sink->name,
636 volume_str,
637 pa_yes_no(pa_sink_input_get_mute(i)),
638 (double) pa_sink_input_get_latency(i, NULL) / PA_USEC_PER_MSEC,
639 clt,
640 pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec),
641 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
642 cmn ? "\n\t " : "",
643 cmn ? cmn : "",
644 pa_resample_method_to_string(pa_sink_input_get_resample_method(i)));
645
646 pa_xfree(volume_str);
647
648 if (i->module)
649 pa_strbuf_printf(s, "\tmodule: %u\n", i->module->index);
650 if (i->client)
651 pa_strbuf_printf(s, "\tclient: %u <%s>\n", i->client->index, pa_strnull(pa_proplist_gets(i->client->proplist, PA_PROP_APPLICATION_NAME)));
652
653 t = pa_proplist_to_string_sep(i->proplist, "\n\t\t");
654 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
655 pa_xfree(t);
656 }
657
658 return pa_strbuf_tostring_free(s);
659 }
660
661 char *pa_scache_list_to_string(pa_core *c) {
662 pa_strbuf *s;
663 pa_assert(c);
664
665 s = pa_strbuf_new();
666
667 pa_strbuf_printf(s, "%u cache entrie(s) available.\n", c->scache ? pa_idxset_size(c->scache) : 0);
668
669 if (c->scache) {
670 pa_scache_entry *e;
671 uint32_t idx = PA_IDXSET_INVALID;
672
673 PA_IDXSET_FOREACH(e, c->scache, idx) {
674 double l = 0;
675 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX] = "n/a", cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX] = "n/a", *t;
676 const char *cmn;
677
678 cmn = pa_channel_map_to_pretty_name(&e->channel_map);
679
680 if (e->memchunk.memblock) {
681 pa_sample_spec_snprint(ss, sizeof(ss), &e->sample_spec);
682 pa_channel_map_snprint(cm, sizeof(cm), &e->channel_map);
683 l = (double) e->memchunk.length / (double) pa_bytes_per_second(&e->sample_spec);
684 }
685
686 pa_strbuf_printf(
687 s,
688 " name: <%s>\n"
689 "\tindex: %u\n"
690 "\tsample spec: %s\n"
691 "\tchannel map: %s%s%s\n"
692 "\tlength: %lu\n"
693 "\tduration: %0.1f s\n"
694 "\tvolume: %s\n"
695 "\t balance %0.2f\n"
696 "\tlazy: %s\n"
697 "\tfilename: <%s>\n",
698 e->name,
699 e->index,
700 ss,
701 cm,
702 cmn ? "\n\t " : "",
703 cmn ? cmn : "",
704 (long unsigned)(e->memchunk.memblock ? e->memchunk.length : 0),
705 l,
706 e->volume_is_set ? pa_cvolume_snprint_verbose(cv, sizeof(cv), &e->volume, &e->channel_map, true) : "n/a",
707 (e->memchunk.memblock && e->volume_is_set) ? pa_cvolume_get_balance(&e->volume, &e->channel_map) : 0.0f,
708 pa_yes_no(e->lazy),
709 e->filename ? e->filename : "n/a");
710
711 t = pa_proplist_to_string_sep(e->proplist, "\n\t\t");
712 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
713 pa_xfree(t);
714 }
715 }
716
717 return pa_strbuf_tostring_free(s);
718 }
719
720 char *pa_full_status_string(pa_core *c) {
721 pa_strbuf *s;
722 int i;
723
724 s = pa_strbuf_new();
725
726 for (i = 0; i < 8; i++) {
727 char *t = NULL;
728
729 switch (i) {
730 case 0:
731 t = pa_sink_list_to_string(c);
732 break;
733 case 1:
734 t = pa_source_list_to_string(c);
735 break;
736 case 2:
737 t = pa_sink_input_list_to_string(c);
738 break;
739 case 3:
740 t = pa_source_output_list_to_string(c);
741 break;
742 case 4:
743 t = pa_client_list_to_string(c);
744 break;
745 case 5:
746 t = pa_card_list_to_string(c);
747 break;
748 case 6:
749 t = pa_module_list_to_string(c);
750 break;
751 case 7:
752 t = pa_scache_list_to_string(c);
753 break;
754 }
755
756 pa_strbuf_puts(s, t);
757 pa_xfree(t);
758 }
759
760 return pa_strbuf_tostring_free(s);
761 }