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