]> code.delx.au - pulseaudio/blob - src/pulsecore/cli-text.c
merge 'lennart' branch back into trunk.
[pulseaudio] / src / pulsecore / cli-text.c
1 /* $Id$ */
2
3 /***
4 This file is part of PulseAudio.
5
6 Copyright 2004-2006 Lennart Poettering
7
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.
12
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.
17
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 ***/
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <string.h>
29
30 #include <pulse/volume.h>
31 #include <pulse/xmalloc.h>
32
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>
44
45 #include "cli-text.h"
46
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);
52
53 s = pa_strbuf_new();
54
55 pa_strbuf_printf(s, "%u module(s) loaded.\n", pa_idxset_size(c->modules));
56
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");
65 }
66
67 return pa_strbuf_tostring_free(s);
68 }
69
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);
75
76 s = pa_strbuf_new();
77
78 pa_strbuf_printf(s, "%u client(s) logged in.\n", pa_idxset_size(c->clients));
79
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);
82
83 if (client->owner)
84 pa_strbuf_printf(s, "\towner module: <%u>\n", client->owner->index);
85 }
86
87 return pa_strbuf_tostring_free(s);
88 }
89
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"
99 };
100 pa_assert(c);
101
102 s = pa_strbuf_new();
103
104 pa_strbuf_printf(s, "%u sink(s) available.\n", pa_idxset_size(c->sinks));
105
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];
108
109 pa_strbuf_printf(
110 s,
111 " %c index: %u\n"
112 "\tname: <%s>\n"
113 "\tdriver: <%s>\n"
114 "\tflags: %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 state_table[pa_sink_get_state(sink)],
132 pa_cvolume_snprint(cv, sizeof(cv), pa_sink_get_volume(sink)),
133 !!pa_sink_get_mute(sink),
134 (double) pa_sink_get_latency(sink),
135 sink->monitor_source ? sink->monitor_source->index : PA_INVALID_INDEX,
136 pa_sample_spec_snprint(ss, sizeof(ss), &sink->sample_spec),
137 pa_channel_map_snprint(cm, sizeof(cm), &sink->channel_map),
138 pa_sink_used_by(sink),
139 pa_sink_linked_by(sink));
140
141 if (sink->module)
142 pa_strbuf_printf(s, "\tmodule: <%u>\n", sink->module->index);
143 if (sink->description)
144 pa_strbuf_printf(s, "\tdescription: <%s>\n", sink->description);
145 }
146
147 return pa_strbuf_tostring_free(s);
148 }
149
150 char *pa_source_list_to_string(pa_core *c) {
151 pa_strbuf *s;
152 pa_source *source;
153 uint32_t idx = PA_IDXSET_INVALID;
154 static const char* const state_table[] = {
155 [PA_SOURCE_RUNNING] = "RUNNING",
156 [PA_SOURCE_SUSPENDED] = "SUSPENDED",
157 [PA_SOURCE_IDLE] = "IDLE",
158 [PA_SOURCE_UNLINKED] = "UNLINKED"
159 };
160 pa_assert(c);
161
162 s = pa_strbuf_new();
163
164 pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_size(c->sources));
165
166 for (source = pa_idxset_first(c->sources, &idx); source; source = pa_idxset_next(c->sources, &idx)) {
167 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX];
168
169
170 pa_strbuf_printf(
171 s,
172 " %c index: %u\n"
173 "\tname: <%s>\n"
174 "\tdriver: <%s>\n"
175 "\tflags: %s%s%s\n"
176 "\tstate: %s\n"
177 "\tvolume: <%s>\n"
178 "\tmute: <%u>\n"
179 "\tlatency: <%0.0f usec>\n"
180 "\tsample spec: <%s>\n"
181 "\tchannel map: <%s>\n"
182 "\tused by: <%u>\n"
183 "\tlinked by: <%u>\n",
184 c->default_source_name && !strcmp(source->name, c->default_source_name) ? '*' : ' ',
185 source->index,
186 source->name,
187 source->driver,
188 source->flags & PA_SOURCE_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
189 source->flags & PA_SOURCE_LATENCY ? "LATENCY " : "",
190 source->flags & PA_SOURCE_HARDWARE ? "HARDWARE " : "",
191 state_table[pa_source_get_state(source)],
192 pa_cvolume_snprint(cv, sizeof(cv), pa_source_get_volume(source)),
193 !!pa_source_get_mute(source),
194 (double) pa_source_get_latency(source),
195 pa_sample_spec_snprint(ss, sizeof(ss), &source->sample_spec),
196 pa_channel_map_snprint(cm, sizeof(cm), &source->channel_map),
197 pa_source_used_by(source),
198 pa_source_linked_by(source));
199
200 if (source->monitor_of)
201 pa_strbuf_printf(s, "\tmonitor_of: <%u>\n", source->monitor_of->index);
202 if (source->module)
203 pa_strbuf_printf(s, "\tmodule: <%u>\n", source->module->index);
204 if (source->description)
205 pa_strbuf_printf(s, "\tdescription: <%s>\n", source->description);
206 }
207
208 return pa_strbuf_tostring_free(s);
209 }
210
211
212 char *pa_source_output_list_to_string(pa_core *c) {
213 pa_strbuf *s;
214 pa_source_output *o;
215 uint32_t idx = PA_IDXSET_INVALID;
216 static const char* const state_table[] = {
217 [PA_SOURCE_OUTPUT_RUNNING] = "RUNNING",
218 [PA_SOURCE_OUTPUT_CORKED] = "CORKED",
219 [PA_SOURCE_OUTPUT_UNLINKED] = "UNLINKED"
220 };
221 pa_assert(c);
222
223 s = pa_strbuf_new();
224
225 pa_strbuf_printf(s, "%u source outputs(s) available.\n", pa_idxset_size(c->source_outputs));
226
227 for (o = pa_idxset_first(c->source_outputs, &idx); o; o = pa_idxset_next(c->source_outputs, &idx)) {
228 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
229
230 pa_assert(o->source);
231
232 pa_strbuf_printf(
233 s,
234 " index: %u\n"
235 "\tname: '%s'\n"
236 "\tdriver: <%s>\n"
237 "\tflags: %s%s\n"
238 "\tstate: %s\n"
239 "\tsource: <%u> '%s'\n"
240 "\tlatency: <%0.0f usec>\n"
241 "\tsample spec: <%s>\n"
242 "\tchannel map: <%s>\n"
243 "\tresample method: %s\n",
244 o->index,
245 o->name,
246 o->driver,
247 o->flags & PA_SOURCE_OUTPUT_VARIABLE_RATE ? "VARIABLE_RATE " : "",
248 o->flags & PA_SOURCE_OUTPUT_DONT_MOVE ? "DONT_MOVE " : "",
249 state_table[pa_source_output_get_state(o)],
250 o->source->index, o->source->name,
251 (double) pa_source_output_get_latency(o),
252 pa_sample_spec_snprint(ss, sizeof(ss), &o->sample_spec),
253 pa_channel_map_snprint(cm, sizeof(cm), &o->channel_map),
254 pa_resample_method_to_string(pa_source_output_get_resample_method(o)));
255 if (o->module)
256 pa_strbuf_printf(s, "\towner module: <%u>\n", o->module->index);
257 if (o->client)
258 pa_strbuf_printf(s, "\tclient: <%u> '%s'\n", o->client->index, o->client->name);
259 }
260
261 return pa_strbuf_tostring_free(s);
262 }
263
264 char *pa_sink_input_list_to_string(pa_core *c) {
265 pa_strbuf *s;
266 pa_sink_input *i;
267 uint32_t idx = PA_IDXSET_INVALID;
268 static const char* const state_table[] = {
269 [PA_SINK_INPUT_RUNNING] = "RUNNING",
270 [PA_SINK_INPUT_DRAINED] = "DRAINED",
271 [PA_SINK_INPUT_CORKED] = "CORKED",
272 [PA_SINK_INPUT_UNLINKED] = "UNLINKED"
273 };
274
275 pa_assert(c);
276 s = pa_strbuf_new();
277
278 pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_size(c->sink_inputs));
279
280 for (i = pa_idxset_first(c->sink_inputs, &idx); i; i = pa_idxset_next(c->sink_inputs, &idx)) {
281 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
282
283 pa_assert(i->sink);
284
285 pa_strbuf_printf(
286 s,
287 " index: %u\n"
288 "\tname: <%s>\n"
289 "\tdriver: <%s>\n"
290 "\tflags: %s%s\n"
291 "\tstate: %s\n"
292 "\tsink: <%u> '%s'\n"
293 "\tvolume: <%s>\n"
294 "\tmute: <%i>\n"
295 "\tlatency: <%0.0f usec>\n"
296 "\tsample spec: <%s>\n"
297 "\tchannel map: <%s>\n"
298 "\tresample method: %s\n",
299 i->index,
300 i->name,
301 i->driver,
302 i->flags & PA_SINK_INPUT_VARIABLE_RATE ? "VARIABLE_RATE " : "",
303 i->flags & PA_SINK_INPUT_DONT_MOVE ? "DONT_MOVE " : "",
304 state_table[pa_sink_input_get_state(i)],
305 i->sink->index, i->sink->name,
306 pa_cvolume_snprint(cv, sizeof(cv), pa_sink_input_get_volume(i)),
307 !!pa_sink_input_get_mute(i),
308 (double) pa_sink_input_get_latency(i),
309 pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec),
310 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
311 pa_resample_method_to_string(pa_sink_input_get_resample_method(i)));
312
313 if (i->module)
314 pa_strbuf_printf(s, "\tmodule: <%u>\n", i->module->index);
315 if (i->client)
316 pa_strbuf_printf(s, "\tclient: <%u> '%s'\n", i->client->index, i->client->name);
317 }
318
319 return pa_strbuf_tostring_free(s);
320 }
321
322 char *pa_scache_list_to_string(pa_core *c) {
323 pa_strbuf *s;
324 pa_assert(c);
325
326 s = pa_strbuf_new();
327
328 pa_strbuf_printf(s, "%u cache entries available.\n", c->scache ? pa_idxset_size(c->scache) : 0);
329
330 if (c->scache) {
331 pa_scache_entry *e;
332 uint32_t idx = PA_IDXSET_INVALID;
333
334 for (e = pa_idxset_first(c->scache, &idx); e; e = pa_idxset_next(c->scache, &idx)) {
335 double l = 0;
336 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX] = "n/a", cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX] = "n/a";
337
338 if (e->memchunk.memblock) {
339 pa_sample_spec_snprint(ss, sizeof(ss), &e->sample_spec);
340 pa_channel_map_snprint(cm, sizeof(cm), &e->channel_map);
341 l = (double) e->memchunk.length / pa_bytes_per_second(&e->sample_spec);
342 }
343
344 pa_strbuf_printf(
345 s,
346 " name: <%s>\n"
347 "\tindex: <%u>\n"
348 "\tsample spec: <%s>\n"
349 "\tchannel map: <%s>\n"
350 "\tlength: <%lu>\n"
351 "\tduration: <%0.1fs>\n"
352 "\tvolume: <%s>\n"
353 "\tlazy: %s\n"
354 "\tfilename: %s\n",
355 e->name,
356 e->index,
357 ss,
358 cm,
359 (long unsigned)(e->memchunk.memblock ? e->memchunk.length : 0),
360 l,
361 pa_cvolume_snprint(cv, sizeof(cv), &e->volume),
362 e->lazy ? "yes" : "no",
363 e->filename ? e->filename : "n/a");
364 }
365 }
366
367 return pa_strbuf_tostring_free(s);
368 }
369
370 char *pa_autoload_list_to_string(pa_core *c) {
371 pa_strbuf *s;
372 pa_assert(c);
373
374 s = pa_strbuf_new();
375
376 pa_strbuf_printf(s, "%u autoload entries available.\n", c->autoload_hashmap ? pa_hashmap_size(c->autoload_hashmap) : 0);
377
378 if (c->autoload_hashmap) {
379 pa_autoload_entry *e;
380 void *state = NULL;
381
382 while ((e = pa_hashmap_iterate(c->autoload_hashmap, &state, NULL))) {
383 pa_strbuf_printf(
384 s, " name: <%s>\n\ttype: <%s>\n\tindex: <%u>\n\tmodule_name: <%s>\n\targuments: <%s>\n",
385 e->name,
386 e->type == PA_NAMEREG_SOURCE ? "source" : "sink",
387 e->index,
388 e->module,
389 e->argument ? e->argument : "");
390
391 }
392 }
393
394 return pa_strbuf_tostring_free(s);
395 }
396
397 char *pa_full_status_string(pa_core *c) {
398 pa_strbuf *s;
399 int i;
400
401 s = pa_strbuf_new();
402
403 for (i = 0; i < 8; i++) {
404 char *t = NULL;
405
406 switch (i) {
407 case 0:
408 t = pa_sink_list_to_string(c);
409 break;
410 case 1:
411 t = pa_source_list_to_string(c);
412 break;
413 case 2:
414 t = pa_sink_input_list_to_string(c);
415 break;
416 case 3:
417 t = pa_source_output_list_to_string(c);
418 break;
419 case 4:
420 t = pa_client_list_to_string(c);
421 break;
422 case 5:
423 t = pa_module_list_to_string(c);
424 break;
425 case 6:
426 t = pa_scache_list_to_string(c);
427 break;
428 case 7:
429 t = pa_autoload_list_to_string(c);
430 break;
431 }
432
433 pa_strbuf_puts(s, t);
434 pa_xfree(t);
435 }
436
437 return pa_strbuf_tostring_free(s);
438 }