2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <pulse/volume.h>
29 #include <pulse/xmalloc.h>
30 #include <pulse/timeval.h>
32 #include <pulsecore/module.h>
33 #include <pulsecore/client.h>
34 #include <pulsecore/sink.h>
35 #include <pulsecore/source.h>
36 #include <pulsecore/sink-input.h>
37 #include <pulsecore/source-output.h>
38 #include <pulsecore/strbuf.h>
39 #include <pulsecore/sample-util.h>
40 #include <pulsecore/core-scache.h>
41 #include <pulsecore/autoload.h>
42 #include <pulsecore/macro.h>
43 #include <pulsecore/core-util.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 pa_yes_no(m
->auto_unload
));
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
)) {
90 pa_strbuf_printf(s
, "\towner module: %u\n", client
->module
->index
);
92 t
= pa_proplist_to_string(client
->proplist
);
93 pa_strbuf_printf(s
, "\tproperties:\n%s", t
);
97 return pa_strbuf_tostring_free(s
);
100 char *pa_sink_list_to_string(pa_core
*c
) {
103 uint32_t idx
= PA_IDXSET_INVALID
;
104 static const char* const state_table
[] = {
105 [PA_SINK_INIT
] = "INIT",
106 [PA_SINK_RUNNING
] = "RUNNING",
107 [PA_SINK_SUSPENDED
] = "SUSPENDED",
108 [PA_SINK_IDLE
] = "IDLE",
109 [PA_SINK_UNLINKED
] = "UNLINKED"
115 pa_strbuf_printf(s
, "%u sink(s) available.\n", pa_idxset_size(c
->sinks
));
117 for (sink
= pa_idxset_first(c
->sinks
, &idx
); sink
; sink
= pa_idxset_next(c
->sinks
, &idx
)) {
118 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
119 cv
[PA_CVOLUME_SNPRINT_MAX
],
120 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
121 v
[PA_VOLUME_SNPRINT_MAX
],
122 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
123 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
], *t
;
124 pa_usec_t min_latency
, max_latency
;
126 pa_sink_get_latency_range(sink
, &min_latency
, &max_latency
);
133 "\tflags: %s%s%s%s%s%s\n"
136 "\tbase volume: %s%s%s\n"
138 "\tcurrent latency: %0.2f ms\n"
139 "\tconfigured latency: %0.2f ms; range is %0.2f .. %0.2f ms\n"
140 "\tmax request: %lu KiB\n"
141 "\tmax rewind: %lu KiB\n"
142 "\tmonitor source: %u\n"
143 "\tsample spec: %s\n"
144 "\tchannel map: %s\n"
147 c
->default_sink_name
&& !strcmp(sink
->name
, c
->default_sink_name
) ? '*' : ' ',
151 sink
->flags
& PA_SINK_HARDWARE
? "HARDWARE " : "",
152 sink
->flags
& PA_SINK_NETWORK
? "NETWORK " : "",
153 sink
->flags
& PA_SINK_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
154 sink
->flags
& PA_SINK_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
155 sink
->flags
& PA_SINK_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
156 sink
->flags
& PA_SINK_LATENCY
? "LATENCY " : "",
157 state_table
[pa_sink_get_state(sink
)],
158 pa_cvolume_snprint(cv
, sizeof(cv
), pa_sink_get_volume(sink
, FALSE
)),
159 sink
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
160 sink
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), pa_sink_get_volume(sink
, FALSE
)) : "",
161 pa_volume_snprint(v
, sizeof(v
), sink
->base_volume
),
162 sink
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
163 sink
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), sink
->base_volume
) : "",
164 pa_yes_no(pa_sink_get_mute(sink
, FALSE
)),
165 (double) pa_sink_get_latency(sink
) / (double) PA_USEC_PER_MSEC
,
166 (double) pa_sink_get_requested_latency(sink
) / (double) PA_USEC_PER_MSEC
,
167 (double) min_latency
/ PA_USEC_PER_MSEC
,
168 (double) max_latency
/ PA_USEC_PER_MSEC
,
169 (unsigned long) pa_sink_get_max_request(sink
) / 1024,
170 (unsigned long) pa_sink_get_max_rewind(sink
) / 1024,
171 sink
->monitor_source
? sink
->monitor_source
->index
: PA_INVALID_INDEX
,
172 pa_sample_spec_snprint(ss
, sizeof(ss
), &sink
->sample_spec
),
173 pa_channel_map_snprint(cm
, sizeof(cm
), &sink
->channel_map
),
174 pa_sink_used_by(sink
),
175 pa_sink_linked_by(sink
));
178 pa_strbuf_printf(s
, "\tmodule: %u\n", sink
->module
->index
);
180 t
= pa_proplist_to_string(sink
->proplist
);
181 pa_strbuf_printf(s
, "\tproperties:\n%s", t
);
185 return pa_strbuf_tostring_free(s
);
188 char *pa_source_list_to_string(pa_core
*c
) {
191 uint32_t idx
= PA_IDXSET_INVALID
;
192 static const char* const state_table
[] = {
193 [PA_SOURCE_INIT
] = "INIT",
194 [PA_SOURCE_RUNNING
] = "RUNNING",
195 [PA_SOURCE_SUSPENDED
] = "SUSPENDED",
196 [PA_SOURCE_IDLE
] = "IDLE",
197 [PA_SOURCE_UNLINKED
] = "UNLINKED"
203 pa_strbuf_printf(s
, "%u source(s) available.\n", pa_idxset_size(c
->sources
));
205 for (source
= pa_idxset_first(c
->sources
, &idx
); source
; source
= pa_idxset_next(c
->sources
, &idx
)) {
206 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
207 cv
[PA_CVOLUME_SNPRINT_MAX
],
208 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
209 v
[PA_VOLUME_SNPRINT_MAX
],
210 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
211 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
], *t
;
212 pa_usec_t min_latency
, max_latency
;
214 pa_source_get_latency_range(source
, &min_latency
, &max_latency
);
221 "\tflags: %s%s%s%s%s%s\n"
224 "\tbase volume: %s%s%s\n"
226 "\tcurrent latency: %0.2f ms\n"
227 "\tconfigured latency: %0.2f ms; range is %0.2f .. %0.2f ms\n"
228 "\tmax rewind: %lu KiB\n"
229 "\tsample spec: %s\n"
230 "\tchannel map: %s\n"
233 c
->default_source_name
&& !strcmp(source
->name
, c
->default_source_name
) ? '*' : ' ',
237 source
->flags
& PA_SOURCE_HARDWARE
? "HARDWARE " : "",
238 source
->flags
& PA_SOURCE_NETWORK
? "NETWORK " : "",
239 source
->flags
& PA_SOURCE_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
240 source
->flags
& PA_SOURCE_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
241 source
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
242 source
->flags
& PA_SOURCE_LATENCY
? "LATENCY " : "",
243 state_table
[pa_source_get_state(source
)],
244 pa_cvolume_snprint(cv
, sizeof(cv
), pa_source_get_volume(source
, FALSE
)),
245 source
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
246 source
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), pa_source_get_volume(source
, FALSE
)) : "",
247 pa_volume_snprint(v
, sizeof(v
), source
->base_volume
),
248 source
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
249 source
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), source
->base_volume
) : "",
250 pa_yes_no(pa_source_get_mute(source
, FALSE
)),
251 (double) pa_source_get_latency(source
) / PA_USEC_PER_MSEC
,
252 (double) pa_source_get_requested_latency(source
) / PA_USEC_PER_MSEC
,
253 (double) min_latency
/ PA_USEC_PER_MSEC
,
254 (double) max_latency
/ PA_USEC_PER_MSEC
,
255 (unsigned long) pa_source_get_max_rewind(source
) / 1024,
256 pa_sample_spec_snprint(ss
, sizeof(ss
), &source
->sample_spec
),
257 pa_channel_map_snprint(cm
, sizeof(cm
), &source
->channel_map
),
258 pa_source_used_by(source
),
259 pa_source_linked_by(source
));
261 if (source
->monitor_of
)
262 pa_strbuf_printf(s
, "\tmonitor_of: %u\n", source
->monitor_of
->index
);
264 pa_strbuf_printf(s
, "\tmodule: %u\n", source
->module
->index
);
266 t
= pa_proplist_to_string(source
->proplist
);
267 pa_strbuf_printf(s
, "\tproperties:\n%s", t
);
271 return pa_strbuf_tostring_free(s
);
275 char *pa_source_output_list_to_string(pa_core
*c
) {
278 uint32_t idx
= PA_IDXSET_INVALID
;
279 static const char* const state_table
[] = {
280 [PA_SOURCE_OUTPUT_INIT
] = "INIT",
281 [PA_SOURCE_OUTPUT_RUNNING
] = "RUNNING",
282 [PA_SOURCE_OUTPUT_CORKED
] = "CORKED",
283 [PA_SOURCE_OUTPUT_UNLINKED
] = "UNLINKED"
289 pa_strbuf_printf(s
, "%u source outputs(s) available.\n", pa_idxset_size(c
->source_outputs
));
291 for (o
= pa_idxset_first(c
->source_outputs
, &idx
); o
; o
= pa_idxset_next(c
->source_outputs
, &idx
)) {
292 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
], *t
, clt
[28];
295 if ((cl
= pa_source_output_get_requested_latency(o
)) == (pa_usec_t
) -1)
296 pa_snprintf(clt
, sizeof(clt
), "n/a");
298 pa_snprintf(clt
, sizeof(clt
), "%0.2f ms", (double) cl
/ PA_USEC_PER_MSEC
);
300 pa_assert(o
->source
);
306 "\tflags: %s%s%s%s%s%s%s%s\n"
308 "\tsource: %u <%s>\n"
309 "\tcurrent latency: %0.2f ms\n"
310 "\trequested latency: %s\n"
311 "\tsample spec: %s\n"
312 "\tchannel map: %s\n"
313 "\tresample method: %s\n",
316 o
->flags
& PA_SOURCE_OUTPUT_VARIABLE_RATE
? "VARIABLE_RATE " : "",
317 o
->flags
& PA_SOURCE_OUTPUT_DONT_MOVE
? "DONT_MOVE " : "",
318 o
->flags
& PA_SOURCE_OUTPUT_START_CORKED
? "START_CORKED " : "",
319 o
->flags
& PA_SOURCE_OUTPUT_NO_REMAP
? "NO_REMAP " : "",
320 o
->flags
& PA_SOURCE_OUTPUT_NO_REMIX
? "NO_REMIX " : "",
321 o
->flags
& PA_SOURCE_OUTPUT_FIX_FORMAT
? "FIX_FORMAT " : "",
322 o
->flags
& PA_SOURCE_OUTPUT_FIX_RATE
? "FIX_RATE " : "",
323 o
->flags
& PA_SOURCE_OUTPUT_FIX_CHANNELS
? "FIX_CHANNELS " : "",
324 state_table
[pa_source_output_get_state(o
)],
325 o
->source
->index
, o
->source
->name
,
326 (double) pa_source_output_get_latency(o
, NULL
) / PA_USEC_PER_MSEC
,
328 pa_sample_spec_snprint(ss
, sizeof(ss
), &o
->sample_spec
),
329 pa_channel_map_snprint(cm
, sizeof(cm
), &o
->channel_map
),
330 pa_resample_method_to_string(pa_source_output_get_resample_method(o
)));
332 pa_strbuf_printf(s
, "\towner module: %u\n", o
->module
->index
);
334 pa_strbuf_printf(s
, "\tclient: %u <%s>\n", o
->client
->index
, pa_strnull(pa_proplist_gets(o
->client
->proplist
, PA_PROP_APPLICATION_NAME
)));
335 if (o
->direct_on_input
)
336 pa_strbuf_printf(s
, "\tdirect on input: %u\n", o
->direct_on_input
->index
);
338 t
= pa_proplist_to_string(o
->proplist
);
339 pa_strbuf_printf(s
, "\tproperties:\n%s", t
);
343 return pa_strbuf_tostring_free(s
);
346 char *pa_sink_input_list_to_string(pa_core
*c
) {
349 uint32_t idx
= PA_IDXSET_INVALID
;
350 static const char* const state_table
[] = {
351 [PA_SINK_INPUT_INIT
] = "INIT",
352 [PA_SINK_INPUT_RUNNING
] = "RUNNING",
353 [PA_SINK_INPUT_DRAINED
] = "DRAINED",
354 [PA_SINK_INPUT_CORKED
] = "CORKED",
355 [PA_SINK_INPUT_UNLINKED
] = "UNLINKED"
361 pa_strbuf_printf(s
, "%u sink input(s) available.\n", pa_idxset_size(c
->sink_inputs
));
363 for (i
= pa_idxset_first(c
->sink_inputs
, &idx
); i
; i
= pa_idxset_next(c
->sink_inputs
, &idx
)) {
364 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cv
[PA_CVOLUME_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
], *t
, clt
[28];
367 if ((cl
= pa_sink_input_get_requested_latency(i
)) == (pa_usec_t
) -1)
368 pa_snprintf(clt
, sizeof(clt
), "n/a");
370 pa_snprintf(clt
, sizeof(clt
), "%0.2f ms", (double) cl
/ PA_USEC_PER_MSEC
);
378 "\tflags: %s%s%s%s%s%s%s%s\n"
383 "\tcurrent latency: %0.2f ms\n"
384 "\trequested latency: %s\n"
385 "\tsample spec: %s\n"
386 "\tchannel map: %s\n"
387 "\tresample method: %s\n",
390 i
->flags
& PA_SINK_INPUT_VARIABLE_RATE
? "VARIABLE_RATE " : "",
391 i
->flags
& PA_SINK_INPUT_DONT_MOVE
? "DONT_MOVE " : "",
392 i
->flags
& PA_SINK_INPUT_START_CORKED
? "START_CORKED " : "",
393 i
->flags
& PA_SINK_INPUT_NO_REMAP
? "NO_REMAP " : "",
394 i
->flags
& PA_SINK_INPUT_NO_REMIX
? "NO_REMIX " : "",
395 i
->flags
& PA_SINK_INPUT_FIX_FORMAT
? "FIX_FORMAT " : "",
396 i
->flags
& PA_SINK_INPUT_FIX_RATE
? "FIX_RATE " : "",
397 i
->flags
& PA_SINK_INPUT_FIX_CHANNELS
? "FIX_CHANNELS " : "",
398 state_table
[pa_sink_input_get_state(i
)],
399 i
->sink
->index
, i
->sink
->name
,
400 pa_cvolume_snprint(cv
, sizeof(cv
), pa_sink_input_get_volume(i
)),
401 pa_yes_no(pa_sink_input_get_mute(i
)),
402 (double) pa_sink_input_get_latency(i
, NULL
) / PA_USEC_PER_MSEC
,
404 pa_sample_spec_snprint(ss
, sizeof(ss
), &i
->sample_spec
),
405 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
406 pa_resample_method_to_string(pa_sink_input_get_resample_method(i
)));
409 pa_strbuf_printf(s
, "\tmodule: %u\n", i
->module
->index
);
411 pa_strbuf_printf(s
, "\tclient: %u <%s>\n", i
->client
->index
, pa_strnull(pa_proplist_gets(i
->client
->proplist
, PA_PROP_APPLICATION_NAME
)));
413 t
= pa_proplist_to_string(i
->proplist
);
414 pa_strbuf_printf(s
, "\tproperties:\n%s", t
);
418 return pa_strbuf_tostring_free(s
);
421 char *pa_scache_list_to_string(pa_core
*c
) {
427 pa_strbuf_printf(s
, "%u cache entries available.\n", c
->scache
? pa_idxset_size(c
->scache
) : 0);
431 uint32_t idx
= PA_IDXSET_INVALID
;
433 for (e
= pa_idxset_first(c
->scache
, &idx
); e
; e
= pa_idxset_next(c
->scache
, &idx
)) {
435 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
] = "n/a", cv
[PA_CVOLUME_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
] = "n/a", *t
;
437 if (e
->memchunk
.memblock
) {
438 pa_sample_spec_snprint(ss
, sizeof(ss
), &e
->sample_spec
);
439 pa_channel_map_snprint(cm
, sizeof(cm
), &e
->channel_map
);
440 l
= (double) e
->memchunk
.length
/ (double) pa_bytes_per_second(&e
->sample_spec
);
447 "\tsample spec: %s\n"
448 "\tchannel map: %s\n"
450 "\tduration: %0.1f s\n"
453 "\tfilename: <%s>\n",
458 (long unsigned)(e
->memchunk
.memblock
? e
->memchunk
.length
: 0),
460 pa_cvolume_snprint(cv
, sizeof(cv
), &e
->volume
),
462 e
->filename
? e
->filename
: "n/a");
464 t
= pa_proplist_to_string(e
->proplist
);
465 pa_strbuf_printf(s
, "\tproperties:\n%s", t
);
470 return pa_strbuf_tostring_free(s
);
473 char *pa_autoload_list_to_string(pa_core
*c
) {
479 pa_strbuf_printf(s
, "%u autoload entries available.\n", c
->autoload_hashmap
? pa_hashmap_size(c
->autoload_hashmap
) : 0);
481 if (c
->autoload_hashmap
) {
482 pa_autoload_entry
*e
;
485 while ((e
= pa_hashmap_iterate(c
->autoload_hashmap
, &state
, NULL
))) {
491 "\tmodule_name: <%s>\n"
492 "\targuments: <%s>\n",
494 e
->type
== PA_NAMEREG_SOURCE
? "source" : "sink",
497 e
->argument
? e
->argument
: "");
502 return pa_strbuf_tostring_free(s
);
505 char *pa_full_status_string(pa_core
*c
) {
511 for (i
= 0; i
< 8; i
++) {
516 t
= pa_sink_list_to_string(c
);
519 t
= pa_source_list_to_string(c
);
522 t
= pa_sink_input_list_to_string(c
);
525 t
= pa_source_output_list_to_string(c
);
528 t
= pa_client_list_to_string(c
);
531 t
= pa_module_list_to_string(c
);
534 t
= pa_scache_list_to_string(c
);
537 t
= pa_autoload_list_to_string(c
);
541 pa_strbuf_puts(s
, t
);
545 return pa_strbuf_tostring_free(s
);