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