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