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