]> code.delx.au - pulseaudio/blob - src/pulsecore/cli-text.c
Lots of assorted minor cleanups and fixes:
[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 <assert.h>
29 #include <string.h>
30
31 #include <pulse/volume.h>
32 #include <pulse/xmalloc.h>
33
34 #include <pulsecore/module.h>
35 #include <pulsecore/client.h>
36 #include <pulsecore/sink.h>
37 #include <pulsecore/source.h>
38 #include <pulsecore/sink-input.h>
39 #include <pulsecore/source-output.h>
40 #include <pulsecore/strbuf.h>
41 #include <pulsecore/sample-util.h>
42 #include <pulsecore/core-scache.h>
43 #include <pulsecore/autoload.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 assert(c);
52
53 s = pa_strbuf_new();
54 assert(s);
55
56 pa_strbuf_printf(s, "%u module(s) loaded.\n", pa_idxset_size(c->modules));
57
58 for (m = pa_idxset_first(c->modules, &idx); m; m = pa_idxset_next(c->modules, &idx)) {
59 pa_strbuf_printf(s, " index: %u\n"
60 "\tname: <%s>\n"
61 "\targument: <%s>\n"
62 "\tused: %i\n"
63 "\tauto unload: %s\n",
64 m->index, m->name, m->argument ? m->argument : "", m->n_used,
65 m->auto_unload ? "yes" : "no");
66 }
67
68 return pa_strbuf_tostring_free(s);
69 }
70
71 char *pa_client_list_to_string(pa_core *c) {
72 pa_strbuf *s;
73 pa_client *client;
74 uint32_t idx = PA_IDXSET_INVALID;
75 assert(c);
76
77 s = pa_strbuf_new();
78 assert(s);
79
80 pa_strbuf_printf(s, "%u client(s) logged in.\n", pa_idxset_size(c->clients));
81
82 for (client = pa_idxset_first(c->clients, &idx); client; client = pa_idxset_next(c->clients, &idx)) {
83 pa_strbuf_printf(s, " index: %u\n\tname: <%s>\n\tdriver: <%s>\n", client->index, client->name, client->driver);
84
85 if (client->owner)
86 pa_strbuf_printf(s, "\towner module: <%u>\n", client->owner->index);
87 }
88
89 return pa_strbuf_tostring_free(s);
90 }
91
92 char *pa_sink_list_to_string(pa_core *c) {
93 pa_strbuf *s;
94 pa_sink *sink;
95 uint32_t idx = PA_IDXSET_INVALID;
96 static const char* const state_table[] = {
97 [PA_SINK_RUNNING] = "RUNNING",
98 [PA_SINK_SUSPENDED] = "SUSPENDED",
99 [PA_SINK_IDLE] = "IDLE",
100 [PA_SINK_UNLINKED] = "UNLINKED"
101 };
102 assert(c);
103
104 s = pa_strbuf_new();
105 assert(s);
106
107 pa_strbuf_printf(s, "%u sink(s) available.\n", pa_idxset_size(c->sinks));
108
109 for (sink = pa_idxset_first(c->sinks, &idx); sink; sink = pa_idxset_next(c->sinks, &idx)) {
110 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
111
112 pa_strbuf_printf(
113 s,
114 " %c index: %u\n"
115 "\tname: <%s>\n"
116 "\tdriver: <%s>\n"
117 "\tflags: %s%s%s%s\n"
118 "\tstate: %s\n"
119 "\tvolume: <%s>\n"
120 "\tmute: <%i>\n"
121 "\tlatency: <%0.0f usec>\n"
122 "\tmonitor source: <%u>\n"
123 "\tsample spec: <%s>\n"
124 "\tchannel map: <%s>\n"
125 "\tused by: <%u>\n",
126 c->default_sink_name && !strcmp(sink->name, c->default_sink_name) ? '*' : ' ',
127 sink->index,
128 sink->name,
129 sink->driver,
130 sink->flags & PA_SINK_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
131 sink->flags & PA_SINK_LATENCY ? "LATENCY " : "",
132 sink->flags & PA_SINK_HARDWARE ? "HARDWARE " : "",
133 sink->flags & PA_SINK_CAN_SUSPEND ? "CAN_SUSPEND " : "",
134 state_table[pa_sink_get_state(sink)],
135 pa_cvolume_snprint(cv, sizeof(cv), pa_sink_get_volume(sink)),
136 !!pa_sink_get_mute(sink),
137 (double) pa_sink_get_latency(sink),
138 sink->monitor_source ? sink->monitor_source->index : PA_INVALID_INDEX,
139 pa_sample_spec_snprint(ss, sizeof(ss), &sink->sample_spec),
140 pa_channel_map_snprint(cm, sizeof(cm), &sink->channel_map),
141 pa_sink_used_by(sink));
142
143 if (sink->module)
144 pa_strbuf_printf(s, "\tmodule: <%u>\n", sink->module->index);
145 if (sink->description)
146 pa_strbuf_printf(s, "\tdescription: <%s>\n", sink->description);
147 }
148
149 return pa_strbuf_tostring_free(s);
150 }
151
152 char *pa_source_list_to_string(pa_core *c) {
153 pa_strbuf *s;
154 pa_source *source;
155 uint32_t idx = PA_IDXSET_INVALID;
156 static const char* const state_table[] = {
157 [PA_SOURCE_RUNNING] = "RUNNING",
158 [PA_SOURCE_SUSPENDED] = "SUSPENDED",
159 [PA_SOURCE_IDLE] = "IDLE",
160 [PA_SOURCE_UNLINKED] = "UNLINKED"
161 };
162 assert(c);
163
164 s = pa_strbuf_new();
165 assert(s);
166
167 pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_size(c->sources));
168
169 for (source = pa_idxset_first(c->sources, &idx); source; source = pa_idxset_next(c->sources, &idx)) {
170 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX];
171
172
173 pa_strbuf_printf(
174 s,
175 " %c index: %u\n"
176 "\tname: <%s>\n"
177 "\tdriver: <%s>\n"
178 "\tflags: %s%s%s%s\n"
179 "\tstate: %s\n"
180 "\tvolume: <%s>\n"
181 "\tmute: <%u>\n"
182 "\tlatency: <%0.0f usec>\n"
183 "\tsample spec: <%s>\n"
184 "\tchannel map: <%s>\n"
185 "\tused by: <%u>\n",
186 c->default_source_name && !strcmp(source->name, c->default_source_name) ? '*' : ' ',
187 source->index,
188 source->name,
189 source->driver,
190 source->flags & PA_SOURCE_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
191 source->flags & PA_SOURCE_LATENCY ? "LATENCY " : "",
192 source->flags & PA_SOURCE_HARDWARE ? "HARDWARE " : "",
193 source->flags & PA_SOURCE_CAN_SUSPEND ? "CAN_SUSPEND " : "",
194 state_table[pa_source_get_state(source)],
195 pa_cvolume_snprint(cv, sizeof(cv), pa_source_get_volume(source)),
196 !!pa_source_get_mute(source),
197 (double) pa_source_get_latency(source),
198 pa_sample_spec_snprint(ss, sizeof(ss), &source->sample_spec),
199 pa_channel_map_snprint(cm, sizeof(cm), &source->channel_map),
200 pa_source_used_by(source));
201
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);
208 }
209
210 return pa_strbuf_tostring_free(s);
211 }
212
213
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"
222 };
223 assert(c);
224
225 s = pa_strbuf_new();
226 assert(s);
227
228 pa_strbuf_printf(s, "%u source outputs(s) available.\n", pa_idxset_size(c->source_outputs));
229
230 for (o = pa_idxset_first(c->source_outputs, &idx); o; o = pa_idxset_next(c->source_outputs, &idx)) {
231 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
232
233 assert(o->source);
234
235 pa_strbuf_printf(
236 s,
237 " index: %u\n"
238 "\tname: '%s'\n"
239 "\tdriver: <%s>\n"
240 "\tflags: %s%s\n"
241 "\tstate: %s\n"
242 "\tsource: <%u> '%s'\n"
243 "\tlatency: <%0.0f usec>\n"
244 "\tsample spec: <%s>\n"
245 "\tchannel map: <%s>\n"
246 "\tresample method: %s\n",
247 o->index,
248 o->name,
249 o->driver,
250 o->flags & PA_SOURCE_OUTPUT_VARIABLE_RATE ? "VARIABLE_RATE " : "",
251 o->flags & PA_SOURCE_OUTPUT_DONT_MOVE ? "DONT_MOVE " : "",
252 state_table[pa_source_output_get_state(o)],
253 o->source->index, o->source->name,
254 (double) pa_source_output_get_latency(o),
255 pa_sample_spec_snprint(ss, sizeof(ss), &o->sample_spec),
256 pa_channel_map_snprint(cm, sizeof(cm), &o->channel_map),
257 pa_resample_method_to_string(pa_source_output_get_resample_method(o)));
258 if (o->module)
259 pa_strbuf_printf(s, "\towner module: <%u>\n", o->module->index);
260 if (o->client)
261 pa_strbuf_printf(s, "\tclient: <%u> '%s'\n", o->client->index, o->client->name);
262 }
263
264 return pa_strbuf_tostring_free(s);
265 }
266
267 char *pa_sink_input_list_to_string(pa_core *c) {
268 pa_strbuf *s;
269 pa_sink_input *i;
270 uint32_t idx = PA_IDXSET_INVALID;
271 static const char* const state_table[] = {
272 [PA_SINK_INPUT_RUNNING] = "RUNNING",
273 [PA_SINK_INPUT_DRAINED] = "DRAINED",
274 [PA_SINK_INPUT_CORKED] = "CORKED",
275 [PA_SINK_INPUT_UNLINKED] = "UNLINKED"
276 };
277
278 assert(c);
279 s = pa_strbuf_new();
280 assert(s);
281
282 pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_size(c->sink_inputs));
283
284 for (i = pa_idxset_first(c->sink_inputs, &idx); i; i = pa_idxset_next(c->sink_inputs, &idx)) {
285 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
286
287 assert(i->sink);
288
289 pa_strbuf_printf(
290 s,
291 " index: %u\n"
292 "\tname: <%s>\n"
293 "\tdriver: <%s>\n"
294 "\tflags: %s%s\n"
295 "\tstate: %s\n"
296 "\tsink: <%u> '%s'\n"
297 "\tvolume: <%s>\n"
298 "\tmute: <%i>\n"
299 "\tlatency: <%0.0f usec>\n"
300 "\tsample spec: <%s>\n"
301 "\tchannel map: <%s>\n"
302 "\tresample method: %s\n",
303 i->index,
304 i->name,
305 i->driver,
306 i->flags & PA_SINK_INPUT_VARIABLE_RATE ? "VARIABLE_RATE " : "",
307 i->flags & PA_SINK_INPUT_DONT_MOVE ? "DONT_MOVE " : "",
308 state_table[pa_sink_input_get_state(i)],
309 i->sink->index, i->sink->name,
310 pa_cvolume_snprint(cv, sizeof(cv), pa_sink_input_get_volume(i)),
311 !!pa_sink_input_get_mute(i),
312 (double) pa_sink_input_get_latency(i),
313 pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec),
314 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
315 pa_resample_method_to_string(pa_sink_input_get_resample_method(i)));
316
317 if (i->module)
318 pa_strbuf_printf(s, "\tmodule: <%u>\n", i->module->index);
319 if (i->client)
320 pa_strbuf_printf(s, "\tclient: <%u> '%s'\n", i->client->index, i->client->name);
321 }
322
323 return pa_strbuf_tostring_free(s);
324 }
325
326 char *pa_scache_list_to_string(pa_core *c) {
327 pa_strbuf *s;
328 assert(c);
329
330 s = pa_strbuf_new();
331 assert(s);
332
333 pa_strbuf_printf(s, "%u cache entries available.\n", c->scache ? pa_idxset_size(c->scache) : 0);
334
335 if (c->scache) {
336 pa_scache_entry *e;
337 uint32_t idx = PA_IDXSET_INVALID;
338
339 for (e = pa_idxset_first(c->scache, &idx); e; e = pa_idxset_next(c->scache, &idx)) {
340 double l = 0;
341 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX] = "n/a", cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX] = "n/a";
342
343 if (e->memchunk.memblock) {
344 pa_sample_spec_snprint(ss, sizeof(ss), &e->sample_spec);
345 pa_channel_map_snprint(cm, sizeof(cm), &e->channel_map);
346 l = (double) e->memchunk.length / pa_bytes_per_second(&e->sample_spec);
347 }
348
349 pa_strbuf_printf(
350 s,
351 " name: <%s>\n"
352 "\tindex: <%u>\n"
353 "\tsample spec: <%s>\n"
354 "\tchannel map: <%s>\n"
355 "\tlength: <%lu>\n"
356 "\tduration: <%0.1fs>\n"
357 "\tvolume: <%s>\n"
358 "\tlazy: %s\n"
359 "\tfilename: %s\n",
360 e->name,
361 e->index,
362 ss,
363 cm,
364 (long unsigned)(e->memchunk.memblock ? e->memchunk.length : 0),
365 l,
366 pa_cvolume_snprint(cv, sizeof(cv), &e->volume),
367 e->lazy ? "yes" : "no",
368 e->filename ? e->filename : "n/a");
369 }
370 }
371
372 return pa_strbuf_tostring_free(s);
373 }
374
375 char *pa_autoload_list_to_string(pa_core *c) {
376 pa_strbuf *s;
377 assert(c);
378
379 s = pa_strbuf_new();
380 assert(s);
381
382 pa_strbuf_printf(s, "%u autoload entries available.\n", c->autoload_hashmap ? pa_hashmap_size(c->autoload_hashmap) : 0);
383
384 if (c->autoload_hashmap) {
385 pa_autoload_entry *e;
386 void *state = NULL;
387
388 while ((e = pa_hashmap_iterate(c->autoload_hashmap, &state, NULL))) {
389 pa_strbuf_printf(
390 s, " name: <%s>\n\ttype: <%s>\n\tindex: <%u>\n\tmodule_name: <%s>\n\targuments: <%s>\n",
391 e->name,
392 e->type == PA_NAMEREG_SOURCE ? "source" : "sink",
393 e->index,
394 e->module,
395 e->argument ? e->argument : "");
396
397 }
398 }
399
400 return pa_strbuf_tostring_free(s);
401 }
402
403 char *pa_full_status_string(pa_core *c) {
404 pa_strbuf *s;
405 int i;
406
407 s = pa_strbuf_new();
408
409 for (i = 0; i < 8; i++) {
410 char *t = NULL;
411
412 switch (i) {
413 case 0:
414 t = pa_sink_list_to_string(c);
415 break;
416 case 1:
417 t = pa_source_list_to_string(c);
418 break;
419 case 2:
420 t = pa_sink_input_list_to_string(c);
421 break;
422 case 3:
423 t = pa_source_output_list_to_string(c);
424 break;
425 case 4:
426 t = pa_client_list_to_string(c);
427 break;
428 case 5:
429 t = pa_module_list_to_string(c);
430 break;
431 case 6:
432 t = pa_scache_list_to_string(c);
433 break;
434 case 7:
435 t = pa_autoload_list_to_string(c);
436 break;
437 }
438
439 pa_strbuf_puts(s, t);
440 pa_xfree(t);
441 }
442
443 return pa_strbuf_tostring_free(s);
444 }