From c7bd759cdb2b8f16693750f89ed781707a53e5a9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 10 Jul 2004 20:56:38 +0000 Subject: add description field for sinks/sources add owner field to all entities add client file to source outputs and sink inputs git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@59 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/cli.c | 3 ++- src/cli.h | 3 ++- src/client.c | 9 +++++++-- src/client.h | 2 ++ src/module-cli.c | 2 +- src/module-oss-mmap.c | 6 ++++++ src/module-oss.c | 21 +++++++++++++-------- src/module-pipe-sink.c | 4 ++++ src/module-protocol-stub.c | 4 ++-- src/protocol-cli.c | 6 ++++-- src/protocol-cli.h | 3 ++- src/protocol-esound.c | 13 ++++++++++--- src/protocol-esound.h | 3 ++- src/protocol-native.c | 12 ++++++++++-- src/protocol-native.h | 3 ++- src/protocol-simple.c | 9 ++++++++- src/protocol-simple.h | 4 +++- src/sink.c | 24 ++++++++++++++++++------ src/sink.h | 5 +++-- src/sinkinput.c | 7 +++++++ src/sinkinput.h | 4 ++++ src/source.c | 22 +++++++++++++++++----- src/source.h | 5 ++++- src/sourceoutput.c | 6 ++++++ src/sourceoutput.h | 4 ++++ src/strbuf.c | 2 ++ src/strbuf.h | 2 +- src/todo | 4 ---- src/util.c | 30 ++++++++++++++++++++++++++++++ src/util.h | 2 ++ 30 files changed, 178 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/cli.c b/src/cli.c index 429aebf3..b7fc787a 100644 --- a/src/cli.c +++ b/src/cli.c @@ -83,7 +83,7 @@ static const char prompt[] = ">>> "; static void client_kill(struct pa_client *c); -struct pa_cli* pa_cli_new(struct pa_core *core, struct pa_iochannel *io) { +struct pa_cli* pa_cli_new(struct pa_core *core, struct pa_iochannel *io, struct pa_module *m) { char cname[256]; struct pa_cli *c; assert(io); @@ -102,6 +102,7 @@ struct pa_cli* pa_cli_new(struct pa_core *core, struct pa_iochannel *io) { assert(c->client); c->client->kill = client_kill; c->client->userdata = c; + c->client->owner = m; pa_ioline_set_callback(c->line, line_callback, c); pa_ioline_puts(c->line, "Welcome to polypaudio! Use \"help\" for usage information.\n"); diff --git a/src/cli.h b/src/cli.h index 80d9fec7..d6250b37 100644 --- a/src/cli.h +++ b/src/cli.h @@ -3,10 +3,11 @@ #include "iochannel.h" #include "core.h" +#include "module.h" struct pa_cli; -struct pa_cli* pa_cli_new(struct pa_core *core, struct pa_iochannel *io); +struct pa_cli* pa_cli_new(struct pa_core *core, struct pa_iochannel *io, struct pa_module *m); void pa_cli_free(struct pa_cli *cli); void pa_cli_set_eof_callback(struct pa_cli *cli, void (*cb)(struct pa_cli*c, void *userdata), void *userdata); diff --git a/src/client.c b/src/client.c index d07f188f..fa1a28d4 100644 --- a/src/client.c +++ b/src/client.c @@ -14,6 +14,7 @@ struct pa_client *pa_client_new(struct pa_core *core, const char *protocol_name, c = malloc(sizeof(struct pa_client)); assert(c); c->name = name ? strdup(name) : NULL; + c->owner = NULL; c->core = core; c->protocol_name = protocol_name; @@ -58,9 +59,13 @@ char *pa_client_list_to_string(struct pa_core *c) { pa_strbuf_printf(s, "%u client(s).\n", pa_idxset_ncontents(c->clients)); - for (client = pa_idxset_first(c->clients, &index); client; client = pa_idxset_next(c->clients, &index)) + for (client = pa_idxset_first(c->clients, &index); client; client = pa_idxset_next(c->clients, &index)) { pa_strbuf_printf(s, " index: %u\n\tname: <%s>\n\tprotocol_name: <%s>\n", client->index, client->name, client->protocol_name); - + + if (client->owner) + pa_strbuf_printf(s, "\towner module: <%u>\n", client->owner->index); + } + return pa_strbuf_tostring_free(s); } diff --git a/src/client.h b/src/client.h index 4ca8d96e..d603411d 100644 --- a/src/client.h +++ b/src/client.h @@ -2,10 +2,12 @@ #define fooclienthfoo #include "core.h" +#include "module.h" struct pa_client { uint32_t index; + struct pa_module *owner; char *name; struct pa_core *core; const char *protocol_name; diff --git a/src/module-cli.c b/src/module-cli.c index a6e9582d..440c4ba5 100644 --- a/src/module-cli.c +++ b/src/module-cli.c @@ -27,7 +27,7 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) { assert(io); pa_iochannel_set_noclose(io, 1); - m->userdata = pa_cli_new(c, io); + m->userdata = pa_cli_new(c, io, m); assert(m->userdata); pa_cli_set_eof_callback(m->userdata, eof_cb, m); diff --git a/src/module-oss-mmap.c b/src/module-oss-mmap.c index 280484d0..772abf99 100644 --- a/src/module-oss-mmap.c +++ b/src/module-oss-mmap.c @@ -17,6 +17,7 @@ #include "module.h" #include "oss-util.h" #include "sample-util.h" +#include "util.h" struct userdata { struct pa_sink *sink; @@ -244,6 +245,9 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) { u->source = pa_source_new(c, "oss_input", 0, &u->sample_spec); assert(u->source); u->source->userdata = u; + pa_source_set_owner(u->source, m); + u->source->description = pa_sprintf_malloc("Open Sound System PCM/mmap() on '%s'", p); + u->in_memblocks = malloc(sizeof(struct pa_memblock *)*u->in_fragments); memset(u->in_memblocks, 0, sizeof(struct pa_memblock *)*u->in_fragments); @@ -276,6 +280,8 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) { assert(u->sink); u->sink->get_latency = sink_get_latency_cb; u->sink->userdata = u; + pa_sink_set_owner(u->sink, m); + u->sink->description = pa_sprintf_malloc("Open Sound System PCM/mmap() on '%s'", p); u->out_memblocks = malloc(sizeof(struct memblock *)*u->out_fragments); memset(u->out_memblocks, 0, sizeof(struct pa_memblock *)*u->out_fragments); diff --git a/src/module-oss.c b/src/module-oss.c index 5ec9d2d7..b0677584 100644 --- a/src/module-oss.c +++ b/src/module-oss.c @@ -16,6 +16,7 @@ #include "module.h" #include "oss-util.h" #include "sample-util.h" +#include "util.h" struct userdata { struct pa_sink *sink; @@ -180,21 +181,25 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) { u->core = c; + if (mode != O_WRONLY) { + u->source = pa_source_new(c, "oss_input", 0, &ss); + assert(u->source); + u->source->userdata = u; + pa_source_set_owner(u->source, m); + u->sink->description = pa_sprintf_malloc("Open Sound System PCM on '%s'", p); + } else + u->source = NULL; + if (mode != O_RDONLY) { - u->sink = pa_sink_new(c, "dsp", 0, &ss); + u->sink = pa_sink_new(c, "oss_output", 0, &ss); assert(u->sink); u->sink->get_latency = sink_get_latency_cb; u->sink->userdata = u; + pa_sink_set_owner(u->sink, m); + u->sink->description = pa_sprintf_malloc("Open Sound System PCM on '%s'", p); } else u->sink = NULL; - if (mode != O_WRONLY) { - u->source = pa_source_new(c, "dsp", 0, &ss); - assert(u->source); - u->source->userdata = u; - } else - u->source = NULL; - assert(u->source || u->sink); u->io = pa_iochannel_new(c->mainloop, u->source ? fd : -1, u->sink ? fd : 0); diff --git a/src/module-pipe-sink.c b/src/module-pipe-sink.c index efba3b5f..67c02404 100644 --- a/src/module-pipe-sink.c +++ b/src/module-pipe-sink.c @@ -11,6 +11,7 @@ #include "iochannel.h" #include "sink.h" #include "module.h" +#include "util.h" struct userdata { char *filename; @@ -113,6 +114,9 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) { assert(u->sink); u->sink->notify = notify_cb; u->sink->userdata = u; + pa_sink_set_owner(u->sink, m); + u->sink->description = pa_sprintf_malloc("Unix FIFO sink '%s'", p); + assert(u->sink->description); u->io = pa_iochannel_new(c->mainloop, -1, fd); assert(u->io); diff --git a/src/module-protocol-stub.c b/src/module-protocol-stub.c index 885ea4c8..3bb0a072 100644 --- a/src/module-protocol-stub.c +++ b/src/module-protocol-stub.c @@ -78,9 +78,9 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) { #endif #ifdef USE_PROTOCOL_SIMPLE - m->userdata = pa_protocol_simple_new(c, s, PA_PROTOCOL_SIMPLE_PLAYBACK); + m->userdata = pa_protocol_simple_new(c, s, m, PA_PROTOCOL_SIMPLE_PLAYBACK); #else - m->userdata = protocol_new(c, s); + m->userdata = protocol_new(c, s, m); #endif if (!m->userdata) { diff --git a/src/protocol-cli.c b/src/protocol-cli.c index 0cdf2db1..55b4a8a0 100644 --- a/src/protocol-cli.c +++ b/src/protocol-cli.c @@ -5,6 +5,7 @@ #include "cli.h" struct pa_protocol_cli { + struct pa_module *module; struct pa_core *core; struct pa_socket_server*server; struct pa_idxset *connections; @@ -22,19 +23,20 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo struct pa_cli *c; assert(s && io && p); - c = pa_cli_new(p->core, io); + c = pa_cli_new(p->core, io, p->module); assert(c); pa_cli_set_eof_callback(c, cli_eof_cb, p); pa_idxset_put(p->connections, c, NULL); } -struct pa_protocol_cli* pa_protocol_cli_new(struct pa_core *core, struct pa_socket_server *server) { +struct pa_protocol_cli* pa_protocol_cli_new(struct pa_core *core, struct pa_socket_server *server, struct pa_module *m) { struct pa_protocol_cli* p; assert(core && server); p = malloc(sizeof(struct pa_protocol_cli)); assert(p); + p->module = m; p->core = core; p->server = server; p->connections = pa_idxset_new(NULL, NULL); diff --git a/src/protocol-cli.h b/src/protocol-cli.h index fc6a7d65..c3bb8b4f 100644 --- a/src/protocol-cli.h +++ b/src/protocol-cli.h @@ -3,10 +3,11 @@ #include "core.h" #include "socket-server.h" +#include "module.h" struct pa_protocol_cli; -struct pa_protocol_cli* pa_protocol_cli_new(struct pa_core *core, struct pa_socket_server *server); +struct pa_protocol_cli* pa_protocol_cli_new(struct pa_core *core, struct pa_socket_server *server, struct pa_module *m); void pa_protocol_cli_free(struct pa_protocol_cli *n); #endif diff --git a/src/protocol-esound.c b/src/protocol-esound.c index 4d9ca546..fc4444c3 100644 --- a/src/protocol-esound.c +++ b/src/protocol-esound.c @@ -50,6 +50,7 @@ struct connection { struct pa_protocol_esound { int public; + struct pa_module *module; struct pa_core *core; struct pa_socket_server *server; struct pa_idxset *connections; @@ -260,6 +261,8 @@ static int esd_proto_stream_play(struct connection *c, esd_proto_t request, cons c->sink_input = pa_sink_input_new(sink, name, &ss); assert(c->sink_input); + c->sink_input->owner = c->protocol->module; + c->sink_input->client = c->client; c->sink_input->peek = sink_input_peek_cb; c->sink_input->drop = sink_input_drop_cb; c->sink_input->kill = sink_input_kill_cb; @@ -321,7 +324,9 @@ static int esd_proto_stream_record(struct connection *c, esd_proto_t request, co assert(!c->source_output); c->source_output = pa_source_output_new(source, name, &ss); assert(c->source_output); - + + c->source_output->owner = c->protocol->module; + c->source_output->client = c->client; c->source_output->push = source_output_push_cb; c->source_output->kill = source_output_kill_cb; c->source_output->userdata = c; @@ -733,6 +738,7 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo assert(c->protocol->core); c->client = pa_client_new(c->protocol->core, "ESOUND", cname); assert(c->client); + c->client->owner = c->protocol->module; c->client->kill = client_kill_cb; c->client->userdata = c; @@ -768,7 +774,7 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo /*** entry points ***/ -struct pa_protocol_esound* pa_protocol_esound_new(struct pa_core*core, struct pa_socket_server *server) { +struct pa_protocol_esound* pa_protocol_esound_new(struct pa_core*core, struct pa_socket_server *server, struct pa_module *m) { struct pa_protocol_esound *p; assert(core && server); @@ -779,7 +785,8 @@ struct pa_protocol_esound* pa_protocol_esound_new(struct pa_core*core, struct pa free(p); return NULL; } - + + p->module = m; p->public = 0; p->server = server; pa_socket_server_set_callback(p->server, on_connection, p); diff --git a/src/protocol-esound.h b/src/protocol-esound.h index cd505593..6071699d 100644 --- a/src/protocol-esound.h +++ b/src/protocol-esound.h @@ -3,10 +3,11 @@ #include "core.h" #include "socket-server.h" +#include "module.h" struct pa_protocol_esound; -struct pa_protocol_esound* pa_protocol_esound_new(struct pa_core*core, struct pa_socket_server *server); +struct pa_protocol_esound* pa_protocol_esound_new(struct pa_core*core, struct pa_socket_server *server, struct pa_module *m); void pa_protocol_esound_free(struct pa_protocol_esound *p); #endif diff --git a/src/protocol-native.c b/src/protocol-native.c index c7a7cce0..d6a5f9b2 100644 --- a/src/protocol-native.c +++ b/src/protocol-native.c @@ -48,6 +48,7 @@ struct connection { }; struct pa_protocol_native { + struct pa_module *module; int public; struct pa_core *core; struct pa_socket_server *server; @@ -110,6 +111,8 @@ static struct record_stream* record_stream_new(struct connection *c, struct pa_s s->source_output->push = source_output_push_cb; s->source_output->kill = source_output_kill_cb; s->source_output->userdata = s; + s->source_output->owner = c->protocol->module; + s->source_output->client = c->client; s->memblockq = pa_memblockq_new(maxlength, 0, base = pa_sample_size(ss), 0, 0); assert(s->memblockq); @@ -153,6 +156,8 @@ static struct playback_stream* playback_stream_new(struct connection *c, struct s->sink_input->kill = sink_input_kill_cb; s->sink_input->get_latency = sink_input_get_latency_cb; s->sink_input->userdata = s; + s->sink_input->owner = c->protocol->module; + s->sink_input->client = c->client; s->memblockq = pa_memblockq_new(maxlength, tlength, pa_sample_size(ss), prebuf, minreq); assert(s->memblockq); @@ -707,6 +712,8 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo assert(c->client); c->client->kill = client_kill_cb; c->client->userdata = c; + c->client->owner = p->module; + c->pstream = pa_pstream_new(p->core->mainloop, io); assert(c->pstream); @@ -729,7 +736,7 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo /*** module entry points ***/ -struct pa_protocol_native* pa_protocol_native_new(struct pa_core *core, struct pa_socket_server *server) { +struct pa_protocol_native* pa_protocol_native_new(struct pa_core *core, struct pa_socket_server *server, struct pa_module *m) { struct pa_protocol_native *p; assert(core && server); @@ -740,7 +747,8 @@ struct pa_protocol_native* pa_protocol_native_new(struct pa_core *core, struct p free(p); return NULL; } - + + p->module = m; p->public = 1; p->server = server; p->core = core; diff --git a/src/protocol-native.h b/src/protocol-native.h index 1a260149..811b4e4a 100644 --- a/src/protocol-native.h +++ b/src/protocol-native.h @@ -3,10 +3,11 @@ #include "core.h" #include "socket-server.h" +#include "module.h" struct pa_protocol_native; -struct pa_protocol_native* pa_protocol_native_new(struct pa_core*core, struct pa_socket_server *server); +struct pa_protocol_native* pa_protocol_native_new(struct pa_core*core, struct pa_socket_server *server, struct pa_module *m); void pa_protocol_native_free(struct pa_protocol_native *n); #endif diff --git a/src/protocol-simple.c b/src/protocol-simple.c index e7ca0a76..518d5f24 100644 --- a/src/protocol-simple.c +++ b/src/protocol-simple.c @@ -27,6 +27,7 @@ struct connection { }; struct pa_protocol_simple { + struct pa_module *module; struct pa_core *core; struct pa_socket_server*server; struct pa_idxset *connections; @@ -258,6 +259,7 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo pa_iochannel_socket_peer_to_string(io, cname, sizeof(cname)); c->client = pa_client_new(p->core, "SIMPLE", cname); assert(c->client); + c->client->owner = p->module; c->client->kill = client_kill_cb; c->client->userdata = c; @@ -275,6 +277,8 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo fprintf(stderr, "Failed to create sink input.\n"); goto fail; } + c->sink_input->owner = p->module; + c->sink_input->client = c->client; c->sink_input->peek = sink_input_peek_cb; c->sink_input->drop = sink_input_drop_cb; @@ -304,6 +308,8 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo fprintf(stderr, "Failed to create source output.\n"); goto fail; } + c->source_output->owner = p->module; + c->source_output->client = c->client; c->source_output->push = source_output_push_cb; c->source_output->kill = source_output_kill_cb; @@ -328,12 +334,13 @@ fail: connection_free(c); } -struct pa_protocol_simple* pa_protocol_simple_new(struct pa_core *core, struct pa_socket_server *server, enum pa_protocol_simple_mode mode) { +struct pa_protocol_simple* pa_protocol_simple_new(struct pa_core *core, struct pa_socket_server *server, struct pa_module *m, enum pa_protocol_simple_mode mode) { struct pa_protocol_simple* p; assert(core && server && mode <= PA_PROTOCOL_SIMPLE_DUPLEX && mode > 0); p = malloc(sizeof(struct pa_protocol_simple)); assert(p); + p->module = m; p->core = core; p->server = server; p->connections = pa_idxset_new(NULL, NULL); diff --git a/src/protocol-simple.h b/src/protocol-simple.h index 15ae36a6..6b2a2cd1 100644 --- a/src/protocol-simple.h +++ b/src/protocol-simple.h @@ -2,6 +2,8 @@ #define fooprotocolsimplehfoo #include "socket-server.h" +#include "module.h" +#include "core.h" struct pa_protocol_simple; @@ -11,7 +13,7 @@ enum pa_protocol_simple_mode { PA_PROTOCOL_SIMPLE_DUPLEX = 3 }; -struct pa_protocol_simple* pa_protocol_simple_new(struct pa_core *core, struct pa_socket_server *server, enum pa_protocol_simple_mode mode); +struct pa_protocol_simple* pa_protocol_simple_new(struct pa_core *core, struct pa_socket_server *server, struct pa_module *m, enum pa_protocol_simple_mode mode); void pa_protocol_simple_free(struct pa_protocol_simple *n); #endif diff --git a/src/sink.c b/src/sink.c index 80560724..6a9f3580 100644 --- a/src/sink.c +++ b/src/sink.c @@ -8,6 +8,7 @@ #include "strbuf.h" #include "sample-util.h" #include "namereg.h" +#include "util.h" #define MAX_MIX_CHANNELS 32 @@ -16,7 +17,7 @@ struct pa_sink* pa_sink_new(struct pa_core *core, const char *name, int fail, co char *n = NULL; char st[256]; int r; - assert(core && spec); + assert(core && name && spec); s = malloc(sizeof(struct pa_sink)); assert(s); @@ -27,15 +28,14 @@ struct pa_sink* pa_sink_new(struct pa_core *core, const char *name, int fail, co } s->name = strdup(name); + s->description = NULL; + + s->owner = NULL; s->core = core; s->sample_spec = *spec; s->inputs = pa_idxset_new(NULL, NULL); - if (name) { - n = malloc(strlen(name)+9); - sprintf(n, "%s_monitor", name); - } - + n = pa_sprintf_malloc("%s_monitor", name); s->monitor_source = pa_source_new(core, n, 0, spec); assert(s->monitor_source); free(n); @@ -75,6 +75,7 @@ void pa_sink_free(struct pa_sink *s) { fprintf(stderr, "sink: freed %u \"%s\"\n", s->index, s->name); free(s->name); + free(s->description); free(s); } @@ -285,8 +286,19 @@ char *pa_sink_list_to_string(struct pa_core *c) { pa_sink_get_latency(sink), sink->monitor_source->index, ss); + + if (sink->owner) + pa_strbuf_printf(s, "\towner module: <%u>\n", sink->owner->index); + if (sink->description) + pa_strbuf_printf(s, "\tdescription: <%s>\n", sink->description); } return pa_strbuf_tostring_free(s); } +void pa_sink_set_owner(struct pa_sink *sink, struct pa_module *m) { + sink->owner = m; + + if (sink->monitor_source) + pa_source_set_owner(sink->monitor_source, m); +} diff --git a/src/sink.h b/src/sink.h index 7186f531..071ad094 100644 --- a/src/sink.h +++ b/src/sink.h @@ -13,7 +13,8 @@ struct pa_sink; struct pa_sink { uint32_t index; - char *name; + char *name, *description; + struct pa_module *owner; struct pa_core *core; struct pa_sample_spec sample_spec; struct pa_idxset *inputs; @@ -42,6 +43,6 @@ char *pa_sink_list_to_string(struct pa_core *core); struct pa_sink* pa_sink_get_default(struct pa_core *c); - +void pa_sink_set_owner(struct pa_sink *sink, struct pa_module *m); #endif diff --git a/src/sinkinput.c b/src/sinkinput.c index f3e474bc..3cfe49b3 100644 --- a/src/sinkinput.c +++ b/src/sinkinput.c @@ -23,6 +23,8 @@ struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, con i = malloc(sizeof(struct pa_sink_input)); assert(i); i->name = name ? strdup(name) : NULL; + i->client = NULL; + i->owner = NULL; i->sink = s; i->sample_spec = *spec; @@ -96,6 +98,11 @@ char *pa_sink_input_list_to_string(struct pa_core *c) { (unsigned) i->volume, pa_sink_input_get_latency(i), ss); + + if (i->owner) + pa_strbuf_printf(s, "\towner module: <%u>\n", i->owner->index); + if (i->client) + pa_strbuf_printf(s, "\tclient: <%u>\n", i->client->index); } return pa_strbuf_tostring_free(s); diff --git a/src/sinkinput.h b/src/sinkinput.h index b28b51ef..8c9813e5 100644 --- a/src/sinkinput.h +++ b/src/sinkinput.h @@ -7,11 +7,15 @@ #include "sample.h" #include "memblockq.h" #include "resampler.h" +#include "module.h" +#include "client.h" struct pa_sink_input { uint32_t index; char *name; + struct pa_module *owner; + struct pa_client *client; struct pa_sink *sink; struct pa_sample_spec sample_spec; uint32_t volume; diff --git a/src/source.c b/src/source.c index 44d7da01..45ccfb27 100644 --- a/src/source.c +++ b/src/source.c @@ -12,7 +12,7 @@ struct pa_source* pa_source_new(struct pa_core *core, const char *name, int fail struct pa_source *s; char st[256]; int r; - assert(core && spec); + assert(core && spec && name); s = malloc(sizeof(struct pa_source)); assert(s); @@ -23,6 +23,9 @@ struct pa_source* pa_source_new(struct pa_core *core, const char *name, int fail } s->name = strdup(name); + s->description = NULL; + + s->owner = NULL; s->core = core; s->sample_spec = *spec; s->outputs = pa_idxset_new(NULL, NULL); @@ -58,6 +61,7 @@ void pa_source_free(struct pa_source *s) { fprintf(stderr, "source: freed %u \"%s\"\n", s->index, s->name); free(s->name); + free(s->description); free(s); } @@ -112,13 +116,21 @@ char *pa_source_list_to_string(struct pa_core *c) { for (source = pa_idxset_first(c->sources, &index); source; source = pa_idxset_next(c->sources, &index)) { char ss[PA_SAMPLE_SNPRINT_MAX_LENGTH]; - char mo[256] = ""; - if (source->monitor_of) - snprintf(mo, sizeof(mo), "\n\tmonitor_of: <%u>", source->monitor_of->index); pa_sample_snprint(ss, sizeof(ss), &source->sample_spec); - pa_strbuf_printf(s, " %c index: %u\n\tname: <%s>\n\tsample_spec: <%s>%s\n", source == default_source ? '*' : ' ', source->index, source->name, ss, mo); + pa_strbuf_printf(s, " %c index: %u\n\tname: <%s>\n\tsample_spec: <%s>\n", source == default_source ? '*' : ' ', source->index, source->name, ss); + + if (source->monitor_of) + pa_strbuf_printf(s, "\tmonitor_of: <%u>\n", source->monitor_of->index); + if (source->owner) + pa_strbuf_printf(s, "\towner module: <%u>\n", source->owner->index); + if (source->description) + pa_strbuf_printf(s, "\tdescription: <%s>\n", source->description); } return pa_strbuf_tostring_free(s); } +void pa_source_set_owner(struct pa_source *s, struct pa_module *m) { + assert(s); + s->owner = m; +} diff --git a/src/source.h b/src/source.h index 3b66cd36..2bc5bea8 100644 --- a/src/source.h +++ b/src/source.h @@ -14,7 +14,8 @@ struct pa_source; struct pa_source { uint32_t index; - char *name; + char *name, *description; + struct pa_module *owner; struct pa_core *core; struct pa_sample_spec sample_spec; struct pa_idxset *outputs; @@ -36,4 +37,6 @@ char *pa_source_list_to_string(struct pa_core *c); struct pa_source* pa_source_get_default(struct pa_core *c); +void pa_source_set_owner(struct pa_source *s, struct pa_module *m); + #endif diff --git a/src/sourceoutput.c b/src/sourceoutput.c index 442dc7f4..ea727576 100644 --- a/src/sourceoutput.c +++ b/src/sourceoutput.c @@ -18,6 +18,8 @@ struct pa_source_output* pa_source_output_new(struct pa_source *s, const char *n o = malloc(sizeof(struct pa_source_output)); assert(o); o->name = name ? strdup(name) : NULL; + o->client = NULL; + o->owner = NULL; o->source = s; o->sample_spec = *spec; @@ -77,6 +79,10 @@ char *pa_source_output_list_to_string(struct pa_core *c) { o->name, o->source->index, ss); + if (o->owner) + pa_strbuf_printf(s, "\towner module: <%u>\n", o->owner->index); + if (o->client) + pa_strbuf_printf(s, "\tclient: <%u>\n", o->client->index); } return pa_strbuf_tostring_free(s); diff --git a/src/sourceoutput.h b/src/sourceoutput.h index fb60182a..dfd076db 100644 --- a/src/sourceoutput.h +++ b/src/sourceoutput.h @@ -7,11 +7,15 @@ #include "sample.h" #include "memblockq.h" #include "resampler.h" +#include "module.h" +#include "client.h" struct pa_source_output { uint32_t index; char *name; + struct pa_module *owner; + struct pa_client *client; struct pa_source *source; struct pa_sample_spec sample_spec; diff --git a/src/strbuf.c b/src/strbuf.c index c2a6518e..2082002a 100644 --- a/src/strbuf.c +++ b/src/strbuf.c @@ -87,6 +87,8 @@ void pa_strbuf_puts(struct pa_strbuf *sb, const char *t) { sb->length += l; } +/* The following is based on an example from the GNU libc documentation */ + int pa_strbuf_printf(struct pa_strbuf *sb, const char *format, ...) { int r, size = 100; struct chunk *c = NULL; diff --git a/src/strbuf.h b/src/strbuf.h index bb972044..ab0c6a74 100644 --- a/src/strbuf.h +++ b/src/strbuf.h @@ -8,7 +8,7 @@ void pa_strbuf_free(struct pa_strbuf *sb); char *pa_strbuf_tostring(struct pa_strbuf *sb); char *pa_strbuf_tostring_free(struct pa_strbuf *sb); -int pa_strbuf_printf(struct pa_strbuf *sb, const char *format, ...); +int pa_strbuf_printf(struct pa_strbuf *sb, const char *format, ...) __attribute__ ((format (printf, 2, 3)));; void pa_strbuf_puts(struct pa_strbuf *sb, const char *t); #endif diff --git a/src/todo b/src/todo index 8c647a8d..36e69a18 100644 --- a/src/todo +++ b/src/todo @@ -3,10 +3,6 @@ - config parser/cmdline -- description field for all entities -- client field for sinkinput/sourceoutput -- module field for all entities - - move more stuff from module-oss[-dma] to liboss-util - create libstatustext, libsocketutil diff --git a/src/util.c b/src/util.c index 6fe4bbee..aceb772d 100644 --- a/src/util.c +++ b/src/util.c @@ -1,3 +1,5 @@ +#include +#include #include #include #include @@ -230,3 +232,31 @@ void pa_check_for_sigpipe(void) { if (sa.sa_handler == SIG_DFL) fprintf(stderr, "polypaudio: WARNING: SIGPIPE is not trapped. This might cause malfunction!\n"); } + +/* The following is based on an example from the GNU libc documentation */ +char *pa_sprintf_malloc(const char *format, ...) { + int size = 100; + char *c = NULL; + + assert(format); + + for(;;) { + int r; + va_list ap; + + c = realloc(c, size); + assert(c); + + va_start(ap, format); + r = vsnprintf(c, size, format, ap); + va_end(ap); + + if (r > -1 && r < size) + return c; + + if (r > -1) /* glibc 2.1 */ + size = r+1; + else /* glibc 2.0 */ + size *= 2; + } +} diff --git a/src/util.h b/src/util.h index dba89ee8..c5c6db82 100644 --- a/src/util.h +++ b/src/util.h @@ -23,4 +23,6 @@ int pa_unix_socket_remove_stale(const char *fn); void pa_check_for_sigpipe(void); +char *pa_sprintf_malloc(const char *format, ...) __attribute__ ((format (printf, 1, 2))); + #endif -- cgit