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"
63 "\tauto unload: %s\n",
64 m->index, m->name, m->argument ? m->argument : "", m->n_used,
65 m->auto_unload ? "yes" : "no");
68 return pa_strbuf_tostring_free(s);
71 char *pa_client_list_to_string(pa_core *c) {
74 uint32_t idx = PA_IDXSET_INVALID;
80 pa_strbuf_printf(s, "%u client(s) logged in.\n", pa_idxset_size(c->clients));
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);
86 pa_strbuf_printf(s, "\towner module: <%u>\n", client->owner->index);
89 return pa_strbuf_tostring_free(s);
92 char *pa_sink_list_to_string(pa_core *c) {
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_DISCONNECTED] = "DISCONNECTED"
107 pa_strbuf_printf(s, "%u sink(s) available.\n", pa_idxset_size(c->sinks));
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];
117 "\tis_hardware: <%i>\n"
121 "\tlatency: <%0.0f usec>\n"
122 "\tmonitor_source: <%u>\n"
123 "\tsample spec: <%s>\n"
124 "\tchannel map: <%s>\n",
125 c->default_sink_name && !strcmp(sink->name, c->default_sink_name) ? '*' : ' ',
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));
139 pa_strbuf_printf(s, "\tmodule: <%u>\n", sink->module->index);
140 if (sink->description)
141 pa_strbuf_printf(s, "\tdescription: <%s>\n", sink->description);
144 return pa_strbuf_tostring_free(s);
147 char *pa_source_list_to_string(pa_core *c) {
150 uint32_t idx = PA_IDXSET_INVALID;
151 static const char* const state_table[] = {
152 [PA_SOURCE_RUNNING] = "RUNNING",
153 [PA_SOURCE_SUSPENDED] = "SUSPENDED",
154 [PA_SOURCE_IDLE] = "IDLE",
155 [PA_SOURCE_DISCONNECTED] = "DISCONNECTED"
162 pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_size(c->sources));
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];
173 "\tis_hardware: <%i>\n"
177 "\tlatency: <%0.0f usec>\n"
178 "\tsample spec: <%s>\n"
179 "\tchannel map: <%s>\n",
180 c->default_source_name && !strcmp(source->name, c->default_source_name) ? '*' : ' ',
184 !!source->is_hardware,
185 state_table[pa_source_get_state(source)],
186 pa_cvolume_snprint(cv, sizeof(cv), pa_source_get_volume(source)),
187 !!pa_source_get_mute(source),
188 (double) pa_source_get_latency(source),
189 pa_sample_spec_snprint(ss, sizeof(ss), &source->sample_spec),
190 pa_channel_map_snprint(cm, sizeof(cm), &source->channel_map));
192 if (source->monitor_of)
193 pa_strbuf_printf(s, "\tmonitor_of: <%u>\n", source->monitor_of->index);
195 pa_strbuf_printf(s, "\tmodule: <%u>\n", source->module->index);
196 if (source->description)
197 pa_strbuf_printf(s, "\tdescription: <%s>\n", source->description);
200 return pa_strbuf_tostring_free(s);
204 char *pa_source_output_list_to_string(pa_core *c) {
207 uint32_t idx = PA_IDXSET_INVALID;
208 static const char* const state_table[] = {
209 [PA_SOURCE_OUTPUT_RUNNING] = "RUNNING",
210 [PA_SOURCE_OUTPUT_CORKED] = "CORKED",
211 [PA_SOURCE_OUTPUT_DISCONNECTED] = "DISCONNECTED"
218 pa_strbuf_printf(s, "%u source outputs(s) available.\n", pa_idxset_size(c->source_outputs));
220 for (o = pa_idxset_first(c->source_outputs, &idx); o; o = pa_idxset_next(c->source_outputs, &idx)) {
221 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
231 "\tsource: <%u> '%s'\n"
232 "\tlatency: <%0.0f usec>\n"
233 "\tsample spec: <%s>\n"
234 "\tchannel map: <%s>\n"
235 "\tresample method: %s\n",
239 state_table[pa_source_output_get_state(o)],
240 o->source->index, o->source->name,
241 (double) pa_source_output_get_latency(o),
242 pa_sample_spec_snprint(ss, sizeof(ss), &o->sample_spec),
243 pa_channel_map_snprint(cm, sizeof(cm), &o->channel_map),
244 pa_resample_method_to_string(pa_source_output_get_resample_method(o)));
246 pa_strbuf_printf(s, "\towner module: <%u>\n", o->module->index);
248 pa_strbuf_printf(s, "\tclient: <%u> '%s'\n", o->client->index, o->client->name);
251 return pa_strbuf_tostring_free(s);
254 char *pa_sink_input_list_to_string(pa_core *c) {
257 uint32_t idx = PA_IDXSET_INVALID;
258 static const char* const state_table[] = {
259 [PA_SINK_INPUT_RUNNING] = "RUNNING",
260 [PA_SINK_INPUT_DRAINED] = "DRAINED",
261 [PA_SINK_INPUT_CORKED] = "CORKED",
262 [PA_SINK_INPUT_DISCONNECTED] = "DISCONNECTED"
269 pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_size(c->sink_inputs));
271 for (i = pa_idxset_first(c->sink_inputs, &idx); i; i = pa_idxset_next(c->sink_inputs, &idx)) {
272 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
282 "\tsink: <%u> '%s'\n"
285 "\tlatency: <%0.0f usec>\n"
286 "\tsample spec: <%s>\n"
287 "\tchannel map: <%s>\n"
288 "\tresample method: %s\n",
292 state_table[pa_sink_input_get_state(i)],
293 i->sink->index, i->sink->name,
294 pa_cvolume_snprint(cv, sizeof(cv), pa_sink_input_get_volume(i)),
295 !!pa_sink_input_get_mute(i),
296 (double) pa_sink_input_get_latency(i),
297 pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec),
298 pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
299 pa_resample_method_to_string(pa_sink_input_get_resample_method(i)));
302 pa_strbuf_printf(s, "\tmodule: <%u>\n", i->module->index);
304 pa_strbuf_printf(s, "\tclient: <%u> '%s'\n", i->client->index, i->client->name);
307 return pa_strbuf_tostring_free(s);
310 char *pa_scache_list_to_string(pa_core *c) {
317 pa_strbuf_printf(s, "%u cache entries available.\n", c->scache ? pa_idxset_size(c->scache) : 0);
321 uint32_t idx = PA_IDXSET_INVALID;
323 for (e = pa_idxset_first(c->scache, &idx); e; e = pa_idxset_next(c->scache, &idx)) {
325 char ss[PA_SAMPLE_SPEC_SNPRINT_MAX] = "n/a", cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX] = "n/a";
327 if (e->memchunk.memblock) {
328 pa_sample_spec_snprint(ss, sizeof(ss), &e->sample_spec);
329 pa_channel_map_snprint(cm, sizeof(cm), &e->channel_map);
330 l = (double) e->memchunk.length / pa_bytes_per_second(&e->sample_spec);
337 "\tsample spec: <%s>\n"
338 "\tchannel map: <%s>\n"
340 "\tduration: <%0.1fs>\n"
348 (long unsigned)(e->memchunk.memblock ? e->memchunk.length : 0),
350 pa_cvolume_snprint(cv, sizeof(cv), &e->volume),
351 e->lazy ? "yes" : "no",
352 e->filename ? e->filename : "n/a");
356 return pa_strbuf_tostring_free(s);
359 char *pa_autoload_list_to_string(pa_core *c) {
366 pa_strbuf_printf(s, "%u autoload entries available.\n", c->autoload_hashmap ? pa_hashmap_size(c->autoload_hashmap) : 0);
368 if (c->autoload_hashmap) {
369 pa_autoload_entry *e;
372 while ((e = pa_hashmap_iterate(c->autoload_hashmap, &state, NULL))) {
374 s, " name: <%s>\n\ttype: <%s>\n\tindex: <%u>\n\tmodule_name: <%s>\n\targuments: <%s>\n",
376 e->type == PA_NAMEREG_SOURCE ? "source" : "sink",
379 e->argument ? e->argument : "");
384 return pa_strbuf_tostring_free(s);
387 char *pa_full_status_string(pa_core *c) {
393 for (i = 0; i < 8; i++) {
398 t = pa_sink_list_to_string(c);
401 t = pa_source_list_to_string(c);
404 t = pa_sink_input_list_to_string(c);
407 t = pa_source_output_list_to_string(c);
410 t = pa_client_list_to_string(c);
413 t = pa_module_list_to_string(c);
416 t = pa_scache_list_to_string(c);
419 t = pa_autoload_list_to_string(c);
423 pa_strbuf_puts(s, t);
427 return pa_strbuf_tostring_free(s);