]> code.delx.au - pulseaudio/blob - polyp/clitext.c
fbce22237a14a1042a090676a1fd35bea99b26bb
[pulseaudio] / polyp / clitext.c
1 /* $Id$ */
2
3 /***
4 This file is part of polypaudio.
5
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU 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 polypaudio 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 General Public License
17 along with polypaudio; 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 <assert.h>
27 #include <string.h>
28
29 #include "clitext.h"
30 #include "module.h"
31 #include "client.h"
32 #include "sink.h"
33 #include "source.h"
34 #include "sink-input.h"
35 #include "source-output.h"
36 #include "strbuf.h"
37 #include "sample-util.h"
38 #include "scache.h"
39
40 char *pa_module_list_to_string(struct pa_core *c) {
41 struct pa_strbuf *s;
42 struct pa_module *m;
43 uint32_t index = PA_IDXSET_INVALID;
44 assert(c);
45
46 s = pa_strbuf_new();
47 assert(s);
48
49 pa_strbuf_printf(s, "%u module(s) loaded.\n", pa_idxset_ncontents(c->modules));
50
51 for (m = pa_idxset_first(c->modules, &index); m; m = pa_idxset_next(c->modules, &index))
52 pa_strbuf_printf(s, " index: %u\n\tname: <%s>\n\targument: <%s>\n", m->index, m->name, m->argument);
53
54 return pa_strbuf_tostring_free(s);
55 }
56
57 char *pa_client_list_to_string(struct pa_core *c) {
58 struct pa_strbuf *s;
59 struct pa_client *client;
60 uint32_t index = PA_IDXSET_INVALID;
61 assert(c);
62
63 s = pa_strbuf_new();
64 assert(s);
65
66 pa_strbuf_printf(s, "%u client(s).\n", pa_idxset_ncontents(c->clients));
67
68 for (client = pa_idxset_first(c->clients, &index); client; client = pa_idxset_next(c->clients, &index)) {
69 pa_strbuf_printf(s, " index: %u\n\tname: <%s>\n\tprotocol_name: <%s>\n", client->index, client->name, client->protocol_name);
70
71 if (client->owner)
72 pa_strbuf_printf(s, "\towner module: <%u>\n", client->owner->index);
73 }
74
75 return pa_strbuf_tostring_free(s);
76 }
77
78 char *pa_sink_list_to_string(struct pa_core *c) {
79 struct pa_strbuf *s;
80 struct pa_sink *sink, *default_sink;
81 uint32_t index = PA_IDXSET_INVALID;
82 assert(c);
83
84 s = pa_strbuf_new();
85 assert(s);
86
87 pa_strbuf_printf(s, "%u sink(s) available.\n", pa_idxset_ncontents(c->sinks));
88
89 default_sink = pa_sink_get_default(c);
90
91 for (sink = pa_idxset_first(c->sinks, &index); sink; sink = pa_idxset_next(c->sinks, &index)) {
92 char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH];
93 pa_sample_snprint(ss, sizeof(ss), &sink->sample_spec);
94 assert(sink->monitor_source);
95 pa_strbuf_printf(
96 s,
97 " %c index: %u\n\tname: <%s>\n\tvolume: <0x%04x>\n\tlatency: <%u usec>\n\tmonitor_source: <%u>\n\tsample_spec: <%s>\n",
98 sink == default_sink ? '*' : ' ',
99 sink->index, sink->name,
100 (unsigned) sink->volume,
101 pa_sink_get_latency(sink),
102 sink->monitor_source->index,
103 ss);
104
105 if (sink->owner)
106 pa_strbuf_printf(s, "\towner module: <%u>\n", sink->owner->index);
107 if (sink->description)
108 pa_strbuf_printf(s, "\tdescription: <%s>\n", sink->description);
109 }
110
111 return pa_strbuf_tostring_free(s);
112 }
113
114 char *pa_source_list_to_string(struct pa_core *c) {
115 struct pa_strbuf *s;
116 struct pa_source *source, *default_source;
117 uint32_t index = PA_IDXSET_INVALID;
118 assert(c);
119
120 s = pa_strbuf_new();
121 assert(s);
122
123 pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_ncontents(c->sources));
124
125 default_source = pa_source_get_default(c);
126
127 for (source = pa_idxset_first(c->sources, &index); source; source = pa_idxset_next(c->sources, &index)) {
128 char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH];
129 pa_sample_snprint(ss, sizeof(ss), &source->sample_spec);
130 pa_strbuf_printf(s, " %c index: %u\n\tname: <%s>\n\tsample_spec: <%s>\n", source == default_source ? '*' : ' ', source->index, source->name, ss);
131
132 if (source->monitor_of)
133 pa_strbuf_printf(s, "\tmonitor_of: <%u>\n", source->monitor_of->index);
134 if (source->owner)
135 pa_strbuf_printf(s, "\towner module: <%u>\n", source->owner->index);
136 if (source->description)
137 pa_strbuf_printf(s, "\tdescription: <%s>\n", source->description);
138 }
139
140 return pa_strbuf_tostring_free(s);
141 }
142
143
144 char *pa_source_output_list_to_string(struct pa_core *c) {
145 struct pa_strbuf *s;
146 struct pa_source_output *o;
147 uint32_t index = PA_IDXSET_INVALID;
148 assert(c);
149
150 s = pa_strbuf_new();
151 assert(s);
152
153 pa_strbuf_printf(s, "%u source outputs(s) available.\n", pa_idxset_ncontents(c->source_outputs));
154
155 for (o = pa_idxset_first(c->source_outputs, &index); o; o = pa_idxset_next(c->source_outputs, &index)) {
156 char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH];
157 pa_sample_snprint(ss, sizeof(ss), &o->sample_spec);
158 assert(o->source);
159 pa_strbuf_printf(
160 s, " index: %u\n\tname: <%s>\n\tsource: <%u>\n\tsample_spec: <%s>\n",
161 o->index,
162 o->name,
163 o->source->index,
164 ss);
165 if (o->owner)
166 pa_strbuf_printf(s, "\towner module: <%u>\n", o->owner->index);
167 if (o->client)
168 pa_strbuf_printf(s, "\tclient: <%u>\n", o->client->index);
169 }
170
171 return pa_strbuf_tostring_free(s);
172 }
173
174 char *pa_sink_input_list_to_string(struct pa_core *c) {
175 struct pa_strbuf *s;
176 struct pa_sink_input *i;
177 uint32_t index = PA_IDXSET_INVALID;
178 assert(c);
179
180 s = pa_strbuf_new();
181 assert(s);
182
183 pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_ncontents(c->sink_inputs));
184
185 for (i = pa_idxset_first(c->sink_inputs, &index); i; i = pa_idxset_next(c->sink_inputs, &index)) {
186 char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH];
187 pa_sample_snprint(ss, sizeof(ss), &i->sample_spec);
188 assert(i->sink);
189 pa_strbuf_printf(
190 s, " index: %u\n\tname: <%s>\n\tsink: <%u>\n\tvolume: <0x%04x>\n\tlatency: <%u usec>\n\tsample_spec: <%s>\n",
191 i->index,
192 i->name,
193 i->sink->index,
194 (unsigned) i->volume,
195 pa_sink_input_get_latency(i),
196 ss);
197
198 if (i->owner)
199 pa_strbuf_printf(s, "\towner module: <%u>\n", i->owner->index);
200 if (i->client)
201 pa_strbuf_printf(s, "\tclient: <%u>\n", i->client->index);
202 }
203
204 return pa_strbuf_tostring_free(s);
205 }
206
207 char *pa_scache_list_to_string(struct pa_core *c) {
208 struct pa_scache_entry *e;
209 void *state = NULL;
210 struct pa_strbuf *s;
211 assert(c);
212
213 s = pa_strbuf_new();
214 assert(s);
215
216 pa_strbuf_printf(s, "%u cache entries available.\n", c->scache_hashmap ? pa_hashmap_ncontents(c->scache_hashmap) : 0);
217
218 if (c->scache_hashmap) {
219
220 while ((e = pa_hashmap_iterate(c->scache_hashmap, &state))) {
221 double l;
222 char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH];
223 pa_sample_snprint(ss, sizeof(ss), &e->sample_spec);
224
225 l = (double) e->memchunk.length / pa_bytes_per_second(&e->sample_spec);
226
227 pa_strbuf_printf(
228 s, " name: <%s>\n\tindex: <%i>\n\tsample_spec: <%s>\n\tlength: <%u>\n\tduration: <%0.1fs>\n\tvolume: <0x%04x>\n",
229 e->name,
230 e->index,
231 ss,
232 e->memchunk.length,
233 l,
234 e->volume);
235 }
236 }
237
238 return pa_strbuf_tostring_free(s);
239 }