]> code.delx.au - pulseaudio/blob - src/pulsecore/cli-text.c
add priority logic to find best default profile
[pulseaudio] / src / pulsecore / cli-text.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2004-2006 Lennart Poettering
5
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.
10
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.
15
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
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <string.h>
27
28 #include <pulse/volume.h>
29 #include <pulse/xmalloc.h>
30 #include <pulse/timeval.h>
31
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>
43
44 #include "cli-text.h"
45
46 char *pa_module_list_to_string(pa_core *c) {
47 pa_strbuf *s;
48 pa_module *m;
49 uint32_t idx = PA_IDXSET_INVALID;
50 pa_assert(c);
51
52 s = pa_strbuf_new();
53
54 pa_strbuf_printf(s, "%u module(s) loaded.\n", pa_idxset_size(c->modules));
55
56 for (m = pa_idxset_first(c->modules, &idx); m; m = pa_idxset_next(c->modules, &idx)) {
57 char *t;
58
59 pa_strbuf_printf(s, " index: %u\n"
60 "\tname: <%s>\n"
61 "\targument: <%s>\n"
62 "\tused: %i\n"
63 "\tload once: %s\n",
64 m->index,
65 m->name,
66 pa_strempty(m->argument),
67 pa_module_get_n_used(m),
68 pa_yes_no(m->load_once));
69
70 t = pa_proplist_to_string_sep(m->proplist, "\n\t\t");
71 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
72 pa_xfree(t);
73 }
74
75 return pa_strbuf_tostring_free(s);
76 }
77
78 char *pa_client_list_to_string(pa_core *c) {
79 pa_strbuf *s;
80 pa_client *client;
81 uint32_t idx = PA_IDXSET_INVALID;
82 pa_assert(c);
83
84 s = pa_strbuf_new();
85
86 pa_strbuf_printf(s, "%u client(s) logged in.\n", pa_idxset_size(c->clients));
87
88 for (client = pa_idxset_first(c->clients, &idx); client; client = pa_idxset_next(c->clients, &idx)) {
89 char *t;
90 pa_strbuf_printf(
91 s,
92 " index: %u\n"
93 "\tdriver: <%s>\n",
94 client->index,
95 client->driver);
96
97 if (client->module)
98 pa_strbuf_printf(s, "\towner module: %u\n", client->module->index);
99
100 t = pa_proplist_to_string_sep(client->proplist, "\n\t\t");
101 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
102 pa_xfree(t);
103 }
104
105 return pa_strbuf_tostring_free(s);
106 }
107
108 char *pa_card_list_to_string(pa_core *c) {
109 pa_strbuf *s;
110 pa_card *card;
111 uint32_t idx = PA_IDXSET_INVALID;
112 pa_assert(c);
113
114 s = pa_strbuf_new();
115
116 pa_strbuf_printf(s, "%u card(s) available.\n", pa_idxset_size(c->cards));
117
118 for (card = pa_idxset_first(c->cards, &idx); card; card = pa_idxset_next(c->cards, &idx)) {
119 char *t;
120 pa_strbuf_printf(
121 s,
122 " index: %u\n"
123 "\tname: <%s>\n"
124 "\tdriver: <%s>\n",
125 card->index,
126 card->name,
127 card->driver);
128
129 if (card->module)
130 pa_strbuf_printf(s, "\towner module: %u\n", card->module->index);
131
132 t = pa_proplist_to_string_sep(card->proplist, "\n\t\t");
133 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
134 pa_xfree(t);
135
136 if (card->profiles) {
137 pa_card_profile *p;
138 void *state = NULL;
139
140 pa_strbuf_puts(
141 s,
142 "\tprofiles:\n");
143
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);
146 }
147
148 if (card->active_profile)
149 pa_strbuf_printf(
150 s,
151 "\tactive profile: <%s>\n",
152 card->active_profile->name);
153 }
154
155 return pa_strbuf_tostring_free(s);
156 }
157
158 static const char *sink_state_to_string(pa_sink_state_t state) {
159 switch (state) {
160 case PA_SINK_INIT:
161 return "INIT";
162 case PA_SINK_RUNNING:
163 return "RUNNING";
164 case PA_SINK_SUSPENDED:
165 return "SUSPENDED";
166 case PA_SINK_IDLE:
167 return "IDLE";
168 case PA_SINK_UNLINKED:
169 return "UNLINKED";
170 default:
171 return "INVALID";
172 }
173 }
174
175 static const char *source_state_to_string(pa_source_state_t state) {
176 switch (state) {
177 case PA_SOURCE_INIT:
178 return "INIT";
179 case PA_SOURCE_RUNNING:
180 return "RUNNING";
181 case PA_SOURCE_SUSPENDED:
182 return "SUSPENDED";
183 case PA_SOURCE_IDLE:
184 return "IDLE";
185 case PA_SOURCE_UNLINKED:
186 return "UNLINKED";
187 default:
188 return "INVALID";
189 }
190 }
191
192 char *pa_sink_list_to_string(pa_core *c) {
193 pa_strbuf *s;
194 pa_sink *sink;
195 uint32_t idx = PA_IDXSET_INVALID;
196 pa_assert(c);
197
198 s = pa_strbuf_new();
199
200 pa_strbuf_printf(s, "%u sink(s) available.\n", pa_idxset_size(c->sinks));
201
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;
210
211 pa_sink_get_latency_range(sink, &min_latency, &max_latency);
212
213 pa_strbuf_printf(
214 s,
215 " %c index: %u\n"
216 "\tname: <%s>\n"
217 "\tdriver: <%s>\n"
218 "\tflags: %s%s%s%s%s%s\n"
219 "\tstate: %s\n"
220 "\tvolume: %s%s%s\n"
221 "\t balance %0.2f\n"
222 "\tbase volume: %s%s%s\n"
223 "\tmuted: %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"
231 "\tused by: %u\n"
232 "\tlinked by: %u\n",
233 c->default_sink_name && !strcmp(sink->name, c->default_sink_name) ? '*' : ' ',
234 sink->index,
235 sink->name,
236 sink->driver,
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));
263
264 if (sink->card)
265 pa_strbuf_printf(s, "\tcard: %u <%s>\n", sink->card->index, sink->card->name);
266 if (sink->module)
267 pa_strbuf_printf(s, "\tmodule: %u\n", sink->module->index);
268
269 t = pa_proplist_to_string_sep(sink->proplist, "\n\t\t");
270 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
271 pa_xfree(t);
272 }
273
274 return pa_strbuf_tostring_free(s);
275 }
276
277 char *pa_source_list_to_string(pa_core *c) {
278 pa_strbuf *s;
279 pa_source *source;
280 uint32_t idx = PA_IDXSET_INVALID;
281 pa_assert(c);
282
283 s = pa_strbuf_new();
284
285 pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_size(c->sources));
286
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;
295
296 pa_source_get_latency_range(source, &min_latency, &max_latency);
297
298 pa_strbuf_printf(
299 s,
300 " %c index: %u\n"
301 "\tname: <%s>\n"
302 "\tdriver: <%s>\n"
303 "\tflags: %s%s%s%s%s%s\n"
304 "\tstate: %s\n"
305 "\tvolume: %s%s%s\n"
306 "\t balance %0.2f\n"
307 "\tbase volume: %s%s%s\n"
308 "\tmuted: %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"
314 "\tused by: %u\n"
315 "\tlinked by: %u\n",
316 c->default_source_name && !strcmp(source->name, c->default_source_name) ? '*' : ' ',
317 source->index,
318 source->name,
319 source->driver,
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));
344
345 if (source->monitor_of)
346 pa_strbuf_printf(s, "\tmonitor_of: %u\n", source->monitor_of->index);
347 if (source->card)
348 pa_strbuf_printf(s, "\tcard: %u <%s>\n", source->card->index, source->card->name);
349 if (source->module)
350 pa_strbuf_printf(s, "\tmodule: %u\n", source->module->index);
351
352 t = pa_proplist_to_string_sep(source->proplist, "\n\t\t");
353 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
354 pa_xfree(t);
355 }
356
357 return pa_strbuf_tostring_free(s);
358 }
359
360
361 char *pa_source_output_list_to_string(pa_core *c) {
362 pa_strbuf *s;
363 pa_source_output *o;
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"
370 };
371 pa_assert(c);
372
373 s = pa_strbuf_new();
374
375 pa_strbuf_printf(s, "%u source outputs(s) available.\n", pa_idxset_size(c->source_outputs));
376
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];
379 pa_usec_t cl;
380
381 if ((cl = pa_source_output_get_requested_latency(o)) == (pa_usec_t) -1)
382 pa_snprintf(clt, sizeof(clt), "n/a");
383 else
384 pa_snprintf(clt, sizeof(clt), "%0.2f ms", (double) cl / PA_USEC_PER_MSEC);
385
386 pa_assert(o->source);
387
388 pa_strbuf_printf(
389 s,
390 " index: %u\n"
391 "\tdriver: <%s>\n"
392 "\tflags: %s%s%s%s%s%s%s%s\n"
393 "\tstate: %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",
400 o->index,
401 o->driver,
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,
413 clt,
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)));
417 if (o->module)
418 pa_strbuf_printf(s, "\towner module: %u\n", o->module->index);
419 if (o->client)
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);
423
424 t = pa_proplist_to_string_sep(o->proplist, "\n\t\t");
425 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
426 pa_xfree(t);
427 }
428
429 return pa_strbuf_tostring_free(s);
430 }
431
432 char *pa_sink_input_list_to_string(pa_core *c) {
433 pa_strbuf *s;
434 pa_sink_input *i;
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"
442 };
443
444 pa_assert(c);
445 s = pa_strbuf_new();
446
447 pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_size(c->sink_inputs));
448
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];
451 pa_usec_t cl;
452
453 if ((cl = pa_sink_input_get_requested_latency(i)) == (pa_usec_t) -1)
454 pa_snprintf(clt, sizeof(clt), "n/a");
455 else
456 pa_snprintf(clt, sizeof(clt), "%0.2f ms", (double) cl / PA_USEC_PER_MSEC);
457
458 pa_assert(i->sink);
459
460 pa_strbuf_printf(
461 s,
462 " index: %u\n"
463 "\tdriver: <%s>\n"
464 "\tflags: %s%s%s%s%s%s%s%s\n"
465 "\tstate: %s\n"
466 "\tsink: %u <%s>\n"
467 "\tvolume: %s\n"
468 "\t %s\n"
469 "\t balance %0.2f\n"
470 "\tmuted: %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",
476 i->index,
477 i->driver,
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,
493 clt,
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)));
497
498 if (i->module)
499 pa_strbuf_printf(s, "\tmodule: %u\n", i->module->index);
500 if (i->client)
501 pa_strbuf_printf(s, "\tclient: %u <%s>\n", i->client->index, pa_strnull(pa_proplist_gets(i->client->proplist, PA_PROP_APPLICATION_NAME)));
502
503 t = pa_proplist_to_string_sep(i->proplist, "\n\t\t");
504 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
505 pa_xfree(t);
506 }
507
508 return pa_strbuf_tostring_free(s);
509 }
510
511 char *pa_scache_list_to_string(pa_core *c) {
512 pa_strbuf *s;
513 pa_assert(c);
514
515 s = pa_strbuf_new();
516
517 pa_strbuf_printf(s, "%u cache entrie(s) available.\n", c->scache ? pa_idxset_size(c->scache) : 0);
518
519 if (c->scache) {
520 pa_scache_entry *e;
521 uint32_t idx = PA_IDXSET_INVALID;
522
523 for (e = pa_idxset_first(c->scache, &idx); e; e = pa_idxset_next(c->scache, &idx)) {
524 double l = 0;
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;
526
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);
531 }
532
533 pa_strbuf_printf(
534 s,
535 " name: <%s>\n"
536 "\tindex: %u\n"
537 "\tsample spec: %s\n"
538 "\tchannel map: %s\n"
539 "\tlength: %lu\n"
540 "\tduration: %0.1f s\n"
541 "\tvolume: %s\n"
542 "\t %s\n"
543 "\t balance %0.2f\n"
544 "\tlazy: %s\n"
545 "\tfilename: <%s>\n",
546 e->name,
547 e->index,
548 ss,
549 cm,
550 (long unsigned)(e->memchunk.memblock ? e->memchunk.length : 0),
551 l,
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,
555 pa_yes_no(e->lazy),
556 e->filename ? e->filename : "n/a");
557
558 t = pa_proplist_to_string_sep(e->proplist, "\n\t\t");
559 pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
560 pa_xfree(t);
561 }
562 }
563
564 return pa_strbuf_tostring_free(s);
565 }
566
567 char *pa_full_status_string(pa_core *c) {
568 pa_strbuf *s;
569 int i;
570
571 s = pa_strbuf_new();
572
573 for (i = 0; i < 8; i++) {
574 char *t = NULL;
575
576 switch (i) {
577 case 0:
578 t = pa_sink_list_to_string(c);
579 break;
580 case 1:
581 t = pa_source_list_to_string(c);
582 break;
583 case 2:
584 t = pa_sink_input_list_to_string(c);
585 break;
586 case 3:
587 t = pa_source_output_list_to_string(c);
588 break;
589 case 4:
590 t = pa_client_list_to_string(c);
591 break;
592 case 5:
593 t = pa_card_list_to_string(c);
594 break;
595 case 6:
596 t = pa_module_list_to_string(c);
597 break;
598 case 7:
599 t = pa_scache_list_to_string(c);
600 break;
601 }
602
603 pa_strbuf_puts(s, t);
604 pa_xfree(t);
605 }
606
607 return pa_strbuf_tostring_free(s);
608 }