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>
44 #include <pulsecore/core-util.h>
48 char *pa_module_list_to_string(pa_core
*c
) {
51 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
;
79 pa_strbuf_printf(s
, "%u client(s) logged in.\n", pa_idxset_size(c
->clients
));
81 for (client
= pa_idxset_first(c
->clients
, &idx
); client
; client
= pa_idxset_next(c
->clients
, &idx
)) {
91 pa_strbuf_printf(s
, "\towner module: <%u>\n", client
->module
->index
);
93 t
= pa_proplist_to_string(client
->proplist
);
94 pa_strbuf_printf(s
, "\tproperties:\n%s", t
);
98 return pa_strbuf_tostring_free(s
);
101 char *pa_sink_list_to_string(pa_core
*c
) {
104 uint32_t idx
= PA_IDXSET_INVALID
;
105 static const char* const state_table
[] = {
106 [PA_SINK_INIT
] = "INIT",
107 [PA_SINK_RUNNING
] = "RUNNING",
108 [PA_SINK_SUSPENDED
] = "SUSPENDED",
109 [PA_SINK_IDLE
] = "IDLE",
110 [PA_SINK_UNLINKED
] = "UNLINKED"
116 pa_strbuf_printf(s
, "%u sink(s) available.\n", pa_idxset_size(c
->sinks
));
118 for (sink
= pa_idxset_first(c
->sinks
, &idx
); sink
; sink
= pa_idxset_next(c
->sinks
, &idx
)) {
119 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cv
[PA_CVOLUME_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
], *t
;
126 "\tflags: %s%s%s%s%s%s\n"
130 "\tlatency: <%0.0f usec>\n"
131 "\tmonitor source: <%u>\n"
132 "\tsample spec: <%s>\n"
133 "\tchannel map: <%s>\n"
135 "\tlinked by: <%u>\n",
136 c
->default_sink_name
&& !strcmp(sink
->name
, c
->default_sink_name
) ? '*' : ' ',
140 sink
->flags
& PA_SINK_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
141 sink
->flags
& PA_SINK_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
142 sink
->flags
& PA_SINK_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
143 sink
->flags
& PA_SINK_LATENCY
? "LATENCY " : "",
144 sink
->flags
& PA_SINK_HARDWARE
? "HARDWARE " : "",
145 sink
->flags
& PA_SINK_NETWORK
? "NETWORK " : "",
146 state_table
[pa_sink_get_state(sink
)],
147 pa_cvolume_snprint(cv
, sizeof(cv
), pa_sink_get_volume(sink
)),
148 !!pa_sink_get_mute(sink
),
149 (double) pa_sink_get_latency(sink
),
150 sink
->monitor_source
? sink
->monitor_source
->index
: PA_INVALID_INDEX
,
151 pa_sample_spec_snprint(ss
, sizeof(ss
), &sink
->sample_spec
),
152 pa_channel_map_snprint(cm
, sizeof(cm
), &sink
->channel_map
),
153 pa_sink_used_by(sink
),
154 pa_sink_linked_by(sink
));
157 pa_strbuf_printf(s
, "\tmodule: <%u>\n", sink
->module
->index
);
159 t
= pa_proplist_to_string(sink
->proplist
);
160 pa_strbuf_printf(s
, "\tproperties:\n%s", t
);
164 return pa_strbuf_tostring_free(s
);
167 char *pa_source_list_to_string(pa_core
*c
) {
170 uint32_t idx
= PA_IDXSET_INVALID
;
171 static const char* const state_table
[] = {
172 [PA_SOURCE_INIT
] = "INIT",
173 [PA_SOURCE_RUNNING
] = "RUNNING",
174 [PA_SOURCE_SUSPENDED
] = "SUSPENDED",
175 [PA_SOURCE_IDLE
] = "IDLE",
176 [PA_SOURCE_UNLINKED
] = "UNLINKED"
182 pa_strbuf_printf(s
, "%u source(s) available.\n", pa_idxset_size(c
->sources
));
184 for (source
= pa_idxset_first(c
->sources
, &idx
); source
; source
= pa_idxset_next(c
->sources
, &idx
)) {
185 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
], cv
[PA_CVOLUME_SNPRINT_MAX
], *t
;
192 "\tflags: %s%s%s%s%s%s\n"
196 "\tlatency: <%0.0f usec>\n"
197 "\tsample spec: <%s>\n"
198 "\tchannel map: <%s>\n"
200 "\tlinked by: <%u>\n",
201 c
->default_source_name
&& !strcmp(source
->name
, c
->default_source_name
) ? '*' : ' ',
205 source
->flags
& PA_SOURCE_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
206 source
->flags
& PA_SOURCE_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
207 source
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
208 source
->flags
& PA_SOURCE_LATENCY
? "LATENCY " : "",
209 source
->flags
& PA_SOURCE_HARDWARE
? "HARDWARE " : "",
210 source
->flags
& PA_SOURCE_NETWORK
? "NETWORK " : "",
211 state_table
[pa_source_get_state(source
)],
212 pa_cvolume_snprint(cv
, sizeof(cv
), pa_source_get_volume(source
)),
213 !!pa_source_get_mute(source
),
214 (double) pa_source_get_latency(source
),
215 pa_sample_spec_snprint(ss
, sizeof(ss
), &source
->sample_spec
),
216 pa_channel_map_snprint(cm
, sizeof(cm
), &source
->channel_map
),
217 pa_source_used_by(source
),
218 pa_source_linked_by(source
));
220 if (source
->monitor_of
)
221 pa_strbuf_printf(s
, "\tmonitor_of: <%u>\n", source
->monitor_of
->index
);
223 pa_strbuf_printf(s
, "\tmodule: <%u>\n", source
->module
->index
);
225 t
= pa_proplist_to_string(source
->proplist
);
226 pa_strbuf_printf(s
, "\tproperties:\n%s", t
);
230 return pa_strbuf_tostring_free(s
);
234 char *pa_source_output_list_to_string(pa_core
*c
) {
237 uint32_t idx
= PA_IDXSET_INVALID
;
238 static const char* const state_table
[] = {
239 [PA_SOURCE_OUTPUT_INIT
] = "INIT",
240 [PA_SOURCE_OUTPUT_RUNNING
] = "RUNNING",
241 [PA_SOURCE_OUTPUT_CORKED
] = "CORKED",
242 [PA_SOURCE_OUTPUT_UNLINKED
] = "UNLINKED"
248 pa_strbuf_printf(s
, "%u source outputs(s) available.\n", pa_idxset_size(c
->source_outputs
));
250 for (o
= pa_idxset_first(c
->source_outputs
, &idx
); o
; o
= pa_idxset_next(c
->source_outputs
, &idx
)) {
251 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
], *t
;
253 pa_assert(o
->source
);
259 "\tflags: %s%s%s%s%s%s%s%s\n"
261 "\tsource: <%u> '%s'\n"
262 "\tlatency: <%0.0f usec>\n"
263 "\tsample spec: <%s>\n"
264 "\tchannel map: <%s>\n"
265 "\tresample method: %s\n",
268 o
->flags
& PA_SOURCE_OUTPUT_VARIABLE_RATE
? "VARIABLE_RATE " : "",
269 o
->flags
& PA_SOURCE_OUTPUT_DONT_MOVE
? "DONT_MOVE " : "",
270 o
->flags
& PA_SOURCE_OUTPUT_START_CORKED
? "START_CORKED " : "",
271 o
->flags
& PA_SOURCE_OUTPUT_NO_REMAP
? "NO_REMAP " : "",
272 o
->flags
& PA_SOURCE_OUTPUT_NO_REMIX
? "NO_REMIX " : "",
273 o
->flags
& PA_SOURCE_OUTPUT_FIX_FORMAT
? "FIX_FORMAT " : "",
274 o
->flags
& PA_SOURCE_OUTPUT_FIX_RATE
? "FIX_RATE " : "",
275 o
->flags
& PA_SOURCE_OUTPUT_FIX_CHANNELS
? "FIX_CHANNELS " : "",
276 state_table
[pa_source_output_get_state(o
)],
277 o
->source
->index
, o
->source
->name
,
278 (double) pa_source_output_get_latency(o
),
279 pa_sample_spec_snprint(ss
, sizeof(ss
), &o
->sample_spec
),
280 pa_channel_map_snprint(cm
, sizeof(cm
), &o
->channel_map
),
281 pa_resample_method_to_string(pa_source_output_get_resample_method(o
)));
283 pa_strbuf_printf(s
, "\towner module: <%u>\n", o
->module
->index
);
285 pa_strbuf_printf(s
, "\tclient: <%u> '%s'\n", o
->client
->index
, pa_strnull(pa_proplist_gets(o
->client
->proplist
, PA_PROP_APPLICATION_NAME
)));
287 t
= pa_proplist_to_string(o
->proplist
);
288 pa_strbuf_printf(s
, "\tproperties:\n%s", t
);
292 return pa_strbuf_tostring_free(s
);
295 char *pa_sink_input_list_to_string(pa_core
*c
) {
298 uint32_t idx
= PA_IDXSET_INVALID
;
299 static const char* const state_table
[] = {
300 [PA_SINK_INPUT_INIT
] = "INIT",
301 [PA_SINK_INPUT_RUNNING
] = "RUNNING",
302 [PA_SINK_INPUT_DRAINED
] = "DRAINED",
303 [PA_SINK_INPUT_CORKED
] = "CORKED",
304 [PA_SINK_INPUT_UNLINKED
] = "UNLINKED"
310 pa_strbuf_printf(s
, "%u sink input(s) available.\n", pa_idxset_size(c
->sink_inputs
));
312 for (i
= pa_idxset_first(c
->sink_inputs
, &idx
); i
; i
= pa_idxset_next(c
->sink_inputs
, &idx
)) {
313 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cv
[PA_CVOLUME_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
], *t
;
321 "\tflags: %s%s%s%s%s%s%s%s\n"
323 "\tsink: <%u> '%s'\n"
326 "\tlatency: <%0.0f usec>\n"
327 "\tsample spec: <%s>\n"
328 "\tchannel map: <%s>\n"
329 "\tresample method: %s\n",
332 i
->flags
& PA_SINK_INPUT_VARIABLE_RATE
? "VARIABLE_RATE " : "",
333 i
->flags
& PA_SINK_INPUT_DONT_MOVE
? "DONT_MOVE " : "",
334 i
->flags
& PA_SINK_INPUT_START_CORKED
? "START_CORKED " : "",
335 i
->flags
& PA_SINK_INPUT_NO_REMAP
? "NO_REMAP " : "",
336 i
->flags
& PA_SINK_INPUT_NO_REMIX
? "NO_REMIX " : "",
337 i
->flags
& PA_SINK_INPUT_FIX_FORMAT
? "FIX_FORMAT " : "",
338 i
->flags
& PA_SINK_INPUT_FIX_RATE
? "FIX_RATE " : "",
339 i
->flags
& PA_SINK_INPUT_FIX_CHANNELS
? "FIX_CHANNELS " : "",
340 state_table
[pa_sink_input_get_state(i
)],
341 i
->sink
->index
, i
->sink
->name
,
342 pa_cvolume_snprint(cv
, sizeof(cv
), pa_sink_input_get_volume(i
)),
343 !!pa_sink_input_get_mute(i
),
344 (double) pa_sink_input_get_latency(i
),
345 pa_sample_spec_snprint(ss
, sizeof(ss
), &i
->sample_spec
),
346 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
347 pa_resample_method_to_string(pa_sink_input_get_resample_method(i
)));
350 pa_strbuf_printf(s
, "\tmodule: <%u>\n", i
->module
->index
);
352 pa_strbuf_printf(s
, "\tclient: <%u> '%s'\n", i
->client
->index
, pa_strnull(pa_proplist_gets(i
->client
->proplist
, PA_PROP_APPLICATION_NAME
)));
354 t
= pa_proplist_to_string(i
->proplist
);
355 pa_strbuf_printf(s
, "\tproperties:\n%s", t
);
359 return pa_strbuf_tostring_free(s
);
362 char *pa_scache_list_to_string(pa_core
*c
) {
368 pa_strbuf_printf(s
, "%u cache entries available.\n", c
->scache
? pa_idxset_size(c
->scache
) : 0);
372 uint32_t idx
= PA_IDXSET_INVALID
;
374 for (e
= pa_idxset_first(c
->scache
, &idx
); e
; e
= pa_idxset_next(c
->scache
, &idx
)) {
376 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
] = "n/a", cv
[PA_CVOLUME_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
] = "n/a", *t
;
378 if (e
->memchunk
.memblock
) {
379 pa_sample_spec_snprint(ss
, sizeof(ss
), &e
->sample_spec
);
380 pa_channel_map_snprint(cm
, sizeof(cm
), &e
->channel_map
);
381 l
= (double) e
->memchunk
.length
/ pa_bytes_per_second(&e
->sample_spec
);
388 "\tsample spec: <%s>\n"
389 "\tchannel map: <%s>\n"
391 "\tduration: <%0.1fs>\n"
399 (long unsigned)(e
->memchunk
.memblock
? e
->memchunk
.length
: 0),
401 pa_cvolume_snprint(cv
, sizeof(cv
), &e
->volume
),
403 e
->filename
? e
->filename
: "n/a");
405 t
= pa_proplist_to_string(e
->proplist
);
406 pa_strbuf_printf(s
, "\tproperties:\n%s", t
);
411 return pa_strbuf_tostring_free(s
);
414 char *pa_autoload_list_to_string(pa_core
*c
) {
420 pa_strbuf_printf(s
, "%u autoload entries available.\n", c
->autoload_hashmap
? pa_hashmap_size(c
->autoload_hashmap
) : 0);
422 if (c
->autoload_hashmap
) {
423 pa_autoload_entry
*e
;
426 while ((e
= pa_hashmap_iterate(c
->autoload_hashmap
, &state
, NULL
))) {
428 s
, " name: <%s>\n\ttype: <%s>\n\tindex: <%u>\n\tmodule_name: <%s>\n\targuments: <%s>\n",
430 e
->type
== PA_NAMEREG_SOURCE
? "source" : "sink",
433 e
->argument
? e
->argument
: "");
438 return pa_strbuf_tostring_free(s
);
441 char *pa_full_status_string(pa_core
*c
) {
447 for (i
= 0; i
< 8; i
++) {
452 t
= pa_sink_list_to_string(c
);
455 t
= pa_source_list_to_string(c
);
458 t
= pa_sink_input_list_to_string(c
);
461 t
= pa_source_output_list_to_string(c
);
464 t
= pa_client_list_to_string(c
);
467 t
= pa_module_list_to_string(c
);
470 t
= pa_scache_list_to_string(c
);
473 t
= pa_autoload_list_to_string(c
);
477 pa_strbuf_puts(s
, t
);
481 return pa_strbuf_tostring_free(s
);