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
30 #include <pulse/volume.h>
31 #include <pulse/xmalloc.h>
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>
47 char *pa_module_list_to_string(pa_core
*c
) {
50 uint32_t idx
= PA_IDXSET_INVALID
;
55 pa_strbuf_printf(s
, "%u module(s) loaded.\n", pa_idxset_size(c
->modules
));
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"
62 "\tauto unload: %s\n",
63 m
->index
, m
->name
, m
->argument
? m
->argument
: "", m
->n_used
,
64 m
->auto_unload
? "yes" : "no");
67 return pa_strbuf_tostring_free(s
);
70 char *pa_client_list_to_string(pa_core
*c
) {
73 uint32_t idx
= PA_IDXSET_INVALID
;
78 pa_strbuf_printf(s
, "%u client(s) logged in.\n", pa_idxset_size(c
->clients
));
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
);
84 pa_strbuf_printf(s
, "\towner module: <%u>\n", client
->owner
->index
);
87 return pa_strbuf_tostring_free(s
);
90 char *pa_sink_list_to_string(pa_core
*c
) {
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"
104 pa_strbuf_printf(s
, "%u sink(s) available.\n", pa_idxset_size(c
->sinks
));
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
];
114 "\tflags: %s%s%s%s\n"
118 "\tlatency: <%0.0f usec>\n"
119 "\tmonitor source: <%u>\n"
120 "\tsample spec: <%s>\n"
121 "\tchannel map: <%s>\n"
123 c
->default_sink_name
&& !strcmp(sink
->name
, c
->default_sink_name
) ? '*' : ' ',
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 sink
->flags
& PA_SINK_CAN_SUSPEND
? "CAN_SUSPEND " : "",
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
));
141 pa_strbuf_printf(s
, "\tmodule: <%u>\n", sink
->module
->index
);
142 if (sink
->description
)
143 pa_strbuf_printf(s
, "\tdescription: <%s>\n", sink
->description
);
146 return pa_strbuf_tostring_free(s
);
149 char *pa_source_list_to_string(pa_core
*c
) {
152 uint32_t idx
= PA_IDXSET_INVALID
;
153 static const char* const state_table
[] = {
154 [PA_SOURCE_RUNNING
] = "RUNNING",
155 [PA_SOURCE_SUSPENDED
] = "SUSPENDED",
156 [PA_SOURCE_IDLE
] = "IDLE",
157 [PA_SOURCE_UNLINKED
] = "UNLINKED"
163 pa_strbuf_printf(s
, "%u source(s) available.\n", pa_idxset_size(c
->sources
));
165 for (source
= pa_idxset_first(c
->sources
, &idx
); source
; source
= pa_idxset_next(c
->sources
, &idx
)) {
166 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
], cv
[PA_CVOLUME_SNPRINT_MAX
];
174 "\tflags: %s%s%s%s\n"
178 "\tlatency: <%0.0f usec>\n"
179 "\tsample spec: <%s>\n"
180 "\tchannel map: <%s>\n"
182 c
->default_source_name
&& !strcmp(source
->name
, c
->default_source_name
) ? '*' : ' ',
186 source
->flags
& PA_SOURCE_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
187 source
->flags
& PA_SOURCE_LATENCY
? "LATENCY " : "",
188 source
->flags
& PA_SOURCE_HARDWARE
? "HARDWARE " : "",
189 source
->flags
& PA_SOURCE_CAN_SUSPEND
? "CAN_SUSPEND " : "",
190 state_table
[pa_source_get_state(source
)],
191 pa_cvolume_snprint(cv
, sizeof(cv
), pa_source_get_volume(source
)),
192 !!pa_source_get_mute(source
),
193 (double) pa_source_get_latency(source
),
194 pa_sample_spec_snprint(ss
, sizeof(ss
), &source
->sample_spec
),
195 pa_channel_map_snprint(cm
, sizeof(cm
), &source
->channel_map
),
196 pa_source_used_by(source
));
198 if (source
->monitor_of
)
199 pa_strbuf_printf(s
, "\tmonitor_of: <%u>\n", source
->monitor_of
->index
);
201 pa_strbuf_printf(s
, "\tmodule: <%u>\n", source
->module
->index
);
202 if (source
->description
)
203 pa_strbuf_printf(s
, "\tdescription: <%s>\n", source
->description
);
206 return pa_strbuf_tostring_free(s
);
210 char *pa_source_output_list_to_string(pa_core
*c
) {
213 uint32_t idx
= PA_IDXSET_INVALID
;
214 static const char* const state_table
[] = {
215 [PA_SOURCE_OUTPUT_RUNNING
] = "RUNNING",
216 [PA_SOURCE_OUTPUT_CORKED
] = "CORKED",
217 [PA_SOURCE_OUTPUT_UNLINKED
] = "UNLINKED"
223 pa_strbuf_printf(s
, "%u source outputs(s) available.\n", pa_idxset_size(c
->source_outputs
));
225 for (o
= pa_idxset_first(c
->source_outputs
, &idx
); o
; o
= pa_idxset_next(c
->source_outputs
, &idx
)) {
226 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
228 pa_assert(o
->source
);
237 "\tsource: <%u> '%s'\n"
238 "\tlatency: <%0.0f usec>\n"
239 "\tsample spec: <%s>\n"
240 "\tchannel map: <%s>\n"
241 "\tresample method: %s\n",
245 o
->flags
& PA_SOURCE_OUTPUT_VARIABLE_RATE
? "VARIABLE_RATE " : "",
246 o
->flags
& PA_SOURCE_OUTPUT_DONT_MOVE
? "DONT_MOVE " : "",
247 state_table
[pa_source_output_get_state(o
)],
248 o
->source
->index
, o
->source
->name
,
249 (double) pa_source_output_get_latency(o
),
250 pa_sample_spec_snprint(ss
, sizeof(ss
), &o
->sample_spec
),
251 pa_channel_map_snprint(cm
, sizeof(cm
), &o
->channel_map
),
252 pa_resample_method_to_string(pa_source_output_get_resample_method(o
)));
254 pa_strbuf_printf(s
, "\towner module: <%u>\n", o
->module
->index
);
256 pa_strbuf_printf(s
, "\tclient: <%u> '%s'\n", o
->client
->index
, o
->client
->name
);
259 return pa_strbuf_tostring_free(s
);
262 char *pa_sink_input_list_to_string(pa_core
*c
) {
265 uint32_t idx
= PA_IDXSET_INVALID
;
266 static const char* const state_table
[] = {
267 [PA_SINK_INPUT_RUNNING
] = "RUNNING",
268 [PA_SINK_INPUT_DRAINED
] = "DRAINED",
269 [PA_SINK_INPUT_CORKED
] = "CORKED",
270 [PA_SINK_INPUT_UNLINKED
] = "UNLINKED"
276 pa_strbuf_printf(s
, "%u sink input(s) available.\n", pa_idxset_size(c
->sink_inputs
));
278 for (i
= pa_idxset_first(c
->sink_inputs
, &idx
); i
; i
= pa_idxset_next(c
->sink_inputs
, &idx
)) {
279 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cv
[PA_CVOLUME_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
290 "\tsink: <%u> '%s'\n"
293 "\tlatency: <%0.0f usec>\n"
294 "\tsample spec: <%s>\n"
295 "\tchannel map: <%s>\n"
296 "\tresample method: %s\n",
300 i
->flags
& PA_SINK_INPUT_VARIABLE_RATE
? "VARIABLE_RATE " : "",
301 i
->flags
& PA_SINK_INPUT_DONT_MOVE
? "DONT_MOVE " : "",
302 state_table
[pa_sink_input_get_state(i
)],
303 i
->sink
->index
, i
->sink
->name
,
304 pa_cvolume_snprint(cv
, sizeof(cv
), pa_sink_input_get_volume(i
)),
305 !!pa_sink_input_get_mute(i
),
306 (double) pa_sink_input_get_latency(i
),
307 pa_sample_spec_snprint(ss
, sizeof(ss
), &i
->sample_spec
),
308 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
309 pa_resample_method_to_string(pa_sink_input_get_resample_method(i
)));
312 pa_strbuf_printf(s
, "\tmodule: <%u>\n", i
->module
->index
);
314 pa_strbuf_printf(s
, "\tclient: <%u> '%s'\n", i
->client
->index
, i
->client
->name
);
317 return pa_strbuf_tostring_free(s
);
320 char *pa_scache_list_to_string(pa_core
*c
) {
326 pa_strbuf_printf(s
, "%u cache entries available.\n", c
->scache
? pa_idxset_size(c
->scache
) : 0);
330 uint32_t idx
= PA_IDXSET_INVALID
;
332 for (e
= pa_idxset_first(c
->scache
, &idx
); e
; e
= pa_idxset_next(c
->scache
, &idx
)) {
334 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
] = "n/a", cv
[PA_CVOLUME_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
] = "n/a";
336 if (e
->memchunk
.memblock
) {
337 pa_sample_spec_snprint(ss
, sizeof(ss
), &e
->sample_spec
);
338 pa_channel_map_snprint(cm
, sizeof(cm
), &e
->channel_map
);
339 l
= (double) e
->memchunk
.length
/ pa_bytes_per_second(&e
->sample_spec
);
346 "\tsample spec: <%s>\n"
347 "\tchannel map: <%s>\n"
349 "\tduration: <%0.1fs>\n"
357 (long unsigned)(e
->memchunk
.memblock
? e
->memchunk
.length
: 0),
359 pa_cvolume_snprint(cv
, sizeof(cv
), &e
->volume
),
360 e
->lazy
? "yes" : "no",
361 e
->filename
? e
->filename
: "n/a");
365 return pa_strbuf_tostring_free(s
);
368 char *pa_autoload_list_to_string(pa_core
*c
) {
374 pa_strbuf_printf(s
, "%u autoload entries available.\n", c
->autoload_hashmap
? pa_hashmap_size(c
->autoload_hashmap
) : 0);
376 if (c
->autoload_hashmap
) {
377 pa_autoload_entry
*e
;
380 while ((e
= pa_hashmap_iterate(c
->autoload_hashmap
, &state
, NULL
))) {
382 s
, " name: <%s>\n\ttype: <%s>\n\tindex: <%u>\n\tmodule_name: <%s>\n\targuments: <%s>\n",
384 e
->type
== PA_NAMEREG_SOURCE
? "source" : "sink",
387 e
->argument
? e
->argument
: "");
392 return pa_strbuf_tostring_free(s
);
395 char *pa_full_status_string(pa_core
*c
) {
401 for (i
= 0; i
< 8; i
++) {
406 t
= pa_sink_list_to_string(c
);
409 t
= pa_source_list_to_string(c
);
412 t
= pa_sink_input_list_to_string(c
);
415 t
= pa_source_output_list_to_string(c
);
418 t
= pa_client_list_to_string(c
);
421 t
= pa_module_list_to_string(c
);
424 t
= pa_scache_list_to_string(c
);
427 t
= pa_autoload_list_to_string(c
);
431 pa_strbuf_puts(s
, t
);
435 return pa_strbuf_tostring_free(s
);