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
31 #include <pulse/volume.h>
32 #include <pulse/xmalloc.h>
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>
47 char *pa_module_list_to_string(pa_core *c) {
50 uint32_t idx = PA_IDXSET_INVALID;
56 pa_strbuf_printf(s, "%u module(s) loaded.\n", pa_idxset_size(c->modules));
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\tname: <%s>\n\targument: <%s>\n\tused: %i\n\tauto unload: %s\n", m->index, m->name, m->argument, m->n_used, m->auto_unload ? "yes" : "no");
61 return pa_strbuf_tostring_free(s);
64 char *pa_client_list_to_string(pa_core *c) {
67 uint32_t idx = PA_IDXSET_INVALID;
73 pa_strbuf_printf(s, "%u client(s) logged in.\n", pa_idxset_size(c->clients));
75 for (client = pa_idxset_first(c->clients, &idx); client; client = pa_idxset_next(c->clients, &idx)) {
76 pa_strbuf_printf(s, " index: %u\n\tname: <%s>\n\tdriver: <%s>\n", client->index, client->name, client->driver);
79 pa_strbuf_printf(s, "\towner module: <%u>\n", client->owner->index);
82 return pa_strbuf_tostring_free(s);
85 char *pa_sink_list_to_string(pa_core *c) {
88 uint32_t idx = PA_IDXSET_INVALID;
94 pa_strbuf_printf(s, "%u sink(s) available.\n", pa_idxset_size(c->sinks));
96 for (sink = pa_idxset_first(c->sinks, &idx); sink; sink = pa_idxset_next(c->sinks, &idx)) {
97 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
105 "\tlatency: <%0.0f usec>\n"
106 "\tmonitor_source: <%u>\n"
107 "\tsample spec: <%s>\n"
108 "\tchannel map: <%s>\n",
109 c->default_sink_name && !strcmp(sink->name, c->default_sink_name) ? '*' : ' ',
110 sink->index, sink->name,
112 pa_cvolume_snprint(cv, sizeof(cv), pa_sink_get_volume(sink, PA_MIXER_HARDWARE)),
113 (double) pa_sink_get_latency(sink),
114 sink->monitor_source ? sink->monitor_source->index : PA_INVALID_INDEX,
115 pa_sample_spec_snprint(ss, sizeof(ss), &sink->sample_spec),
116 pa_channel_map_snprint(cm, sizeof(cm), &sink->channel_map));
119 pa_strbuf_printf(s, "\towner module: <%u>\n", sink->owner->index);
120 if (sink->description)
121 pa_strbuf_printf(s, "\tdescription: <%s>\n", sink->description);
124 return pa_strbuf_tostring_free(s);
127 char *pa_source_list_to_string(pa_core *c) {
130 uint32_t idx = PA_IDXSET_INVALID;
136 pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_size(c->sources));
138 for (source = pa_idxset_first(c->sources, &idx); source; source = pa_idxset_next(c->sources, &idx)) {
139 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
147 "\tlatency: <%0.0f usec>\n"
148 "\tsample spec: <%s>\n"
149 "\tchannel map: <%s>\n",
150 c->default_source_name && !strcmp(source->name, c->default_source_name) ? '*' : ' ',
154 (double) pa_source_get_latency(source),
155 pa_sample_spec_snprint(ss, sizeof(ss), &source->sample_spec),
156 pa_channel_map_snprint(cm, sizeof(cm), &source->channel_map));
158 if (source->monitor_of)
159 pa_strbuf_printf(s, "\tmonitor_of: <%u>\n", source->monitor_of->index);
161 pa_strbuf_printf(s, "\towner module: <%u>\n", source->owner->index);
162 if (source->description)
163 pa_strbuf_printf(s, "\tdescription: <%s>\n", source->description);
166 return pa_strbuf_tostring_free(s);
170 char *pa_source_output_list_to_string(pa_core *c) {
173 uint32_t idx = PA_IDXSET_INVALID;
174 static const char* const state_table[] = {
184 pa_strbuf_printf(s, "%u source outputs(s) available.\n", pa_idxset_size(c->source_outputs));
186 for (o = pa_idxset_first(c->source_outputs, &idx); o; o = pa_idxset_next(c->source_outputs, &idx)) {
187 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
197 "\tsource: <%u> '%s'\n"
198 "\tsample spec: <%s>\n"
199 "\tchannel map: <%s>\n"
200 "\tresample method: %s\n",
204 state_table[o->state],
205 o->source->index, o->source->name,
206 pa_sample_spec_snprint(ss, sizeof(ss), &o->sample_spec),
207 pa_channel_map_snprint(cm, sizeof(cm), &o->channel_map),
208 pa_resample_method_to_string(pa_source_output_get_resample_method(o)));
210 pa_strbuf_printf(s, "\towner module: <%u>\n", o->module->index);
212 pa_strbuf_printf(s, "\tclient: <%u> '%s'\n", o->client->index, o->client->name);
215 return pa_strbuf_tostring_free(s);
218 char *pa_sink_input_list_to_string(pa_core *c) {
221 uint32_t idx = PA_IDXSET_INVALID;
222 static const char* const state_table[] = {
232 pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_size(c->sink_inputs));
234 for (i = pa_idxset_first(c->sink_inputs, &idx); i; i = pa_idxset_next(c->sink_inputs, &idx)) {
235 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
245 "\tsink: <%u> '%s'\n"
247 "\tlatency: <%0.0f usec>\n"
248 "\tsample spec: <%s>\n"
249 "\tchannel map: <%s>\n"
250 "\tresample method: %s\n",
254 state_table[i->state],
255 i->sink->index, i->sink->name,
256 pa_cvolume_snprint(cv, sizeof(cv), pa_sink_input_get_volume(i)),
257 (double) pa_sink_input_get_latency(i),
258 pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec),
259 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
260 pa_resample_method_to_string(pa_sink_input_get_resample_method(i)));
263 pa_strbuf_printf(s, "\towner module: <%u>\n", i->module->index);
265 pa_strbuf_printf(s, "\tclient: <%u> '%s'\n", i->client->index, i->client->name);
268 return pa_strbuf_tostring_free(s);
271 char *pa_scache_list_to_string(pa_core *c) {
278 pa_strbuf_printf(s, "%u cache entries available.\n", c->scache ? pa_idxset_size(c->scache) : 0);
282 uint32_t idx = PA_IDXSET_INVALID;
284 for (e = pa_idxset_first(c->scache, &idx); e; e = pa_idxset_next(c->scache, &idx)) {
286 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX] = "n/a", cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX] = "n/a";
288 if (e->memchunk.memblock) {
289 pa_sample_spec_snprint(ss, sizeof(ss), &e->sample_spec);
290 pa_channel_map_snprint(cm, sizeof(cm), &e->channel_map);
291 l = (double) e->memchunk.length / pa_bytes_per_second(&e->sample_spec);
298 "\tsample spec: <%s>\n"
299 "\tchannel map: <%s>\n"
301 "\tduration: <%0.1fs>\n"
309 (long unsigned)(e->memchunk.memblock ? e->memchunk.length : 0),
311 pa_cvolume_snprint(cv, sizeof(cv), &e->volume),
312 e->lazy ? "yes" : "no",
313 e->filename ? e->filename : "n/a");
317 return pa_strbuf_tostring_free(s);
320 char *pa_autoload_list_to_string(pa_core *c) {
327 pa_strbuf_printf(s, "%u autoload entries available.\n", c->autoload_hashmap ? pa_hashmap_size(c->autoload_hashmap) : 0);
329 if (c->autoload_hashmap) {
330 pa_autoload_entry *e;
333 while ((e = pa_hashmap_iterate(c->autoload_hashmap, &state, NULL))) {
335 s, " name: <%s>\n\ttype: <%s>\n\tindex: <%u>\n\tmodule_name: <%s>\n\targuments: <%s>\n",
337 e->type == PA_NAMEREG_SOURCE ? "source" : "sink",
345 return pa_strbuf_tostring_free(s);
348 char *pa_full_status_string(pa_core *c) {
354 for (i = 0; i < 8; i++) {
359 t = pa_sink_list_to_string(c);
362 t = pa_source_list_to_string(c);
365 t = pa_sink_input_list_to_string(c);
368 t = pa_source_output_list_to_string(c);
371 t = pa_client_list_to_string(c);
374 t = pa_module_list_to_string(c);
377 t = pa_scache_list_to_string(c);
380 t = pa_autoload_list_to_string(c);
384 pa_strbuf_puts(s, t);
388 return pa_strbuf_tostring_free(s);