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