Add a missing pa_xfree.
[pulseaudio.git] / src / pulsecore / cli-text.c
blobb64cafe264762e599854b33f8bc77e6a8bf02349
1 /* $Id$ */
3 /***
4 This file is part of PulseAudio.
6 Copyright 2004-2006 Lennart Poettering
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 USA.
22 ***/
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
28 #include <string.h>
30 #include <pulse/volume.h>
31 #include <pulse/xmalloc.h>
33 #include <pulsecore/module.h>
34 #include <pulsecore/client.h>
35 #include <pulsecore/sink.h>
36 #include <pulsecore/source.h>
37 #include <pulsecore/sink-input.h>
38 #include <pulsecore/source-output.h>
39 #include <pulsecore/strbuf.h>
40 #include <pulsecore/sample-util.h>
41 #include <pulsecore/core-scache.h>
42 #include <pulsecore/autoload.h>
43 #include <pulsecore/macro.h>
45 #include "cli-text.h"
47 char *pa_module_list_to_string(pa_core *c) {
48 pa_strbuf *s;
49 pa_module *m;
50 uint32_t idx = PA_IDXSET_INVALID;
51 pa_assert(c);
53 s = pa_strbuf_new();
55 pa_strbuf_printf(s, "%u module(s) loaded.\n", pa_idxset_size(c->modules));
57 for (m = pa_idxset_first(c->modules, &idx); m; m = pa_idxset_next(c->modules, &idx)) {
58 pa_strbuf_printf(s, " index: %u\n"
59 "\tname: <%s>\n"
60 "\targument: <%s>\n"
61 "\tused: %i\n"
62 "\tauto unload: %s\n",
63 m->index, m->name, m->argument ? m->argument : "", m->n_used,
64 m->auto_unload ? "yes" : "no");
67 return pa_strbuf_tostring_free(s);
70 char *pa_client_list_to_string(pa_core *c) {
71 pa_strbuf *s;
72 pa_client *client;
73 uint32_t idx = PA_IDXSET_INVALID;
74 pa_assert(c);
76 s = pa_strbuf_new();
78 pa_strbuf_printf(s, "%u client(s) logged in.\n", pa_idxset_size(c->clients));
80 for (client = pa_idxset_first(c->clients, &idx); client; client = pa_idxset_next(c->clients, &idx)) {
81 pa_strbuf_printf(s, " index: %u\n\tname: <%s>\n\tdriver: <%s>\n", client->index, client->name, client->driver);
83 if (client->owner)
84 pa_strbuf_printf(s, "\towner module: <%u>\n", client->owner->index);
87 return pa_strbuf_tostring_free(s);
90 char *pa_sink_list_to_string(pa_core *c) {
91 pa_strbuf *s;
92 pa_sink *sink;
93 uint32_t idx = PA_IDXSET_INVALID;
94 static const char* const state_table[] = {
95 [PA_SINK_RUNNING] = "RUNNING",
96 [PA_SINK_SUSPENDED] = "SUSPENDED",
97 [PA_SINK_IDLE] = "IDLE",
98 [PA_SINK_UNLINKED] = "UNLINKED"
100 pa_assert(c);
102 s = pa_strbuf_new();
104 pa_strbuf_printf(s, "%u sink(s) available.\n", pa_idxset_size(c->sinks));
106 for (sink = pa_idxset_first(c->sinks, &idx); sink; sink = pa_idxset_next(c->sinks, &idx)) {
107 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
109 pa_strbuf_printf(
111 " %c index: %u\n"
112 "\tname: <%s>\n"
113 "\tdriver: <%s>\n"
114 "\tflags: %s%s%s%s\n"
115 "\tstate: %s\n"
116 "\tvolume: <%s>\n"
117 "\tmute: <%i>\n"
118 "\tlatency: <%0.0f usec>\n"
119 "\tmonitor source: <%u>\n"
120 "\tsample spec: <%s>\n"
121 "\tchannel map: <%s>\n"
122 "\tused by: <%u>\n"
123 "\tlinked by: <%u>\n",
124 c->default_sink_name && !strcmp(sink->name, c->default_sink_name) ? '*' : ' ',
125 sink->index,
126 sink->name,
127 sink->driver,
128 sink->flags & PA_SINK_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
129 sink->flags & PA_SINK_LATENCY ? "LATENCY " : "",
130 sink->flags & PA_SINK_HARDWARE ? "HARDWARE " : "",
131 sink->flags & PA_SINK_NETWORK ? "NETWORK " : "",
132 state_table[pa_sink_get_state(sink)],
133 pa_cvolume_snprint(cv, sizeof(cv), pa_sink_get_volume(sink)),
134 !!pa_sink_get_mute(sink),
135 (double) pa_sink_get_latency(sink),
136 sink->monitor_source ? sink->monitor_source->index : PA_INVALID_INDEX,
137 pa_sample_spec_snprint(ss, sizeof(ss), &sink->sample_spec),
138 pa_channel_map_snprint(cm, sizeof(cm), &sink->channel_map),
139 pa_sink_used_by(sink),
140 pa_sink_linked_by(sink));
142 if (sink->module)
143 pa_strbuf_printf(s, "\tmodule: <%u>\n", sink->module->index);
144 if (sink->description)
145 pa_strbuf_printf(s, "\tdescription: <%s>\n", sink->description);
148 return pa_strbuf_tostring_free(s);
151 char *pa_source_list_to_string(pa_core *c) {
152 pa_strbuf *s;
153 pa_source *source;
154 uint32_t idx = PA_IDXSET_INVALID;
155 static const char* const state_table[] = {
156 [PA_SOURCE_RUNNING] = "RUNNING",
157 [PA_SOURCE_SUSPENDED] = "SUSPENDED",
158 [PA_SOURCE_IDLE] = "IDLE",
159 [PA_SOURCE_UNLINKED] = "UNLINKED"
161 pa_assert(c);
163 s = pa_strbuf_new();
165 pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_size(c->sources));
167 for (source = pa_idxset_first(c->sources, &idx); source; source = pa_idxset_next(c->sources, &idx)) {
168 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX];
171 pa_strbuf_printf(
173 " %c index: %u\n"
174 "\tname: <%s>\n"
175 "\tdriver: <%s>\n"
176 "\tflags: %s%s%s%s\n"
177 "\tstate: %s\n"
178 "\tvolume: <%s>\n"
179 "\tmute: <%u>\n"
180 "\tlatency: <%0.0f usec>\n"
181 "\tsample spec: <%s>\n"
182 "\tchannel map: <%s>\n"
183 "\tused by: <%u>\n"
184 "\tlinked by: <%u>\n",
185 c->default_source_name && !strcmp(source->name, c->default_source_name) ? '*' : ' ',
186 source->index,
187 source->name,
188 source->driver,
189 source->flags & PA_SOURCE_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
190 source->flags & PA_SOURCE_LATENCY ? "LATENCY " : "",
191 source->flags & PA_SOURCE_HARDWARE ? "HARDWARE " : "",
192 source->flags & PA_SOURCE_NETWORK ? "NETWORK " : "",
193 state_table[pa_source_get_state(source)],
194 pa_cvolume_snprint(cv, sizeof(cv), pa_source_get_volume(source)),
195 !!pa_source_get_mute(source),
196 (double) pa_source_get_latency(source),
197 pa_sample_spec_snprint(ss, sizeof(ss), &source->sample_spec),
198 pa_channel_map_snprint(cm, sizeof(cm), &source->channel_map),
199 pa_source_used_by(source),
200 pa_source_linked_by(source));
202 if (source->monitor_of)
203 pa_strbuf_printf(s, "\tmonitor_of: <%u>\n", source->monitor_of->index);
204 if (source->module)
205 pa_strbuf_printf(s, "\tmodule: <%u>\n", source->module->index);
206 if (source->description)
207 pa_strbuf_printf(s, "\tdescription: <%s>\n", source->description);
210 return pa_strbuf_tostring_free(s);
214 char *pa_source_output_list_to_string(pa_core *c) {
215 pa_strbuf *s;
216 pa_source_output *o;
217 uint32_t idx = PA_IDXSET_INVALID;
218 static const char* const state_table[] = {
219 [PA_SOURCE_OUTPUT_RUNNING] = "RUNNING",
220 [PA_SOURCE_OUTPUT_CORKED] = "CORKED",
221 [PA_SOURCE_OUTPUT_UNLINKED] = "UNLINKED"
223 pa_assert(c);
225 s = pa_strbuf_new();
227 pa_strbuf_printf(s, "%u source outputs(s) available.\n", pa_idxset_size(c->source_outputs));
229 for (o = pa_idxset_first(c->source_outputs, &idx); o; o = pa_idxset_next(c->source_outputs, &idx)) {
230 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
232 pa_assert(o->source);
234 pa_strbuf_printf(
236 " index: %u\n"
237 "\tname: '%s'\n"
238 "\tdriver: <%s>\n"
239 "\tflags: %s%s%s%s%s%s%s\n"
240 "\tstate: %s\n"
241 "\tsource: <%u> '%s'\n"
242 "\tlatency: <%0.0f usec>\n"
243 "\tsample spec: <%s>\n"
244 "\tchannel map: <%s>\n"
245 "\tresample method: %s\n",
246 o->index,
247 o->name,
248 o->driver,
249 o->flags & PA_SOURCE_OUTPUT_VARIABLE_RATE ? "VARIABLE_RATE " : "",
250 o->flags & PA_SOURCE_OUTPUT_DONT_MOVE ? "DONT_MOVE " : "",
251 o->flags & PA_SOURCE_OUTPUT_NO_REMAP ? "NO_REMAP " : "",
252 o->flags & PA_SOURCE_OUTPUT_NO_REMIX ? "NO_REMIX " : "",
253 o->flags & PA_SOURCE_OUTPUT_FIX_FORMAT ? "FIX_FORMAT " : "",
254 o->flags & PA_SOURCE_OUTPUT_FIX_RATE ? "FIX_RATE " : "",
255 o->flags & PA_SOURCE_OUTPUT_FIX_CHANNELS ? "FIX_CHANNELS " : "",
256 state_table[pa_source_output_get_state(o)],
257 o->source->index, o->source->name,
258 (double) pa_source_output_get_latency(o),
259 pa_sample_spec_snprint(ss, sizeof(ss), &o->sample_spec),
260 pa_channel_map_snprint(cm, sizeof(cm), &o->channel_map),
261 pa_resample_method_to_string(pa_source_output_get_resample_method(o)));
262 if (o->module)
263 pa_strbuf_printf(s, "\towner module: <%u>\n", o->module->index);
264 if (o->client)
265 pa_strbuf_printf(s, "\tclient: <%u> '%s'\n", o->client->index, o->client->name);
268 return pa_strbuf_tostring_free(s);
271 char *pa_sink_input_list_to_string(pa_core *c) {
272 pa_strbuf *s;
273 pa_sink_input *i;
274 uint32_t idx = PA_IDXSET_INVALID;
275 static const char* const state_table[] = {
276 [PA_SINK_INPUT_RUNNING] = "RUNNING",
277 [PA_SINK_INPUT_DRAINED] = "DRAINED",
278 [PA_SINK_INPUT_CORKED] = "CORKED",
279 [PA_SINK_INPUT_UNLINKED] = "UNLINKED"
282 pa_assert(c);
283 s = pa_strbuf_new();
285 pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_size(c->sink_inputs));
287 for (i = pa_idxset_first(c->sink_inputs, &idx); i; i = pa_idxset_next(c->sink_inputs, &idx)) {
288 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
290 pa_assert(i->sink);
292 pa_strbuf_printf(
294 " index: %u\n"
295 "\tname: <%s>\n"
296 "\tdriver: <%s>\n"
297 "\tflags: %s%s%s%s%s%s%s\n"
298 "\tstate: %s\n"
299 "\tsink: <%u> '%s'\n"
300 "\tvolume: <%s>\n"
301 "\tmute: <%i>\n"
302 "\tlatency: <%0.0f usec>\n"
303 "\tsample spec: <%s>\n"
304 "\tchannel map: <%s>\n"
305 "\tresample method: %s\n",
306 i->index,
307 i->name,
308 i->driver,
309 i->flags & PA_SINK_INPUT_VARIABLE_RATE ? "VARIABLE_RATE " : "",
310 i->flags & PA_SINK_INPUT_DONT_MOVE ? "DONT_MOVE " : "",
311 i->flags & PA_SINK_INPUT_NO_REMAP ? "NO_REMAP " : "",
312 i->flags & PA_SINK_INPUT_NO_REMIX ? "NO_REMIX " : "",
313 i->flags & PA_SINK_INPUT_FIX_FORMAT ? "FIX_FORMAT " : "",
314 i->flags & PA_SINK_INPUT_FIX_RATE ? "FIX_RATE " : "",
315 i->flags & PA_SINK_INPUT_FIX_CHANNELS ? "FIX_CHANNELS " : "",
316 state_table[pa_sink_input_get_state(i)],
317 i->sink->index, i->sink->name,
318 pa_cvolume_snprint(cv, sizeof(cv), pa_sink_input_get_volume(i)),
319 !!pa_sink_input_get_mute(i),
320 (double) pa_sink_input_get_latency(i),
321 pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec),
322 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
323 pa_resample_method_to_string(pa_sink_input_get_resample_method(i)));
325 if (i->module)
326 pa_strbuf_printf(s, "\tmodule: <%u>\n", i->module->index);
327 if (i->client)
328 pa_strbuf_printf(s, "\tclient: <%u> '%s'\n", i->client->index, i->client->name);
331 return pa_strbuf_tostring_free(s);
334 char *pa_scache_list_to_string(pa_core *c) {
335 pa_strbuf *s;
336 pa_assert(c);
338 s = pa_strbuf_new();
340 pa_strbuf_printf(s, "%u cache entries available.\n", c->scache ? pa_idxset_size(c->scache) : 0);
342 if (c->scache) {
343 pa_scache_entry *e;
344 uint32_t idx = PA_IDXSET_INVALID;
346 for (e = pa_idxset_first(c->scache, &idx); e; e = pa_idxset_next(c->scache, &idx)) {
347 double l = 0;
348 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX] = "n/a", cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX] = "n/a";
350 if (e->memchunk.memblock) {
351 pa_sample_spec_snprint(ss, sizeof(ss), &e->sample_spec);
352 pa_channel_map_snprint(cm, sizeof(cm), &e->channel_map);
353 l = (double) e->memchunk.length / pa_bytes_per_second(&e->sample_spec);
356 pa_strbuf_printf(
358 " name: <%s>\n"
359 "\tindex: <%u>\n"
360 "\tsample spec: <%s>\n"
361 "\tchannel map: <%s>\n"
362 "\tlength: <%lu>\n"
363 "\tduration: <%0.1fs>\n"
364 "\tvolume: <%s>\n"
365 "\tlazy: %s\n"
366 "\tfilename: %s\n",
367 e->name,
368 e->index,
371 (long unsigned)(e->memchunk.memblock ? e->memchunk.length : 0),
373 pa_cvolume_snprint(cv, sizeof(cv), &e->volume),
374 e->lazy ? "yes" : "no",
375 e->filename ? e->filename : "n/a");
379 return pa_strbuf_tostring_free(s);
382 char *pa_autoload_list_to_string(pa_core *c) {
383 pa_strbuf *s;
384 pa_assert(c);
386 s = pa_strbuf_new();
388 pa_strbuf_printf(s, "%u autoload entries available.\n", c->autoload_hashmap ? pa_hashmap_size(c->autoload_hashmap) : 0);
390 if (c->autoload_hashmap) {
391 pa_autoload_entry *e;
392 void *state = NULL;
394 while ((e = pa_hashmap_iterate(c->autoload_hashmap, &state, NULL))) {
395 pa_strbuf_printf(
396 s, " name: <%s>\n\ttype: <%s>\n\tindex: <%u>\n\tmodule_name: <%s>\n\targuments: <%s>\n",
397 e->name,
398 e->type == PA_NAMEREG_SOURCE ? "source" : "sink",
399 e->index,
400 e->module,
401 e->argument ? e->argument : "");
406 return pa_strbuf_tostring_free(s);
409 char *pa_full_status_string(pa_core *c) {
410 pa_strbuf *s;
411 int i;
413 s = pa_strbuf_new();
415 for (i = 0; i < 8; i++) {
416 char *t = NULL;
418 switch (i) {
419 case 0:
420 t = pa_sink_list_to_string(c);
421 break;
422 case 1:
423 t = pa_source_list_to_string(c);
424 break;
425 case 2:
426 t = pa_sink_input_list_to_string(c);
427 break;
428 case 3:
429 t = pa_source_output_list_to_string(c);
430 break;
431 case 4:
432 t = pa_client_list_to_string(c);
433 break;
434 case 5:
435 t = pa_module_list_to_string(c);
436 break;
437 case 6:
438 t = pa_scache_list_to_string(c);
439 break;
440 case 7:
441 t = pa_autoload_list_to_string(c);
442 break;
445 pa_strbuf_puts(s, t);
446 pa_xfree(t);
449 return pa_strbuf_tostring_free(s);