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/macro.h>
42 #include <pulsecore/core-util.h>
46 char *pa_module_list_to_string(pa_core
*c
) {
49 uint32_t idx
= PA_IDXSET_INVALID
;
54 pa_strbuf_printf(s
, "%u module(s) loaded.\n", pa_idxset_size(c
->modules
));
56 for (m
= pa_idxset_first(c
->modules
, &idx
); m
; m
= pa_idxset_next(c
->modules
, &idx
)) {
59 pa_strbuf_printf(s
, " index: %u\n"
66 pa_strempty(m
->argument
),
67 pa_module_get_n_used(m
),
68 pa_yes_no(m
->load_once
));
70 t
= pa_proplist_to_string_sep(m
->proplist
, "\n\t\t");
71 pa_strbuf_printf(s
, "\tproperties:\n\t\t%s\n", t
);
75 return pa_strbuf_tostring_free(s
);
78 char *pa_client_list_to_string(pa_core
*c
) {
81 uint32_t idx
= PA_IDXSET_INVALID
;
86 pa_strbuf_printf(s
, "%u client(s) logged in.\n", pa_idxset_size(c
->clients
));
88 for (client
= pa_idxset_first(c
->clients
, &idx
); client
; client
= pa_idxset_next(c
->clients
, &idx
)) {
98 pa_strbuf_printf(s
, "\towner module: %u\n", client
->module
->index
);
100 t
= pa_proplist_to_string_sep(client
->proplist
, "\n\t\t");
101 pa_strbuf_printf(s
, "\tproperties:\n\t\t%s\n", t
);
105 return pa_strbuf_tostring_free(s
);
108 char *pa_card_list_to_string(pa_core
*c
) {
111 uint32_t idx
= PA_IDXSET_INVALID
;
116 pa_strbuf_printf(s
, "%u card(s) available.\n", pa_idxset_size(c
->cards
));
118 for (card
= pa_idxset_first(c
->cards
, &idx
); card
; card
= pa_idxset_next(c
->cards
, &idx
)) {
130 pa_strbuf_printf(s
, "\towner module: %u\n", card
->module
->index
);
132 t
= pa_proplist_to_string_sep(card
->proplist
, "\n\t\t");
133 pa_strbuf_printf(s
, "\tproperties:\n\t\t%s\n", t
);
136 if (card
->profiles
) {
144 while ((p
= pa_hashmap_iterate(card
->profiles
, &state
, NULL
)))
145 pa_strbuf_printf(s
, "\t\t%s: %s (priority %u)\n", p
->name
, p
->description
, p
->priority
);
148 if (card
->active_profile
)
151 "\tactive profile: <%s>\n",
152 card
->active_profile
->name
);
155 return pa_strbuf_tostring_free(s
);
158 static const char *sink_state_to_string(pa_sink_state_t state
) {
162 case PA_SINK_RUNNING
:
164 case PA_SINK_SUSPENDED
:
168 case PA_SINK_UNLINKED
:
175 static const char *source_state_to_string(pa_source_state_t state
) {
179 case PA_SOURCE_RUNNING
:
181 case PA_SOURCE_SUSPENDED
:
185 case PA_SOURCE_UNLINKED
:
192 char *pa_sink_list_to_string(pa_core
*c
) {
195 uint32_t idx
= PA_IDXSET_INVALID
;
200 pa_strbuf_printf(s
, "%u sink(s) available.\n", pa_idxset_size(c
->sinks
));
202 for (sink
= pa_idxset_first(c
->sinks
, &idx
); sink
; sink
= pa_idxset_next(c
->sinks
, &idx
)) {
203 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
204 cv
[PA_CVOLUME_SNPRINT_MAX
],
205 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
206 v
[PA_VOLUME_SNPRINT_MAX
],
207 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
208 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
], *t
;
209 pa_usec_t min_latency
, max_latency
;
211 pa_sink_get_latency_range(sink
, &min_latency
, &max_latency
);
218 "\tflags: %s%s%s%s%s%s\n"
222 "\tbase volume: %s%s%s\n"
224 "\tcurrent latency: %0.2f ms\n"
225 "\tconfigured latency: %0.2f ms; range is %0.2f .. %0.2f ms\n"
226 "\tmax request: %lu KiB\n"
227 "\tmax rewind: %lu KiB\n"
228 "\tmonitor source: %u\n"
229 "\tsample spec: %s\n"
230 "\tchannel map: %s\n"
233 c
->default_sink_name
&& !strcmp(sink
->name
, c
->default_sink_name
) ? '*' : ' ',
237 sink
->flags
& PA_SINK_HARDWARE
? "HARDWARE " : "",
238 sink
->flags
& PA_SINK_NETWORK
? "NETWORK " : "",
239 sink
->flags
& PA_SINK_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
240 sink
->flags
& PA_SINK_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
241 sink
->flags
& PA_SINK_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
242 sink
->flags
& PA_SINK_LATENCY
? "LATENCY " : "",
243 sink_state_to_string(pa_sink_get_state(sink
)),
244 pa_cvolume_snprint(cv
, sizeof(cv
), pa_sink_get_volume(sink
, FALSE
)),
245 sink
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
246 sink
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), pa_sink_get_volume(sink
, FALSE
)) : "",
247 pa_cvolume_get_balance(&sink
->channel_map
, pa_sink_get_volume(sink
, FALSE
)),
248 pa_volume_snprint(v
, sizeof(v
), sink
->base_volume
),
249 sink
->flags
& PA_SINK_DECIBEL_VOLUME
? "\n\t " : "",
250 sink
->flags
& PA_SINK_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), sink
->base_volume
) : "",
251 pa_yes_no(pa_sink_get_mute(sink
, FALSE
)),
252 (double) pa_sink_get_latency(sink
) / (double) PA_USEC_PER_MSEC
,
253 (double) pa_sink_get_requested_latency(sink
) / (double) PA_USEC_PER_MSEC
,
254 (double) min_latency
/ PA_USEC_PER_MSEC
,
255 (double) max_latency
/ PA_USEC_PER_MSEC
,
256 (unsigned long) pa_sink_get_max_request(sink
) / 1024,
257 (unsigned long) pa_sink_get_max_rewind(sink
) / 1024,
258 sink
->monitor_source
? sink
->monitor_source
->index
: PA_INVALID_INDEX
,
259 pa_sample_spec_snprint(ss
, sizeof(ss
), &sink
->sample_spec
),
260 pa_channel_map_snprint(cm
, sizeof(cm
), &sink
->channel_map
),
261 pa_sink_used_by(sink
),
262 pa_sink_linked_by(sink
));
265 pa_strbuf_printf(s
, "\tcard: %u <%s>\n", sink
->card
->index
, sink
->card
->name
);
267 pa_strbuf_printf(s
, "\tmodule: %u\n", sink
->module
->index
);
269 t
= pa_proplist_to_string_sep(sink
->proplist
, "\n\t\t");
270 pa_strbuf_printf(s
, "\tproperties:\n\t\t%s\n", t
);
274 return pa_strbuf_tostring_free(s
);
277 char *pa_source_list_to_string(pa_core
*c
) {
280 uint32_t idx
= PA_IDXSET_INVALID
;
285 pa_strbuf_printf(s
, "%u source(s) available.\n", pa_idxset_size(c
->sources
));
287 for (source
= pa_idxset_first(c
->sources
, &idx
); source
; source
= pa_idxset_next(c
->sources
, &idx
)) {
288 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
],
289 cv
[PA_CVOLUME_SNPRINT_MAX
],
290 cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
],
291 v
[PA_VOLUME_SNPRINT_MAX
],
292 vdb
[PA_SW_VOLUME_SNPRINT_DB_MAX
],
293 cm
[PA_CHANNEL_MAP_SNPRINT_MAX
], *t
;
294 pa_usec_t min_latency
, max_latency
;
296 pa_source_get_latency_range(source
, &min_latency
, &max_latency
);
303 "\tflags: %s%s%s%s%s%s\n"
307 "\tbase volume: %s%s%s\n"
309 "\tcurrent latency: %0.2f ms\n"
310 "\tconfigured latency: %0.2f ms; range is %0.2f .. %0.2f ms\n"
311 "\tmax rewind: %lu KiB\n"
312 "\tsample spec: %s\n"
313 "\tchannel map: %s\n"
316 c
->default_source_name
&& !strcmp(source
->name
, c
->default_source_name
) ? '*' : ' ',
320 source
->flags
& PA_SOURCE_HARDWARE
? "HARDWARE " : "",
321 source
->flags
& PA_SOURCE_NETWORK
? "NETWORK " : "",
322 source
->flags
& PA_SOURCE_HW_MUTE_CTRL
? "HW_MUTE_CTRL " : "",
323 source
->flags
& PA_SOURCE_HW_VOLUME_CTRL
? "HW_VOLUME_CTRL " : "",
324 source
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "DECIBEL_VOLUME " : "",
325 source
->flags
& PA_SOURCE_LATENCY
? "LATENCY " : "",
326 source_state_to_string(pa_source_get_state(source
)),
327 pa_cvolume_snprint(cv
, sizeof(cv
), pa_source_get_volume(source
, FALSE
)),
328 source
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
329 source
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), pa_source_get_volume(source
, FALSE
)) : "",
330 pa_cvolume_get_balance(&source
->channel_map
, pa_source_get_volume(source
, FALSE
)),
331 pa_volume_snprint(v
, sizeof(v
), source
->base_volume
),
332 source
->flags
& PA_SOURCE_DECIBEL_VOLUME
? "\n\t " : "",
333 source
->flags
& PA_SOURCE_DECIBEL_VOLUME
? pa_sw_volume_snprint_dB(vdb
, sizeof(vdb
), source
->base_volume
) : "",
334 pa_yes_no(pa_source_get_mute(source
, FALSE
)),
335 (double) pa_source_get_latency(source
) / PA_USEC_PER_MSEC
,
336 (double) pa_source_get_requested_latency(source
) / PA_USEC_PER_MSEC
,
337 (double) min_latency
/ PA_USEC_PER_MSEC
,
338 (double) max_latency
/ PA_USEC_PER_MSEC
,
339 (unsigned long) pa_source_get_max_rewind(source
) / 1024,
340 pa_sample_spec_snprint(ss
, sizeof(ss
), &source
->sample_spec
),
341 pa_channel_map_snprint(cm
, sizeof(cm
), &source
->channel_map
),
342 pa_source_used_by(source
),
343 pa_source_linked_by(source
));
345 if (source
->monitor_of
)
346 pa_strbuf_printf(s
, "\tmonitor_of: %u\n", source
->monitor_of
->index
);
348 pa_strbuf_printf(s
, "\tcard: %u <%s>\n", source
->card
->index
, source
->card
->name
);
350 pa_strbuf_printf(s
, "\tmodule: %u\n", source
->module
->index
);
352 t
= pa_proplist_to_string_sep(source
->proplist
, "\n\t\t");
353 pa_strbuf_printf(s
, "\tproperties:\n\t\t%s\n", t
);
357 return pa_strbuf_tostring_free(s
);
361 char *pa_source_output_list_to_string(pa_core
*c
) {
364 uint32_t idx
= PA_IDXSET_INVALID
;
365 static const char* const state_table
[] = {
366 [PA_SOURCE_OUTPUT_INIT
] = "INIT",
367 [PA_SOURCE_OUTPUT_RUNNING
] = "RUNNING",
368 [PA_SOURCE_OUTPUT_CORKED
] = "CORKED",
369 [PA_SOURCE_OUTPUT_UNLINKED
] = "UNLINKED"
375 pa_strbuf_printf(s
, "%u source outputs(s) available.\n", pa_idxset_size(c
->source_outputs
));
377 for (o
= pa_idxset_first(c
->source_outputs
, &idx
); o
; o
= pa_idxset_next(c
->source_outputs
, &idx
)) {
378 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
], *t
, clt
[28];
381 if ((cl
= pa_source_output_get_requested_latency(o
)) == (pa_usec_t
) -1)
382 pa_snprintf(clt
, sizeof(clt
), "n/a");
384 pa_snprintf(clt
, sizeof(clt
), "%0.2f ms", (double) cl
/ PA_USEC_PER_MSEC
);
386 pa_assert(o
->source
);
392 "\tflags: %s%s%s%s%s%s%s%s\n"
394 "\tsource: %u <%s>\n"
395 "\tcurrent latency: %0.2f ms\n"
396 "\trequested latency: %s\n"
397 "\tsample spec: %s\n"
398 "\tchannel map: %s\n"
399 "\tresample method: %s\n",
402 o
->flags
& PA_SOURCE_OUTPUT_VARIABLE_RATE
? "VARIABLE_RATE " : "",
403 o
->flags
& PA_SOURCE_OUTPUT_DONT_MOVE
? "DONT_MOVE " : "",
404 o
->flags
& PA_SOURCE_OUTPUT_START_CORKED
? "START_CORKED " : "",
405 o
->flags
& PA_SOURCE_OUTPUT_NO_REMAP
? "NO_REMAP " : "",
406 o
->flags
& PA_SOURCE_OUTPUT_NO_REMIX
? "NO_REMIX " : "",
407 o
->flags
& PA_SOURCE_OUTPUT_FIX_FORMAT
? "FIX_FORMAT " : "",
408 o
->flags
& PA_SOURCE_OUTPUT_FIX_RATE
? "FIX_RATE " : "",
409 o
->flags
& PA_SOURCE_OUTPUT_FIX_CHANNELS
? "FIX_CHANNELS " : "",
410 state_table
[pa_source_output_get_state(o
)],
411 o
->source
->index
, o
->source
->name
,
412 (double) pa_source_output_get_latency(o
, NULL
) / PA_USEC_PER_MSEC
,
414 pa_sample_spec_snprint(ss
, sizeof(ss
), &o
->sample_spec
),
415 pa_channel_map_snprint(cm
, sizeof(cm
), &o
->channel_map
),
416 pa_resample_method_to_string(pa_source_output_get_resample_method(o
)));
418 pa_strbuf_printf(s
, "\towner module: %u\n", o
->module
->index
);
420 pa_strbuf_printf(s
, "\tclient: %u <%s>\n", o
->client
->index
, pa_strnull(pa_proplist_gets(o
->client
->proplist
, PA_PROP_APPLICATION_NAME
)));
421 if (o
->direct_on_input
)
422 pa_strbuf_printf(s
, "\tdirect on input: %u\n", o
->direct_on_input
->index
);
424 t
= pa_proplist_to_string_sep(o
->proplist
, "\n\t\t");
425 pa_strbuf_printf(s
, "\tproperties:\n\t\t%s\n", t
);
429 return pa_strbuf_tostring_free(s
);
432 char *pa_sink_input_list_to_string(pa_core
*c
) {
435 uint32_t idx
= PA_IDXSET_INVALID
;
436 static const char* const state_table
[] = {
437 [PA_SINK_INPUT_INIT
] = "INIT",
438 [PA_SINK_INPUT_RUNNING
] = "RUNNING",
439 [PA_SINK_INPUT_DRAINED
] = "DRAINED",
440 [PA_SINK_INPUT_CORKED
] = "CORKED",
441 [PA_SINK_INPUT_UNLINKED
] = "UNLINKED"
447 pa_strbuf_printf(s
, "%u sink input(s) available.\n", pa_idxset_size(c
->sink_inputs
));
449 for (i
= pa_idxset_first(c
->sink_inputs
, &idx
); i
; i
= pa_idxset_next(c
->sink_inputs
, &idx
)) {
450 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
], cv
[PA_CVOLUME_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
], *t
, clt
[28];
453 if ((cl
= pa_sink_input_get_requested_latency(i
)) == (pa_usec_t
) -1)
454 pa_snprintf(clt
, sizeof(clt
), "n/a");
456 pa_snprintf(clt
, sizeof(clt
), "%0.2f ms", (double) cl
/ PA_USEC_PER_MSEC
);
464 "\tflags: %s%s%s%s%s%s%s%s\n"
471 "\tcurrent latency: %0.2f ms\n"
472 "\trequested latency: %s\n"
473 "\tsample spec: %s\n"
474 "\tchannel map: %s\n"
475 "\tresample method: %s\n",
478 i
->flags
& PA_SINK_INPUT_VARIABLE_RATE
? "VARIABLE_RATE " : "",
479 i
->flags
& PA_SINK_INPUT_DONT_MOVE
? "DONT_MOVE " : "",
480 i
->flags
& PA_SINK_INPUT_START_CORKED
? "START_CORKED " : "",
481 i
->flags
& PA_SINK_INPUT_NO_REMAP
? "NO_REMAP " : "",
482 i
->flags
& PA_SINK_INPUT_NO_REMIX
? "NO_REMIX " : "",
483 i
->flags
& PA_SINK_INPUT_FIX_FORMAT
? "FIX_FORMAT " : "",
484 i
->flags
& PA_SINK_INPUT_FIX_RATE
? "FIX_RATE " : "",
485 i
->flags
& PA_SINK_INPUT_FIX_CHANNELS
? "FIX_CHANNELS " : "",
486 state_table
[pa_sink_input_get_state(i
)],
487 i
->sink
->index
, i
->sink
->name
,
488 pa_cvolume_snprint(cv
, sizeof(cv
), pa_sink_input_get_volume(i
)),
489 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), pa_sink_input_get_volume(i
)),
490 pa_cvolume_get_balance(&i
->channel_map
, pa_sink_input_get_volume(i
)),
491 pa_yes_no(pa_sink_input_get_mute(i
)),
492 (double) pa_sink_input_get_latency(i
, NULL
) / PA_USEC_PER_MSEC
,
494 pa_sample_spec_snprint(ss
, sizeof(ss
), &i
->sample_spec
),
495 pa_channel_map_snprint(cm
, sizeof(cm
), &i
->channel_map
),
496 pa_resample_method_to_string(pa_sink_input_get_resample_method(i
)));
499 pa_strbuf_printf(s
, "\tmodule: %u\n", i
->module
->index
);
501 pa_strbuf_printf(s
, "\tclient: %u <%s>\n", i
->client
->index
, pa_strnull(pa_proplist_gets(i
->client
->proplist
, PA_PROP_APPLICATION_NAME
)));
503 t
= pa_proplist_to_string_sep(i
->proplist
, "\n\t\t");
504 pa_strbuf_printf(s
, "\tproperties:\n\t\t%s\n", t
);
508 return pa_strbuf_tostring_free(s
);
511 char *pa_scache_list_to_string(pa_core
*c
) {
517 pa_strbuf_printf(s
, "%u cache entrie(s) available.\n", c
->scache
? pa_idxset_size(c
->scache
) : 0);
521 uint32_t idx
= PA_IDXSET_INVALID
;
523 for (e
= pa_idxset_first(c
->scache
, &idx
); e
; e
= pa_idxset_next(c
->scache
, &idx
)) {
525 char ss
[PA_SAMPLE_SPEC_SNPRINT_MAX
] = "n/a", cv
[PA_CVOLUME_SNPRINT_MAX
], cvdb
[PA_SW_CVOLUME_SNPRINT_DB_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
] = "n/a", *t
;
527 if (e
->memchunk
.memblock
) {
528 pa_sample_spec_snprint(ss
, sizeof(ss
), &e
->sample_spec
);
529 pa_channel_map_snprint(cm
, sizeof(cm
), &e
->channel_map
);
530 l
= (double) e
->memchunk
.length
/ (double) pa_bytes_per_second(&e
->sample_spec
);
537 "\tsample spec: %s\n"
538 "\tchannel map: %s\n"
540 "\tduration: %0.1f s\n"
545 "\tfilename: <%s>\n",
550 (long unsigned)(e
->memchunk
.memblock
? e
->memchunk
.length
: 0),
552 pa_cvolume_snprint(cv
, sizeof(cv
), &e
->volume
),
553 pa_sw_cvolume_snprint_dB(cvdb
, sizeof(cvdb
), &e
->volume
),
554 e
->memchunk
.memblock
? pa_cvolume_get_balance(&e
->channel_map
, &e
->volume
) : 0.0f
,
556 e
->filename
? e
->filename
: "n/a");
558 t
= pa_proplist_to_string_sep(e
->proplist
, "\n\t\t");
559 pa_strbuf_printf(s
, "\tproperties:\n\t\t%s\n", t
);
564 return pa_strbuf_tostring_free(s
);
567 char *pa_full_status_string(pa_core
*c
) {
573 for (i
= 0; i
< 8; i
++) {
578 t
= pa_sink_list_to_string(c
);
581 t
= pa_source_list_to_string(c
);
584 t
= pa_sink_input_list_to_string(c
);
587 t
= pa_source_output_list_to_string(c
);
590 t
= pa_client_list_to_string(c
);
593 t
= pa_card_list_to_string(c
);
596 t
= pa_module_list_to_string(c
);
599 t
= pa_scache_list_to_string(c
);
603 pa_strbuf_puts(s
, t
);
607 return pa_strbuf_tostring_free(s
);