add pa_ prefix to all identifiers.

fix downsampling/resampling
add support for U8 samples


git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@49 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2004-07-03 23:35:12 +00:00
parent a8a5ab1c79
commit e61c2dddb7
91 changed files with 1795 additions and 1643 deletions

View file

@ -20,17 +20,36 @@ AM_CFLAGS=-ansi -D_GNU_SOURCE
bin_PROGRAMS = polypaudio pacat bin_PROGRAMS = polypaudio pacat
pkglib_LTLIBRARIES=libiochannel.la libsocket-server.la libsocket-client.la \ pkglib_LTLIBRARIES=libiochannel.la \
libprotocol-simple.la module-simple-protocol-tcp.la \ libsocket-server.la \
module-pipe-sink.la libpstream.la \ libsocket-client.la \
libpacket.la module-oss.la module-oss-mmap.la liboss-util.la libioline.la \ libpstream.la \
libcli.la module-cli.la libtokenizer.la libdynarray.la \ libpacket.la \
module-simple-protocol-unix.la module-cli-protocol-tcp.la \ liboss-util.la \
libprotocol-cli.la module-cli-protocol-unix.la libtagstruct.la \ libioline.la \
libpdispatch.la libprotocol-native.la libpstream-util.la \ libcli.la \
module-native-protocol-tcp.la module-native-protocol-unix.la \ libtokenizer.la \
libpolyp.la libprotocol-esound.la module-esound-protocol-unix.la \ libdynarray.la \
module-esound-protocol-tcp.la libprotocol-cli.la \
libtagstruct.la \
libpstream-util.la \
libpdispatch.la \
libprotocol-simple.la \
libprotocol-esound.la \
libprotocol-native.la \
module-cli.la \
module-cli-protocol-tcp.la \
module-cli-protocol-unix.la \
module-pipe-sink.la \
module-oss.la \
module-oss-mmap.la \
module-simple-protocol-tcp.la \
module-simple-protocol-unix.la \
module-esound-protocol-tcp.la \
module-esound-protocol-unix.la \
module-native-protocol-tcp.la \
module-native-protocol-unix.la \
libpolyp.la
polypaudio_SOURCES = idxset.c idxset.h \ polypaudio_SOURCES = idxset.c idxset.h \
queue.c queue.h \ queue.c queue.h \
@ -56,7 +75,9 @@ polypaudio_SOURCES = idxset.c idxset.h \
sconv.c sconv.h \ sconv.c sconv.h \
resampler.c resampler.h \ resampler.c resampler.h \
endianmacros.h \ endianmacros.h \
memchunk.c memchunk.h memchunk.c memchunk.h \
sconv-s16le.c sconv-s16le.h \
sconv-s16be.c sconv-s16be.h
polypaudio_CFLAGS = $(AM_CFLAGS) $(LIBSAMPLERATE_CFLAGS) polypaudio_CFLAGS = $(AM_CFLAGS) $(LIBSAMPLERATE_CFLAGS)
polypaudio_INCLUDES = $(INCLTDL) polypaudio_INCLUDES = $(INCLTDL)
polypaudio_LDADD = $(LIBLTDL) $(LIBSAMPLERATE_LIBS) polypaudio_LDADD = $(LIBLTDL) $(LIBSAMPLERATE_LIBS)

248
src/cli.c
View file

@ -15,94 +15,94 @@
#include "strbuf.h" #include "strbuf.h"
#include "namereg.h" #include "namereg.h"
struct cli { struct pa_cli {
struct core *core; struct pa_core *core;
struct ioline *line; struct pa_ioline *line;
void (*eof_callback)(struct cli *c, void *userdata); void (*eof_callback)(struct pa_cli *c, void *userdata);
void *userdata; void *userdata;
struct client *client; struct pa_client *client;
}; };
struct command { struct command {
const char *name; const char *name;
void (*proc) (struct cli *cli, struct tokenizer*t); void (*proc) (struct pa_cli *cli, struct pa_tokenizer*t);
const char *help; const char *help;
unsigned args; unsigned args;
}; };
static void line_callback(struct ioline *line, const char *s, void *userdata); static void line_callback(struct pa_ioline *line, const char *s, void *userdata);
static void cli_command_exit(struct cli *c, struct tokenizer *t); static void pa_cli_command_exit(struct pa_cli *c, struct pa_tokenizer *t);
static void cli_command_help(struct cli *c, struct tokenizer *t); static void pa_cli_command_help(struct pa_cli *c, struct pa_tokenizer *t);
static void cli_command_modules(struct cli *c, struct tokenizer *t); static void pa_cli_command_modules(struct pa_cli *c, struct pa_tokenizer *t);
static void cli_command_clients(struct cli *c, struct tokenizer *t); static void pa_cli_command_clients(struct pa_cli *c, struct pa_tokenizer *t);
static void cli_command_sinks(struct cli *c, struct tokenizer *t); static void pa_cli_command_sinks(struct pa_cli *c, struct pa_tokenizer *t);
static void cli_command_sources(struct cli *c, struct tokenizer *t); static void pa_cli_command_sources(struct pa_cli *c, struct pa_tokenizer *t);
static void cli_command_sink_inputs(struct cli *c, struct tokenizer *t); static void pa_cli_command_sink_inputs(struct pa_cli *c, struct pa_tokenizer *t);
static void cli_command_source_outputs(struct cli *c, struct tokenizer *t); static void pa_cli_command_source_outputs(struct pa_cli *c, struct pa_tokenizer *t);
static void cli_command_stat(struct cli *c, struct tokenizer *t); static void pa_cli_command_stat(struct pa_cli *c, struct pa_tokenizer *t);
static void cli_command_info(struct cli *c, struct tokenizer *t); static void pa_cli_command_info(struct pa_cli *c, struct pa_tokenizer *t);
static void cli_command_load(struct cli *c, struct tokenizer *t); static void pa_cli_command_load(struct pa_cli *c, struct pa_tokenizer *t);
static void cli_command_unload(struct cli *c, struct tokenizer *t); static void pa_cli_command_unload(struct pa_cli *c, struct pa_tokenizer *t);
static void cli_command_sink_volume(struct cli *c, struct tokenizer *t); static void pa_cli_command_sink_volume(struct pa_cli *c, struct pa_tokenizer *t);
static void cli_command_sink_input_volume(struct cli *c, struct tokenizer *t); static void pa_cli_command_sink_input_volume(struct pa_cli *c, struct pa_tokenizer *t);
static const struct command commands[] = { static const struct command commands[] = {
{ "exit", cli_command_exit, "Terminate the daemon", 1 }, { "exit", pa_cli_command_exit, "Terminate the daemon", 1 },
{ "help", cli_command_help, "Show this help", 1 }, { "help", pa_cli_command_help, "Show this help", 1 },
{ "modules", cli_command_modules, "List loaded modules", 1 }, { "modules", pa_cli_command_modules, "List loaded modules", 1 },
{ "sinks", cli_command_sinks, "List loaded sinks", 1 }, { "sinks", pa_cli_command_sinks, "List loaded sinks", 1 },
{ "sources", cli_command_sources, "List loaded sources", 1 }, { "sources", pa_cli_command_sources, "List loaded sources", 1 },
{ "clients", cli_command_clients, "List loaded clients", 1 }, { "clients", pa_cli_command_clients, "List loaded clients", 1 },
{ "sink_inputs", cli_command_sink_inputs, "List sink inputs", 1 }, { "sink_inputs", pa_cli_command_sink_inputs, "List sink inputs", 1 },
{ "source_outputs", cli_command_source_outputs, "List source outputs", 1 }, { "source_outputs", pa_cli_command_source_outputs, "List source outputs", 1 },
{ "stat", cli_command_stat, "Show memory block statistics", 1 }, { "stat", pa_cli_command_stat, "Show memory block statistics", 1 },
{ "info", cli_command_info, "Show comprehensive status", 1 }, { "info", pa_cli_command_info, "Show comprehensive status", 1 },
{ "load", cli_command_load, "Load a module (args: name, arguments)", 3}, { "load", pa_cli_command_load, "Load a module (args: name, arguments)", 3},
{ "unload", cli_command_unload, "Unload a module (args: index)", 2}, { "unload", pa_cli_command_unload, "Unload a module (args: index)", 2},
{ "sink_volume", cli_command_sink_volume, "Set the volume of a sink (args: sink, volume)", 3}, { "sink_volume", pa_cli_command_sink_volume, "Set the volume of a sink (args: sink, volume)", 3},
{ "sink_input_volume", cli_command_sink_input_volume, "Set the volume of a sink input (args: sink input, volume)", 3}, { "sink_input_volume", pa_cli_command_sink_input_volume, "Set the volume of a sink input (args: sink input, volume)", 3},
{ NULL, NULL, NULL, 0 } { NULL, NULL, NULL, 0 }
}; };
static const char prompt[] = ">>> "; static const char prompt[] = ">>> ";
struct cli* cli_new(struct core *core, struct iochannel *io) { struct pa_cli* pa_cli_new(struct pa_core *core, struct pa_iochannel *io) {
char cname[256]; char cname[256];
struct cli *c; struct pa_cli *c;
assert(io); assert(io);
c = malloc(sizeof(struct cli)); c = malloc(sizeof(struct pa_cli));
assert(c); assert(c);
c->core = core; c->core = core;
c->line = ioline_new(io); c->line = pa_ioline_new(io);
assert(c->line); assert(c->line);
c->userdata = NULL; c->userdata = NULL;
c->eof_callback = NULL; c->eof_callback = NULL;
iochannel_peer_to_string(io, cname, sizeof(cname)); pa_iochannel_peer_to_string(io, cname, sizeof(cname));
c->client = client_new(core, "CLI", cname); c->client = pa_client_new(core, "CLI", cname);
assert(c->client); assert(c->client);
ioline_set_callback(c->line, line_callback, c); pa_ioline_set_callback(c->line, line_callback, c);
ioline_puts(c->line, "Welcome to polypaudio! Use \"help\" for usage information.\n"); pa_ioline_puts(c->line, "Welcome to polypaudio! Use \"help\" for usage information.\n");
ioline_puts(c->line, prompt); pa_ioline_puts(c->line, prompt);
return c; return c;
} }
void cli_free(struct cli *c) { void pa_cli_free(struct pa_cli *c) {
assert(c); assert(c);
ioline_free(c->line); pa_ioline_free(c->line);
client_free(c->client); pa_client_free(c->client);
free(c); free(c);
} }
static void line_callback(struct ioline *line, const char *s, void *userdata) { static void line_callback(struct pa_ioline *line, const char *s, void *userdata) {
struct cli *c = userdata; struct pa_cli *c = userdata;
const char *cs; const char *cs;
const char delimiter[] = " \t\n\r"; const char delimiter[] = " \t\n\r";
assert(line && c); assert(line && c);
@ -125,225 +125,225 @@ static void line_callback(struct ioline *line, const char *s, void *userdata) {
for (command = commands; command->name; command++) for (command = commands; command->name; command++)
if (strlen(command->name) == l && !strncmp(s, command->name, l)) { if (strlen(command->name) == l && !strncmp(s, command->name, l)) {
struct tokenizer *t = tokenizer_new(s, command->args); struct pa_tokenizer *t = pa_tokenizer_new(s, command->args);
assert(t); assert(t);
command->proc(c, t); command->proc(c, t);
tokenizer_free(t); pa_tokenizer_free(t);
unknown = 0; unknown = 0;
break; break;
} }
if (unknown) if (unknown)
ioline_puts(line, "Unknown command\n"); pa_ioline_puts(line, "Unknown command\n");
} }
ioline_puts(c->line, prompt); pa_ioline_puts(c->line, prompt);
} }
void cli_set_eof_callback(struct cli *c, void (*cb)(struct cli*c, void *userdata), void *userdata) { void pa_cli_set_eof_callback(struct pa_cli *c, void (*cb)(struct pa_cli*c, void *userdata), void *userdata) {
assert(c && cb); assert(c && cb);
c->eof_callback = cb; c->eof_callback = cb;
c->userdata = userdata; c->userdata = userdata;
} }
static void cli_command_exit(struct cli *c, struct tokenizer *t) { static void pa_cli_command_exit(struct pa_cli *c, struct pa_tokenizer *t) {
assert(c && c->core && c->core->mainloop && t); assert(c && c->core && c->core->mainloop && t);
c->core->mainloop->quit(c->core->mainloop, 0); c->core->mainloop->quit(c->core->mainloop, 0);
} }
static void cli_command_help(struct cli *c, struct tokenizer *t) { static void pa_cli_command_help(struct pa_cli *c, struct pa_tokenizer *t) {
const struct command*command; const struct command*command;
struct strbuf *strbuf; struct pa_strbuf *pa_strbuf;
char *p; char *p;
assert(c && t); assert(c && t);
strbuf = strbuf_new(); pa_strbuf = pa_strbuf_new();
assert(strbuf); assert(pa_strbuf);
strbuf_puts(strbuf, "Available commands:\n"); pa_strbuf_puts(pa_strbuf, "Available commands:\n");
for (command = commands; command->name; command++) for (command = commands; command->name; command++)
strbuf_printf(strbuf, " %-20s %s\n", command->name, command->help); pa_strbuf_printf(pa_strbuf, " %-20s %s\n", command->name, command->help);
ioline_puts(c->line, p = strbuf_tostring_free(strbuf)); pa_ioline_puts(c->line, p = pa_strbuf_tostring_free(pa_strbuf));
free(p); free(p);
} }
static void cli_command_modules(struct cli *c, struct tokenizer *t) { static void pa_cli_command_modules(struct pa_cli *c, struct pa_tokenizer *t) {
char *s; char *s;
assert(c && t); assert(c && t);
s = module_list_to_string(c->core); s = pa_module_list_to_string(c->core);
assert(s); assert(s);
ioline_puts(c->line, s); pa_ioline_puts(c->line, s);
free(s); free(s);
} }
static void cli_command_clients(struct cli *c, struct tokenizer *t) { static void pa_cli_command_clients(struct pa_cli *c, struct pa_tokenizer *t) {
char *s; char *s;
assert(c && t); assert(c && t);
s = client_list_to_string(c->core); s = pa_client_list_to_string(c->core);
assert(s); assert(s);
ioline_puts(c->line, s); pa_ioline_puts(c->line, s);
free(s); free(s);
} }
static void cli_command_sinks(struct cli *c, struct tokenizer *t) { static void pa_cli_command_sinks(struct pa_cli *c, struct pa_tokenizer *t) {
char *s; char *s;
assert(c && t); assert(c && t);
s = sink_list_to_string(c->core); s = pa_sink_list_to_string(c->core);
assert(s); assert(s);
ioline_puts(c->line, s); pa_ioline_puts(c->line, s);
free(s); free(s);
} }
static void cli_command_sources(struct cli *c, struct tokenizer *t) { static void pa_cli_command_sources(struct pa_cli *c, struct pa_tokenizer *t) {
char *s; char *s;
assert(c && t); assert(c && t);
s = source_list_to_string(c->core); s = pa_source_list_to_string(c->core);
assert(s); assert(s);
ioline_puts(c->line, s); pa_ioline_puts(c->line, s);
free(s); free(s);
} }
static void cli_command_sink_inputs(struct cli *c, struct tokenizer *t) { static void pa_cli_command_sink_inputs(struct pa_cli *c, struct pa_tokenizer *t) {
char *s; char *s;
assert(c && t); assert(c && t);
s = sink_input_list_to_string(c->core); s = pa_sink_input_list_to_string(c->core);
assert(s); assert(s);
ioline_puts(c->line, s); pa_ioline_puts(c->line, s);
free(s); free(s);
} }
static void cli_command_source_outputs(struct cli *c, struct tokenizer *t) { static void pa_cli_command_source_outputs(struct pa_cli *c, struct pa_tokenizer *t) {
char *s; char *s;
assert(c && t); assert(c && t);
s = source_output_list_to_string(c->core); s = pa_source_output_list_to_string(c->core);
assert(s); assert(s);
ioline_puts(c->line, s); pa_ioline_puts(c->line, s);
free(s); free(s);
} }
static void cli_command_stat(struct cli *c, struct tokenizer *t) { static void pa_cli_command_stat(struct pa_cli *c, struct pa_tokenizer *t) {
char txt[256]; char txt[256];
assert(c && t); assert(c && t);
snprintf(txt, sizeof(txt), "Memory blocks allocated: %u, total size: %u bytes.\n", memblock_count, memblock_total); snprintf(txt, sizeof(txt), "Memory blocks allocated: %u, total size: %u bytes.\n", pa_memblock_count, pa_memblock_total);
ioline_puts(c->line, txt); pa_ioline_puts(c->line, txt);
} }
static void cli_command_info(struct cli *c, struct tokenizer *t) { static void pa_cli_command_info(struct pa_cli *c, struct pa_tokenizer *t) {
assert(c && t); assert(c && t);
cli_command_stat(c, t); pa_cli_command_stat(c, t);
cli_command_modules(c, t); pa_cli_command_modules(c, t);
cli_command_sources(c, t); pa_cli_command_sources(c, t);
cli_command_sinks(c, t); pa_cli_command_sinks(c, t);
cli_command_clients(c, t); pa_cli_command_clients(c, t);
cli_command_sink_inputs(c, t); pa_cli_command_sink_inputs(c, t);
cli_command_source_outputs(c, t); pa_cli_command_source_outputs(c, t);
} }
static void cli_command_load(struct cli *c, struct tokenizer *t) { static void pa_cli_command_load(struct pa_cli *c, struct pa_tokenizer *t) {
struct module *m; struct pa_module *m;
const char *name; const char *name;
char txt[256]; char txt[256];
assert(c && t); assert(c && t);
if (!(name = tokenizer_get(t, 1))) { if (!(name = pa_tokenizer_get(t, 1))) {
ioline_puts(c->line, "You need to specfiy the module name and optionally arguments.\n"); pa_ioline_puts(c->line, "You need to specfiy the module name and optionally arguments.\n");
return; return;
} }
if (!(m = module_load(c->core, name, tokenizer_get(t, 2)))) { if (!(m = pa_module_load(c->core, name, pa_tokenizer_get(t, 2)))) {
ioline_puts(c->line, "Module load failed.\n"); pa_ioline_puts(c->line, "Module load failed.\n");
return; return;
} }
snprintf(txt, sizeof(txt), "Module successfully loaded, index: %u.\n", m->index); snprintf(txt, sizeof(txt), "Module successfully loaded, index: %u.\n", m->index);
ioline_puts(c->line, txt); pa_ioline_puts(c->line, txt);
} }
static void cli_command_unload(struct cli *c, struct tokenizer *t) { static void pa_cli_command_unload(struct pa_cli *c, struct pa_tokenizer *t) {
struct module *m; struct pa_module *m;
uint32_t index; uint32_t index;
const char *i; const char *i;
char *e; char *e;
assert(c && t); assert(c && t);
if (!(i = tokenizer_get(t, 1))) { if (!(i = pa_tokenizer_get(t, 1))) {
ioline_puts(c->line, "You need to specfiy the module index.\n"); pa_ioline_puts(c->line, "You need to specfiy the module index.\n");
return; return;
} }
index = (uint32_t) strtoul(i, &e, 10); index = (uint32_t) strtoul(i, &e, 10);
if (*e || !(m = idxset_get_by_index(c->core->modules, index))) { if (*e || !(m = pa_idxset_get_by_index(c->core->modules, index))) {
ioline_puts(c->line, "Invalid module index.\n"); pa_ioline_puts(c->line, "Invalid module index.\n");
return; return;
} }
module_unload_request(c->core, m); pa_module_unload_request(c->core, m);
} }
static void cli_command_sink_volume(struct cli *c, struct tokenizer *t) { static void pa_cli_command_sink_volume(struct pa_cli *c, struct pa_tokenizer *t) {
const char *n, *v; const char *n, *v;
char *x = NULL; char *x = NULL;
struct sink *sink; struct pa_sink *sink;
long volume; long volume;
if (!(n = tokenizer_get(t, 1))) { if (!(n = pa_tokenizer_get(t, 1))) {
ioline_puts(c->line, "You need to specify a sink either by its name or its index.\n"); pa_ioline_puts(c->line, "You need to specify a sink either by its name or its index.\n");
return; return;
} }
if (!(v = tokenizer_get(t, 2))) { if (!(v = pa_tokenizer_get(t, 2))) {
ioline_puts(c->line, "You need to specify a volume >= 0. (0 is muted, 0x100 is normal volume)\n"); pa_ioline_puts(c->line, "You need to specify a volume >= 0. (0 is muted, 0x100 is normal volume)\n");
return; return;
} }
volume = strtol(v, &x, 0); volume = strtol(v, &x, 0);
if (!x || *x != 0 || volume < 0) { if (!x || *x != 0 || volume < 0) {
ioline_puts(c->line, "Failed to parse volume.\n"); pa_ioline_puts(c->line, "Failed to parse volume.\n");
return; return;
} }
if (!(sink = namereg_get(c->core, n, NAMEREG_SINK))) { if (!(sink = pa_namereg_get(c->core, n, PA_NAMEREG_SINK))) {
ioline_puts(c->line, "No sink found by this name or index.\n"); pa_ioline_puts(c->line, "No sink found by this name or index.\n");
return; return;
} }
sink->volume = (uint32_t) volume; sink->volume = (uint32_t) volume;
} }
static void cli_command_sink_input_volume(struct cli *c, struct tokenizer *t) { static void pa_cli_command_sink_input_volume(struct pa_cli *c, struct pa_tokenizer *t) {
const char *n, *v; const char *n, *v;
char *x = NULL; char *x = NULL;
struct sink_input *si; struct pa_sink_input *si;
long index, volume; long index, volume;
if (!(n = tokenizer_get(t, 1))) { if (!(n = pa_tokenizer_get(t, 1))) {
ioline_puts(c->line, "You need to specify a sink input by its index.\n"); pa_ioline_puts(c->line, "You need to specify a sink input by its index.\n");
return; return;
} }
index = strtol(n, &x, 0); index = strtol(n, &x, 0);
if (!x || *x != 0 || index < 0) { if (!x || *x != 0 || index < 0) {
ioline_puts(c->line, "Failed to parse index.\n"); pa_ioline_puts(c->line, "Failed to parse index.\n");
return; return;
} }
if (!(v = tokenizer_get(t, 2))) { if (!(v = pa_tokenizer_get(t, 2))) {
ioline_puts(c->line, "You need to specify a volume >= 0. (0 is muted, 0x100 is normal volume)\n"); pa_ioline_puts(c->line, "You need to specify a volume >= 0. (0 is muted, 0x100 is normal volume)\n");
return; return;
} }
x = NULL; x = NULL;
volume = strtol(v, &x, 0); volume = strtol(v, &x, 0);
if (!x || *x != 0 || volume < 0) { if (!x || *x != 0 || volume < 0) {
ioline_puts(c->line, "Failed to parse volume.\n"); pa_ioline_puts(c->line, "Failed to parse volume.\n");
return; return;
} }
if (!(si = idxset_get_by_index(c->core->sink_inputs, (uint32_t) index))) { if (!(si = pa_idxset_get_by_index(c->core->sink_inputs, (uint32_t) index))) {
ioline_puts(c->line, "No sink input found with this index.\n"); pa_ioline_puts(c->line, "No sink input found with this index.\n");
return; return;
} }

View file

@ -4,11 +4,11 @@
#include "iochannel.h" #include "iochannel.h"
#include "core.h" #include "core.h"
struct cli; struct pa_cli;
struct cli* cli_new(struct core *core, struct iochannel *io); struct pa_cli* pa_cli_new(struct pa_core *core, struct pa_iochannel *io);
void cli_free(struct cli *cli); void pa_cli_free(struct pa_cli *cli);
void cli_set_eof_callback(struct cli *cli, void (*cb)(struct cli*c, void *userdata), void *userdata); void pa_cli_set_eof_callback(struct pa_cli *cli, void (*cb)(struct pa_cli*c, void *userdata), void *userdata);
#endif #endif

View file

@ -6,12 +6,12 @@
#include "client.h" #include "client.h"
#include "strbuf.h" #include "strbuf.h"
struct client *client_new(struct core *core, const char *protocol_name, char *name) { struct pa_client *pa_client_new(struct pa_core *core, const char *protocol_name, char *name) {
struct client *c; struct pa_client *c;
int r; int r;
assert(core); assert(core);
c = malloc(sizeof(struct client)); c = malloc(sizeof(struct pa_client));
assert(c); assert(c);
c->name = name ? strdup(name) : NULL; c->name = name ? strdup(name) : NULL;
c->core = core; c->core = core;
@ -20,48 +20,48 @@ struct client *client_new(struct core *core, const char *protocol_name, char *na
c->kill = NULL; c->kill = NULL;
c->userdata = NULL; c->userdata = NULL;
r = idxset_put(core->clients, c, &c->index); r = pa_idxset_put(core->clients, c, &c->index);
assert(c->index != IDXSET_INVALID && r >= 0); assert(c->index != PA_IDXSET_INVALID && r >= 0);
fprintf(stderr, "client: created %u \"%s\"\n", c->index, c->name); fprintf(stderr, "client: created %u \"%s\"\n", c->index, c->name);
return c; return c;
} }
void client_free(struct client *c) { void pa_client_free(struct pa_client *c) {
assert(c && c->core); assert(c && c->core);
idxset_remove_by_data(c->core->clients, c, NULL); pa_idxset_remove_by_data(c->core->clients, c, NULL);
fprintf(stderr, "client: freed %u \"%s\"\n", c->index, c->name); fprintf(stderr, "client: freed %u \"%s\"\n", c->index, c->name);
free(c->name); free(c->name);
free(c); free(c);
} }
void client_kill(struct client *c) { void pa_client_kill(struct pa_client *c) {
assert(c); assert(c);
if (c->kill) if (c->kill)
c->kill(c); c->kill(c);
} }
char *client_list_to_string(struct core *c) { char *pa_client_list_to_string(struct pa_core *c) {
struct strbuf *s; struct pa_strbuf *s;
struct client *client; struct pa_client *client;
uint32_t index = IDXSET_INVALID; uint32_t index = PA_IDXSET_INVALID;
assert(c); assert(c);
s = strbuf_new(); s = pa_strbuf_new();
assert(s); assert(s);
strbuf_printf(s, "%u client(s).\n", idxset_ncontents(c->clients)); pa_strbuf_printf(s, "%u client(s).\n", pa_idxset_ncontents(c->clients));
for (client = idxset_first(c->clients, &index); client; client = idxset_next(c->clients, &index)) for (client = pa_idxset_first(c->clients, &index); client; client = pa_idxset_next(c->clients, &index))
strbuf_printf(s, " index: %u, name: <%s>, protocol_name: <%s>\n", client->index, client->name, client->protocol_name); pa_strbuf_printf(s, " index: %u, name: <%s>, protocol_name: <%s>\n", client->index, client->name, client->protocol_name);
return strbuf_tostring_free(s); return pa_strbuf_tostring_free(s);
} }
void client_rename(struct client *c, const char *name) { void pa_client_rename(struct pa_client *c, const char *name) {
assert(c); assert(c);
free(c->name); free(c->name);
c->name = name ? strdup(name) : NULL; c->name = name ? strdup(name) : NULL;

View file

@ -3,28 +3,28 @@
#include "core.h" #include "core.h"
struct client { struct pa_client {
uint32_t index; uint32_t index;
char *name; char *name;
struct core *core; struct pa_core *core;
const char *protocol_name; const char *protocol_name;
void (*kill)(struct client *c); void (*kill)(struct pa_client *c);
void *userdata; void *userdata;
}; };
struct client *client_new(struct core *c, const char *protocol_name, char *name); struct pa_client *pa_client_new(struct pa_core *c, const char *protocol_name, char *name);
/* This function should be called only by the code that created the client */ /* This function should be called only by the code that created the client */
void client_free(struct client *c); void pa_client_free(struct pa_client *c);
/* Code that didn't create the client should call this function to /* Code that didn't create the client should call this function to
* request destruction of the client */ * request destruction of the client */
void client_kill(struct client *c); void pa_client_kill(struct pa_client *c);
char *client_list_to_string(struct core *c); char *pa_client_list_to_string(struct pa_core *c);
void client_rename(struct client *c, const char *name); void pa_client_rename(struct pa_client *c, const char *name);
#endif #endif

View file

@ -8,19 +8,19 @@
#include "source.h" #include "source.h"
#include "namereg.h" #include "namereg.h"
struct core* core_new(struct pa_mainloop_api *m) { struct pa_core* pa_core_new(struct pa_mainloop_api *m) {
struct core* c; struct pa_core* c;
c = malloc(sizeof(struct core)); c = malloc(sizeof(struct pa_core));
assert(c); assert(c);
c->mainloop = m; c->mainloop = m;
c->clients = idxset_new(NULL, NULL); c->clients = pa_idxset_new(NULL, NULL);
c->sinks = idxset_new(NULL, NULL); c->sinks = pa_idxset_new(NULL, NULL);
c->sources = idxset_new(NULL, NULL); c->sources = pa_idxset_new(NULL, NULL);
c->source_outputs = idxset_new(NULL, NULL); c->source_outputs = pa_idxset_new(NULL, NULL);
c->sink_inputs = idxset_new(NULL, NULL); c->sink_inputs = pa_idxset_new(NULL, NULL);
c->default_source_index = c->default_sink_index = IDXSET_INVALID; c->default_source_index = c->default_sink_index = PA_IDXSET_INVALID;
c->modules = NULL; c->modules = NULL;
c->namereg = NULL; c->namereg = NULL;
@ -28,28 +28,28 @@ struct core* core_new(struct pa_mainloop_api *m) {
return c; return c;
}; };
void core_free(struct core *c) { void pa_core_free(struct pa_core *c) {
assert(c); assert(c);
module_unload_all(c); pa_module_unload_all(c);
assert(!c->modules); assert(!c->modules);
assert(idxset_isempty(c->clients)); assert(pa_idxset_isempty(c->clients));
idxset_free(c->clients, NULL, NULL); pa_idxset_free(c->clients, NULL, NULL);
assert(idxset_isempty(c->sinks)); assert(pa_idxset_isempty(c->sinks));
idxset_free(c->sinks, NULL, NULL); pa_idxset_free(c->sinks, NULL, NULL);
assert(idxset_isempty(c->sources)); assert(pa_idxset_isempty(c->sources));
idxset_free(c->sources, NULL, NULL); pa_idxset_free(c->sources, NULL, NULL);
assert(idxset_isempty(c->source_outputs)); assert(pa_idxset_isempty(c->source_outputs));
idxset_free(c->source_outputs, NULL, NULL); pa_idxset_free(c->source_outputs, NULL, NULL);
assert(idxset_isempty(c->sink_inputs)); assert(pa_idxset_isempty(c->sink_inputs));
idxset_free(c->sink_inputs, NULL, NULL); pa_idxset_free(c->sink_inputs, NULL, NULL);
namereg_free(c); pa_namereg_free(c);
free(c); free(c);
}; };

View file

@ -5,17 +5,17 @@
#include "hashset.h" #include "hashset.h"
#include "mainloop-api.h" #include "mainloop-api.h"
struct core { struct pa_core {
struct pa_mainloop_api *mainloop; struct pa_mainloop_api *mainloop;
struct idxset *clients, *sinks, *sources, *sink_inputs, *source_outputs, *modules; struct pa_idxset *clients, *sinks, *sources, *sink_inputs, *source_outputs, *modules;
struct hashset *namereg; struct pa_hashset *namereg;
uint32_t default_source_index, default_sink_index; uint32_t default_source_index, default_sink_index;
}; };
struct core* core_new(struct pa_mainloop_api *m); struct pa_core* pa_core_new(struct pa_mainloop_api *m);
void core_free(struct core*c); void pa_core_free(struct pa_core*c);
#endif #endif

View file

@ -4,14 +4,14 @@
#include "dynarray.h" #include "dynarray.h"
struct dynarray { struct pa_dynarray {
void **data; void **data;
unsigned n_allocated, n_entries; unsigned n_allocated, n_entries;
}; };
struct dynarray* dynarray_new(void) { struct pa_dynarray* pa_dynarray_new(void) {
struct dynarray *a; struct pa_dynarray *a;
a = malloc(sizeof(struct dynarray)); a = malloc(sizeof(struct pa_dynarray));
assert(a); assert(a);
a->data = NULL; a->data = NULL;
a->n_entries = 0; a->n_entries = 0;
@ -19,7 +19,7 @@ struct dynarray* dynarray_new(void) {
return a; return a;
} }
void dynarray_free(struct dynarray* a, void (*func)(void *p, void *userdata), void *userdata) { void pa_dynarray_free(struct pa_dynarray* a, void (*func)(void *p, void *userdata), void *userdata) {
unsigned i; unsigned i;
assert(a); assert(a);
@ -32,7 +32,7 @@ void dynarray_free(struct dynarray* a, void (*func)(void *p, void *userdata), vo
free(a); free(a);
} }
void dynarray_put(struct dynarray*a, unsigned i, void *p) { void pa_dynarray_put(struct pa_dynarray*a, unsigned i, void *p) {
assert(a); assert(a);
if (i >= a->n_allocated) { if (i >= a->n_allocated) {
@ -53,13 +53,13 @@ void dynarray_put(struct dynarray*a, unsigned i, void *p) {
a->n_entries = i+1; a->n_entries = i+1;
} }
unsigned dynarray_append(struct dynarray*a, void *p) { unsigned pa_dynarray_append(struct pa_dynarray*a, void *p) {
unsigned i = a->n_entries; unsigned i = a->n_entries;
dynarray_put(a, i, p); pa_dynarray_put(a, i, p);
return i; return i;
} }
void *dynarray_get(struct dynarray*a, unsigned i) { void *pa_dynarray_get(struct pa_dynarray*a, unsigned i) {
assert(a); assert(a);
if (i >= a->n_allocated) if (i >= a->n_allocated)
return NULL; return NULL;
@ -67,7 +67,7 @@ void *dynarray_get(struct dynarray*a, unsigned i) {
return a->data[i]; return a->data[i];
} }
unsigned dynarray_ncontents(struct dynarray*a) { unsigned pa_dynarray_ncontents(struct pa_dynarray*a) {
assert(a); assert(a);
return a->n_entries; return a->n_entries;
} }

View file

@ -1,16 +1,16 @@
#ifndef foodynarrayhfoo #ifndef foodynarrayhfoo
#define foodynarrayhfoo #define foodynarrayhfoo
struct dynarray; struct pa_dynarray;
struct dynarray* dynarray_new(void); struct pa_dynarray* pa_dynarray_new(void);
void dynarray_free(struct dynarray* a, void (*func)(void *p, void *userdata), void *userdata); void pa_dynarray_free(struct pa_dynarray* a, void (*func)(void *p, void *userdata), void *userdata);
void dynarray_put(struct dynarray*a, unsigned i, void *p); void pa_dynarray_put(struct pa_dynarray*a, unsigned i, void *p);
unsigned dynarray_append(struct dynarray*a, void *p); unsigned pa_dynarray_append(struct pa_dynarray*a, void *p);
void *dynarray_get(struct dynarray*a, unsigned i); void *pa_dynarray_get(struct pa_dynarray*a, unsigned i);
unsigned dynarray_ncontents(struct dynarray*a); unsigned pa_dynarray_ncontents(struct pa_dynarray*a);
#endif #endif

View file

@ -12,7 +12,7 @@ struct hashset_entry {
void *value; void *value;
}; };
struct hashset { struct pa_hashset {
unsigned size; unsigned size;
struct hashset_entry **data; struct hashset_entry **data;
struct hashset_entry *first_entry; struct hashset_entry *first_entry;
@ -22,21 +22,21 @@ struct hashset {
int (*compare_func) (const void*a, const void*b); int (*compare_func) (const void*a, const void*b);
}; };
struct hashset *hashset_new(unsigned (*hash_func) (const void *p), int (*compare_func) (const void*a, const void*b)) { struct pa_hashset *pa_hashset_new(unsigned (*hash_func) (const void *p), int (*compare_func) (const void*a, const void*b)) {
struct hashset *h; struct pa_hashset *h;
h = malloc(sizeof(struct hashset)); h = malloc(sizeof(struct pa_hashset));
assert(h); assert(h);
h->data = malloc(sizeof(struct hashset_entry*)*(h->size = 1023)); h->data = malloc(sizeof(struct hashset_entry*)*(h->size = 1023));
assert(h->data); assert(h->data);
memset(h->data, 0, sizeof(struct hashset_entry*)*(h->size = 1023)); memset(h->data, 0, sizeof(struct hashset_entry*)*(h->size = 1023));
h->first_entry = NULL; h->first_entry = NULL;
h->n_entries = 0; h->n_entries = 0;
h->hash_func = hash_func ? hash_func : idxset_trivial_hash_func; h->hash_func = hash_func ? hash_func : pa_idxset_trivial_hash_func;
h->compare_func = compare_func ? compare_func : idxset_trivial_compare_func; h->compare_func = compare_func ? compare_func : pa_idxset_trivial_compare_func;
return h; return h;
} }
static void remove(struct hashset *h, struct hashset_entry *e) { static void remove(struct pa_hashset *h, struct hashset_entry *e) {
assert(e); assert(e);
if (e->next) if (e->next)
@ -57,7 +57,7 @@ static void remove(struct hashset *h, struct hashset_entry *e) {
h->n_entries--; h->n_entries--;
} }
void hashset_free(struct hashset*h, void (*free_func)(void *p, void *userdata), void *userdata) { void pa_hashset_free(struct pa_hashset*h, void (*free_func)(void *p, void *userdata), void *userdata) {
assert(h); assert(h);
while (h->first_entry) { while (h->first_entry) {
@ -70,7 +70,7 @@ void hashset_free(struct hashset*h, void (*free_func)(void *p, void *userdata),
free(h); free(h);
} }
static struct hashset_entry *get(struct hashset *h, unsigned hash, const void *key) { static struct hashset_entry *get(struct pa_hashset *h, unsigned hash, const void *key) {
struct hashset_entry *e; struct hashset_entry *e;
for (e = h->data[hash]; e; e = e->bucket_next) for (e = h->data[hash]; e; e = e->bucket_next)
@ -80,7 +80,7 @@ static struct hashset_entry *get(struct hashset *h, unsigned hash, const void *k
return NULL; return NULL;
} }
int hashset_put(struct hashset *h, const void *key, void *value) { int pa_hashset_put(struct pa_hashset *h, const void *key, void *value) {
struct hashset_entry *e; struct hashset_entry *e;
unsigned hash; unsigned hash;
assert(h && key); assert(h && key);
@ -113,7 +113,7 @@ int hashset_put(struct hashset *h, const void *key, void *value) {
return 0; return 0;
} }
void* hashset_get(struct hashset *h, const void *key) { void* pa_hashset_get(struct pa_hashset *h, const void *key) {
unsigned hash; unsigned hash;
struct hashset_entry *e; struct hashset_entry *e;
assert(h && key); assert(h && key);
@ -126,7 +126,7 @@ void* hashset_get(struct hashset *h, const void *key) {
return e->value; return e->value;
} }
int hashset_remove(struct hashset *h, const void *key) { int pa_hashset_remove(struct pa_hashset *h, const void *key) {
struct hashset_entry *e; struct hashset_entry *e;
unsigned hash; unsigned hash;
assert(h && key); assert(h && key);
@ -140,6 +140,6 @@ int hashset_remove(struct hashset *h, const void *key) {
return 0; return 0;
} }
unsigned hashset_ncontents(struct hashset *h) { unsigned pa_hashset_ncontents(struct pa_hashset *h) {
return h->n_entries; return h->n_entries;
} }

View file

@ -1,16 +1,16 @@
#ifndef foohashsethfoo #ifndef foohashsethfoo
#define foohashsethfoo #define foohashsethfoo
struct hashset; struct pa_hashset;
struct hashset *hashset_new(unsigned (*hash_func) (const void *p), int (*compare_func) (const void*a, const void*b)); struct pa_hashset *pa_hashset_new(unsigned (*hash_func) (const void *p), int (*compare_func) (const void*a, const void*b));
void hashset_free(struct hashset*, void (*free_func)(void *p, void *userdata), void *userdata); void pa_hashset_free(struct pa_hashset*, void (*free_func)(void *p, void *userdata), void *userdata);
int hashset_put(struct hashset *h, const void *key, void *value); int pa_hashset_put(struct pa_hashset *h, const void *key, void *value);
void* hashset_get(struct hashset *h, const void *key); void* pa_hashset_get(struct pa_hashset *h, const void *key);
int hashset_remove(struct hashset *h, const void *key); int pa_hashset_remove(struct pa_hashset *h, const void *key);
unsigned hashset_ncontents(struct hashset *h); unsigned pa_hashset_ncontents(struct pa_hashset *h);
#endif #endif

View file

@ -14,7 +14,7 @@ struct idxset_entry {
struct idxset_entry* iterate_prev, *iterate_next; struct idxset_entry* iterate_prev, *iterate_next;
}; };
struct idxset { struct pa_idxset {
unsigned (*hash_func) (const void *p); unsigned (*hash_func) (const void *p);
int (*compare_func)(const void *a, const void *b); int (*compare_func)(const void *a, const void *b);
@ -23,7 +23,7 @@ struct idxset {
uint32_t index, start_index, array_size; uint32_t index, start_index, array_size;
}; };
unsigned idxset_string_hash_func(const void *p) { unsigned pa_idxset_string_hash_func(const void *p) {
unsigned hash = 0; unsigned hash = 0;
const char *c; const char *c;
@ -33,25 +33,25 @@ unsigned idxset_string_hash_func(const void *p) {
return hash; return hash;
} }
int idxset_string_compare_func(const void *a, const void *b) { int pa_idxset_string_compare_func(const void *a, const void *b) {
return strcmp(a, b); return strcmp(a, b);
} }
unsigned idxset_trivial_hash_func(const void *p) { unsigned pa_idxset_trivial_hash_func(const void *p) {
return (unsigned) p; return (unsigned) p;
} }
int idxset_trivial_compare_func(const void *a, const void *b) { int pa_idxset_trivial_compare_func(const void *a, const void *b) {
return a != b; return a != b;
} }
struct idxset* idxset_new(unsigned (*hash_func) (const void *p), int (*compare_func) (const void*a, const void*b)) { struct pa_idxset* pa_idxset_new(unsigned (*hash_func) (const void *p), int (*compare_func) (const void*a, const void*b)) {
struct idxset *s; struct pa_idxset *s;
s = malloc(sizeof(struct idxset)); s = malloc(sizeof(struct pa_idxset));
assert(s); assert(s);
s->hash_func = hash_func ? hash_func : idxset_trivial_hash_func; s->hash_func = hash_func ? hash_func : pa_idxset_trivial_hash_func;
s->compare_func = compare_func ? compare_func : idxset_trivial_compare_func; s->compare_func = compare_func ? compare_func : pa_idxset_trivial_compare_func;
s->hash_table_size = 1023; s->hash_table_size = 1023;
s->hash_table = malloc(sizeof(struct idxset_entry*)*s->hash_table_size); s->hash_table = malloc(sizeof(struct idxset_entry*)*s->hash_table_size);
assert(s->hash_table); assert(s->hash_table);
@ -67,7 +67,7 @@ struct idxset* idxset_new(unsigned (*hash_func) (const void *p), int (*compare_f
return s; return s;
} }
void idxset_free(struct idxset *s, void (*free_func) (void *p, void *userdata), void *userdata) { void pa_idxset_free(struct pa_idxset *s, void (*free_func) (void *p, void *userdata), void *userdata) {
assert(s); assert(s);
if (free_func) { if (free_func) {
@ -86,7 +86,7 @@ void idxset_free(struct idxset *s, void (*free_func) (void *p, void *userdata),
free(s); free(s);
} }
static struct idxset_entry* hash_scan(struct idxset *s, struct idxset_entry* e, void *p) { static struct idxset_entry* hash_scan(struct pa_idxset *s, struct idxset_entry* e, void *p) {
assert(p); assert(p);
assert(s->compare_func); assert(s->compare_func);
@ -97,7 +97,7 @@ static struct idxset_entry* hash_scan(struct idxset *s, struct idxset_entry* e,
return NULL; return NULL;
} }
static void extend_array(struct idxset *s, uint32_t index) { static void extend_array(struct pa_idxset *s, uint32_t index) {
uint32_t i, j, l; uint32_t i, j, l;
struct idxset_entry** n; struct idxset_entry** n;
assert(index >= s->start_index); assert(index >= s->start_index);
@ -124,7 +124,7 @@ static void extend_array(struct idxset *s, uint32_t index) {
s->start_index += i; s->start_index += i;
} }
static struct idxset_entry** array_index(struct idxset*s, uint32_t index) { static struct idxset_entry** array_index(struct pa_idxset*s, uint32_t index) {
if (index >= s->start_index + s->array_size) if (index >= s->start_index + s->array_size)
return NULL; return NULL;
@ -134,7 +134,7 @@ static struct idxset_entry** array_index(struct idxset*s, uint32_t index) {
return s->array + (index - s->start_index); return s->array + (index - s->start_index);
} }
int idxset_put(struct idxset*s, void *p, uint32_t *index) { int pa_idxset_put(struct pa_idxset*s, void *p, uint32_t *index) {
unsigned h; unsigned h;
struct idxset_entry *e, **a; struct idxset_entry *e, **a;
assert(s && p); assert(s && p);
@ -191,7 +191,7 @@ int idxset_put(struct idxset*s, void *p, uint32_t *index) {
return 0; return 0;
} }
void* idxset_get_by_index(struct idxset*s, uint32_t index) { void* pa_idxset_get_by_index(struct pa_idxset*s, uint32_t index) {
struct idxset_entry **a; struct idxset_entry **a;
assert(s); assert(s);
@ -204,7 +204,7 @@ void* idxset_get_by_index(struct idxset*s, uint32_t index) {
return (*a)->data; return (*a)->data;
} }
void* idxset_get_by_data(struct idxset*s, void *p, uint32_t *index) { void* pa_idxset_get_by_data(struct pa_idxset*s, void *p, uint32_t *index) {
unsigned h; unsigned h;
struct idxset_entry *e; struct idxset_entry *e;
assert(s && p); assert(s && p);
@ -222,7 +222,7 @@ void* idxset_get_by_data(struct idxset*s, void *p, uint32_t *index) {
return e->data; return e->data;
} }
static void remove_entry(struct idxset *s, struct idxset_entry *e) { static void remove_entry(struct pa_idxset *s, struct idxset_entry *e) {
struct idxset_entry **a; struct idxset_entry **a;
assert(s && e); assert(s && e);
@ -257,7 +257,7 @@ static void remove_entry(struct idxset *s, struct idxset_entry *e) {
s->n_entries--; s->n_entries--;
} }
void* idxset_remove_by_index(struct idxset*s, uint32_t index) { void* pa_idxset_remove_by_index(struct pa_idxset*s, uint32_t index) {
struct idxset_entry **a; struct idxset_entry **a;
void *data; void *data;
@ -272,7 +272,7 @@ void* idxset_remove_by_index(struct idxset*s, uint32_t index) {
return data; return data;
} }
void* idxset_remove_by_data(struct idxset*s, void *data, uint32_t *index) { void* pa_idxset_remove_by_data(struct pa_idxset*s, void *data, uint32_t *index) {
struct idxset_entry *e; struct idxset_entry *e;
unsigned h; unsigned h;
@ -292,7 +292,7 @@ void* idxset_remove_by_data(struct idxset*s, void *data, uint32_t *index) {
return data; return data;
} }
void* idxset_rrobin(struct idxset *s, uint32_t *index) { void* pa_idxset_rrobin(struct pa_idxset *s, uint32_t *index) {
struct idxset_entry **a, *e = NULL; struct idxset_entry **a, *e = NULL;
assert(s && index); assert(s && index);
@ -309,7 +309,7 @@ void* idxset_rrobin(struct idxset *s, uint32_t *index) {
return e->data; return e->data;
} }
void* idxset_first(struct idxset *s, uint32_t *index) { void* pa_idxset_first(struct pa_idxset *s, uint32_t *index) {
assert(s); assert(s);
if (!s->iterate_list_head) if (!s->iterate_list_head)
@ -320,7 +320,7 @@ void* idxset_first(struct idxset *s, uint32_t *index) {
return s->iterate_list_head->data; return s->iterate_list_head->data;
} }
void *idxset_next(struct idxset *s, uint32_t *index) { void *pa_idxset_next(struct pa_idxset *s, uint32_t *index) {
struct idxset_entry **a, *e = NULL; struct idxset_entry **a, *e = NULL;
assert(s && index); assert(s && index);
@ -331,13 +331,13 @@ void *idxset_next(struct idxset *s, uint32_t *index) {
*index = e->index; *index = e->index;
return e->data; return e->data;
} else { } else {
*index = IDXSET_INVALID; *index = PA_IDXSET_INVALID;
return NULL; return NULL;
} }
} }
int idxset_foreach(struct idxset*s, int (*func)(void *p, uint32_t index, int *del, void*userdata), void *userdata) { int pa_idxset_foreach(struct pa_idxset*s, int (*func)(void *p, uint32_t index, int *del, void*userdata), void *userdata) {
struct idxset_entry *e; struct idxset_entry *e;
assert(s && func); assert(s && func);
@ -360,12 +360,12 @@ int idxset_foreach(struct idxset*s, int (*func)(void *p, uint32_t index, int *de
return 0; return 0;
} }
unsigned idxset_ncontents(struct idxset*s) { unsigned pa_idxset_ncontents(struct pa_idxset*s) {
assert(s); assert(s);
return s->n_entries; return s->n_entries;
} }
int idxset_isempty(struct idxset *s) { int pa_idxset_isempty(struct pa_idxset *s) {
assert(s); assert(s);
return s->n_entries == 0; return s->n_entries == 0;
} }

View file

@ -3,41 +3,40 @@
#include <inttypes.h> #include <inttypes.h>
#define IDXSET_INVALID ((uint32_t) -1) #define PA_IDXSET_INVALID ((uint32_t) -1)
unsigned idxset_trivial_hash_func(const void *p); unsigned pa_idxset_trivial_hash_func(const void *p);
int idxset_trivial_compare_func(const void *a, const void *b); int pa_idxset_trivial_compare_func(const void *a, const void *b);
unsigned idxset_string_hash_func(const void *p); unsigned pa_idxset_string_hash_func(const void *p);
int idxset_string_compare_func(const void *a, const void *b); int pa_idxset_string_compare_func(const void *a, const void *b);
struct idxset; struct pa_idxset;
struct idxset* idxset_new(unsigned (*hash_func) (const void *p), int (*compare_func) (const void*a, const void*b)); struct pa_idxset* pa_idxset_new(unsigned (*hash_func) (const void *p), int (*compare_func) (const void*a, const void*b));
void idxset_free(struct idxset *s, void (*free_func) (void *p, void *userdata), void *userdata); void pa_idxset_free(struct pa_idxset *s, void (*free_func) (void *p, void *userdata), void *userdata);
int idxset_put(struct idxset*s, void *p, uint32_t *index); int pa_idxset_put(struct pa_idxset*s, void *p, uint32_t *index);
void* idxset_get_by_index(struct idxset*s, uint32_t index); void* pa_idxset_get_by_index(struct pa_idxset*s, uint32_t index);
void* idxset_get_by_data(struct idxset*s, void *p, uint32_t *index); void* pa_idxset_get_by_data(struct pa_idxset*s, void *p, uint32_t *index);
void* idxset_remove_by_index(struct idxset*s, uint32_t index); void* pa_idxset_remove_by_index(struct pa_idxset*s, uint32_t index);
void* idxset_remove_by_data(struct idxset*s, void *p, uint32_t *index); void* pa_idxset_remove_by_data(struct pa_idxset*s, void *p, uint32_t *index);
/* This may be used to iterate through all entries. When called with /* This may be used to iterate through all entries. When called with
an invalid index value it returns the first entry, otherwise the an invalid index value it returns the first entry, otherwise the
next following. The function is best called with *index = next following. The function is best called with *index =
IDXSET_VALID first. */ PA_IDXSET_VALID first. */
void* idxset_rrobin(struct idxset *s, uint32_t *index); void* pa_idxset_rrobin(struct pa_idxset *s, uint32_t *index);
/* Return the oldest entry in the idxset */ /* Return the oldest entry in the idxset */
void* idxset_first(struct idxset *s, uint32_t *index); void* pa_idxset_first(struct pa_idxset *s, uint32_t *index);
void *idxset_next(struct idxset *s, uint32_t *index); void *pa_idxset_next(struct pa_idxset *s, uint32_t *index);
int idxset_foreach(struct idxset*s, int (*func)(void *p, uint32_t index, int *del, void*userdata), void *userdata); int pa_idxset_foreach(struct pa_idxset*s, int (*func)(void *p, uint32_t index, int *del, void*userdata), void *userdata);
unsigned idxset_ncontents(struct idxset*s);
int idxset_isempty(struct idxset *s);
unsigned pa_idxset_ncontents(struct pa_idxset*s);
int pa_idxset_isempty(struct pa_idxset *s);
#endif #endif

View file

@ -6,11 +6,11 @@
#include "iochannel.h" #include "iochannel.h"
#include "util.h" #include "util.h"
struct iochannel { struct pa_iochannel {
int ifd, ofd; int ifd, ofd;
struct pa_mainloop_api* mainloop; struct pa_mainloop_api* mainloop;
void (*callback)(struct iochannel*io, void *userdata); void (*callback)(struct pa_iochannel*io, void *userdata);
void*userdata; void*userdata;
int readable; int readable;
@ -21,7 +21,7 @@ struct iochannel {
void* input_source, *output_source; void* input_source, *output_source;
}; };
static void enable_mainloop_sources(struct iochannel *io) { static void enable_mainloop_sources(struct pa_iochannel *io) {
assert(io); assert(io);
if (io->input_source == io->output_source) { if (io->input_source == io->output_source) {
@ -43,7 +43,7 @@ static void enable_mainloop_sources(struct iochannel *io) {
} }
static void callback(struct pa_mainloop_api* m, void *id, int fd, enum pa_mainloop_api_io_events events, void *userdata) { static void callback(struct pa_mainloop_api* m, void *id, int fd, enum pa_mainloop_api_io_events events, void *userdata) {
struct iochannel *io = userdata; struct pa_iochannel *io = userdata;
int changed = 0; int changed = 0;
assert(m && fd >= 0 && events && userdata); assert(m && fd >= 0 && events && userdata);
@ -67,11 +67,11 @@ static void callback(struct pa_mainloop_api* m, void *id, int fd, enum pa_mainlo
} }
} }
struct iochannel* iochannel_new(struct pa_mainloop_api*m, int ifd, int ofd) { struct pa_iochannel* pa_iochannel_new(struct pa_mainloop_api*m, int ifd, int ofd) {
struct iochannel *io; struct pa_iochannel *io;
assert(m && (ifd >= 0 || ofd >= 0)); assert(m && (ifd >= 0 || ofd >= 0));
io = malloc(sizeof(struct iochannel)); io = malloc(sizeof(struct pa_iochannel));
io->ifd = ifd; io->ifd = ifd;
io->ofd = ofd; io->ofd = ofd;
io->mainloop = m; io->mainloop = m;
@ -84,18 +84,18 @@ struct iochannel* iochannel_new(struct pa_mainloop_api*m, int ifd, int ofd) {
if (ifd == ofd) { if (ifd == ofd) {
assert(ifd >= 0); assert(ifd >= 0);
make_nonblock_fd(io->ifd); pa_make_nonblock_fd(io->ifd);
io->input_source = io->output_source = m->source_io(m, ifd, PA_MAINLOOP_API_IO_EVENT_BOTH, callback, io); io->input_source = io->output_source = m->source_io(m, ifd, PA_MAINLOOP_API_IO_EVENT_BOTH, callback, io);
} else { } else {
if (ifd >= 0) { if (ifd >= 0) {
make_nonblock_fd(io->ifd); pa_make_nonblock_fd(io->ifd);
io->input_source = m->source_io(m, ifd, PA_MAINLOOP_API_IO_EVENT_INPUT, callback, io); io->input_source = m->source_io(m, ifd, PA_MAINLOOP_API_IO_EVENT_INPUT, callback, io);
} else } else
io->input_source = NULL; io->input_source = NULL;
if (ofd >= 0) { if (ofd >= 0) {
make_nonblock_fd(io->ofd); pa_make_nonblock_fd(io->ofd);
io->output_source = m->source_io(m, ofd, PA_MAINLOOP_API_IO_EVENT_OUTPUT, callback, io); io->output_source = m->source_io(m, ofd, PA_MAINLOOP_API_IO_EVENT_OUTPUT, callback, io);
} else } else
io->output_source = NULL; io->output_source = NULL;
@ -104,7 +104,7 @@ struct iochannel* iochannel_new(struct pa_mainloop_api*m, int ifd, int ofd) {
return io; return io;
} }
void iochannel_free(struct iochannel*io) { void pa_iochannel_free(struct pa_iochannel*io) {
assert(io); assert(io);
if (!io->no_close) { if (!io->no_close) {
@ -122,17 +122,17 @@ void iochannel_free(struct iochannel*io) {
free(io); free(io);
} }
int iochannel_is_readable(struct iochannel*io) { int pa_iochannel_is_readable(struct pa_iochannel*io) {
assert(io); assert(io);
return io->readable; return io->readable;
} }
int iochannel_is_writable(struct iochannel*io) { int pa_iochannel_is_writable(struct pa_iochannel*io) {
assert(io); assert(io);
return io->writable; return io->writable;
} }
ssize_t iochannel_write(struct iochannel*io, const void*data, size_t l) { ssize_t pa_iochannel_write(struct pa_iochannel*io, const void*data, size_t l) {
ssize_t r; ssize_t r;
assert(io && data && l && io->ofd >= 0); assert(io && data && l && io->ofd >= 0);
@ -144,7 +144,7 @@ ssize_t iochannel_write(struct iochannel*io, const void*data, size_t l) {
return r; return r;
} }
ssize_t iochannel_read(struct iochannel*io, void*data, size_t l) { ssize_t pa_iochannel_read(struct pa_iochannel*io, void*data, size_t l) {
ssize_t r; ssize_t r;
assert(io && data && io->ifd >= 0); assert(io && data && io->ifd >= 0);
@ -157,18 +157,18 @@ ssize_t iochannel_read(struct iochannel*io, void*data, size_t l) {
return r; return r;
} }
void iochannel_set_callback(struct iochannel*io, void (*callback)(struct iochannel*io, void *userdata), void *userdata) { void pa_iochannel_set_callback(struct pa_iochannel*io, void (*callback)(struct pa_iochannel*io, void *userdata), void *userdata) {
assert(io); assert(io);
io->callback = callback; io->callback = callback;
io->userdata = userdata; io->userdata = userdata;
} }
void iochannel_set_noclose(struct iochannel*io, int b) { void pa_iochannel_set_noclose(struct pa_iochannel*io, int b) {
assert(io); assert(io);
io->no_close = b; io->no_close = b;
} }
void iochannel_peer_to_string(struct iochannel*io, char*s, size_t l) { void pa_iochannel_peer_to_string(struct pa_iochannel*io, char*s, size_t l) {
assert(io && s && l); assert(io && s && l);
peer_to_string(s, l, io->ifd); pa_peer_to_string(s, l, io->ifd);
} }

View file

@ -4,21 +4,21 @@
#include <sys/types.h> #include <sys/types.h>
#include "mainloop-api.h" #include "mainloop-api.h"
struct iochannel; struct pa_iochannel;
struct iochannel* iochannel_new(struct pa_mainloop_api*m, int ifd, int ofd); struct pa_iochannel* pa_iochannel_new(struct pa_mainloop_api*m, int ifd, int ofd);
void iochannel_free(struct iochannel*io); void pa_iochannel_free(struct pa_iochannel*io);
ssize_t iochannel_write(struct iochannel*io, const void*data, size_t l); ssize_t pa_iochannel_write(struct pa_iochannel*io, const void*data, size_t l);
ssize_t iochannel_read(struct iochannel*io, void*data, size_t l); ssize_t pa_iochannel_read(struct pa_iochannel*io, void*data, size_t l);
int iochannel_is_readable(struct iochannel*io); int pa_iochannel_is_readable(struct pa_iochannel*io);
int iochannel_is_writable(struct iochannel*io); int pa_iochannel_is_writable(struct pa_iochannel*io);
void iochannel_set_noclose(struct iochannel*io, int b); void pa_iochannel_set_noclose(struct pa_iochannel*io, int b);
void iochannel_set_callback(struct iochannel*io, void (*callback)(struct iochannel*io, void *userdata), void *userdata); void pa_iochannel_set_callback(struct pa_iochannel*io, void (*callback)(struct pa_iochannel*io, void *userdata), void *userdata);
void iochannel_peer_to_string(struct iochannel*io, char*s, size_t l); void pa_iochannel_peer_to_string(struct pa_iochannel*io, char*s, size_t l);
#endif #endif

View file

@ -9,8 +9,8 @@
#define BUFFER_LIMIT (64*1024) #define BUFFER_LIMIT (64*1024)
#define READ_SIZE (1024) #define READ_SIZE (1024)
struct ioline { struct pa_ioline {
struct iochannel *io; struct pa_iochannel *io;
int dead; int dead;
char *wbuf; char *wbuf;
@ -19,18 +19,18 @@ struct ioline {
char *rbuf; char *rbuf;
size_t rbuf_length, rbuf_index, rbuf_valid_length; size_t rbuf_length, rbuf_index, rbuf_valid_length;
void (*callback)(struct ioline*io, const char *s, void *userdata); void (*callback)(struct pa_ioline*io, const char *s, void *userdata);
void *userdata; void *userdata;
}; };
static void io_callback(struct iochannel*io, void *userdata); static void io_callback(struct pa_iochannel*io, void *userdata);
static int do_write(struct ioline *l); static int do_write(struct pa_ioline *l);
struct ioline* ioline_new(struct iochannel *io) { struct pa_ioline* pa_ioline_new(struct pa_iochannel *io) {
struct ioline *l; struct pa_ioline *l;
assert(io); assert(io);
l = malloc(sizeof(struct ioline)); l = malloc(sizeof(struct pa_ioline));
assert(l); assert(l);
l->io = io; l->io = io;
l->dead = 0; l->dead = 0;
@ -44,20 +44,20 @@ struct ioline* ioline_new(struct iochannel *io) {
l->callback = NULL; l->callback = NULL;
l->userdata = NULL; l->userdata = NULL;
iochannel_set_callback(io, io_callback, l); pa_iochannel_set_callback(io, io_callback, l);
return l; return l;
} }
void ioline_free(struct ioline *l) { void pa_ioline_free(struct pa_ioline *l) {
assert(l); assert(l);
iochannel_free(l->io); pa_iochannel_free(l->io);
free(l->wbuf); free(l->wbuf);
free(l->rbuf); free(l->rbuf);
free(l); free(l);
} }
void ioline_puts(struct ioline *l, const char *c) { void pa_ioline_puts(struct pa_ioline *l, const char *c) {
size_t len; size_t len;
assert(l && c); assert(l && c);
@ -89,19 +89,19 @@ void ioline_puts(struct ioline *l, const char *c) {
do_write(l); do_write(l);
} }
void ioline_set_callback(struct ioline*l, void (*callback)(struct ioline*io, const char *s, void *userdata), void *userdata) { void pa_ioline_set_callback(struct pa_ioline*l, void (*callback)(struct pa_ioline*io, const char *s, void *userdata), void *userdata) {
assert(l && callback); assert(l && callback);
l->callback = callback; l->callback = callback;
l->userdata = userdata; l->userdata = userdata;
} }
static int do_read(struct ioline *l) { static int do_read(struct pa_ioline *l) {
ssize_t r; ssize_t r;
size_t m, len; size_t m, len;
char *e; char *e;
assert(l); assert(l);
if (!iochannel_is_readable(l->io)) if (!pa_iochannel_is_readable(l->io))
return 0; return 0;
len = l->rbuf_length - l->rbuf_index - l->rbuf_valid_length; len = l->rbuf_length - l->rbuf_index - l->rbuf_valid_length;
@ -129,7 +129,7 @@ static int do_read(struct ioline *l) {
len = l->rbuf_length - l->rbuf_index - l->rbuf_valid_length; len = l->rbuf_length - l->rbuf_index - l->rbuf_valid_length;
if ((r = iochannel_read(l->io, l->rbuf+l->rbuf_index+l->rbuf_valid_length, len)) <= 0) if ((r = pa_iochannel_read(l->io, l->rbuf+l->rbuf_index+l->rbuf_valid_length, len)) <= 0)
return -1; return -1;
e = memchr(l->rbuf+l->rbuf_index+l->rbuf_valid_length, '\n', r); e = memchr(l->rbuf+l->rbuf_index+l->rbuf_valid_length, '\n', r);
@ -159,14 +159,14 @@ static int do_read(struct ioline *l) {
return 0; return 0;
} }
static int do_write(struct ioline *l) { static int do_write(struct pa_ioline *l) {
ssize_t r; ssize_t r;
assert(l); assert(l);
if (!l->wbuf_valid_length || !iochannel_is_writable(l->io)) if (!l->wbuf_valid_length || !pa_iochannel_is_writable(l->io))
return 0; return 0;
if ((r = iochannel_write(l->io, l->wbuf+l->wbuf_index, l->wbuf_valid_length)) < 0) if ((r = pa_iochannel_write(l->io, l->wbuf+l->wbuf_index, l->wbuf_valid_length)) < 0)
return -1; return -1;
l->wbuf_valid_length -= r; l->wbuf_valid_length -= r;
@ -176,8 +176,8 @@ static int do_write(struct ioline *l) {
return 0; return 0;
} }
static void io_callback(struct iochannel*io, void *userdata) { static void io_callback(struct pa_iochannel*io, void *userdata) {
struct ioline *l = userdata; struct pa_ioline *l = userdata;
assert(io && l); assert(io && l);
if (!l->dead && do_read(l) < 0) if (!l->dead && do_read(l) < 0)

View file

@ -3,12 +3,12 @@
#include "iochannel.h" #include "iochannel.h"
struct ioline; struct pa_ioline;
struct ioline* ioline_new(struct iochannel *io); struct pa_ioline* pa_ioline_new(struct pa_iochannel *io);
void ioline_free(struct ioline *l); void pa_ioline_free(struct pa_ioline *l);
void ioline_puts(struct ioline *s, const char *c); void pa_ioline_puts(struct pa_ioline *s, const char *c);
void ioline_set_callback(struct ioline*io, void (*callback)(struct ioline*io, const char *s, void *userdata), void *userdata); void pa_ioline_set_callback(struct pa_ioline*io, void (*callback)(struct pa_ioline*io, const char *s, void *userdata), void *userdata);
#endif #endif

View file

@ -10,7 +10,7 @@
#include "module.h" #include "module.h"
#include "mainloop-signal.h" #include "mainloop-signal.h"
int stdin_inuse = 0, stdout_inuse = 0; int pa_stdin_inuse = 0, pa_stdout_inuse = 0;
static struct pa_mainloop *mainloop; static struct pa_mainloop *mainloop;
@ -21,7 +21,7 @@ static void signal_callback(void *id, int sig, void *userdata) {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
struct core *c; struct pa_core *c;
int r, retval = 0; int r, retval = 0;
r = lt_dlinit(); r = lt_dlinit();
@ -35,26 +35,26 @@ int main(int argc, char *argv[]) {
pa_signal_register(SIGINT, signal_callback, NULL); pa_signal_register(SIGINT, signal_callback, NULL);
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
c = core_new(pa_mainloop_get_api(mainloop)); c = pa_core_new(pa_mainloop_get_api(mainloop));
assert(c); assert(c);
module_load(c, "module-oss-mmap", "/dev/dsp1"); pa_module_load(c, "module-oss", "/dev/dsp");
/* module_load(c, "module-pipe-sink", NULL);*/ /* pa_module_load(c, "module-pipe-sink", NULL);*/
module_load(c, "module-simple-protocol-tcp", NULL); pa_module_load(c, "module-simple-protocol-tcp", NULL);
/* module_load(c, "module-simple-protocol-unix", NULL); /* pa_module_load(c, "module-simple-protocol-unix", NULL);
module_load(c, "module-cli-protocol-tcp", NULL); pa_module_load(c, "module-cli-protocol-tcp", NULL);
module_load(c, "module-cli-protocol-unix", NULL); pa_module_load(c, "module-cli-protocol-unix", NULL);
module_load(c, "module-native-protocol-tcp", NULL);*/ pa_module_load(c, "module-native-protocol-tcp", NULL);*/
module_load(c, "module-native-protocol-unix", NULL); pa_module_load(c, "module-native-protocol-unix", NULL);
/* module_load(c, "module-esound-protocol-tcp", NULL);*/ /* pa_module_load(c, "module-esound-protocol-tcp", NULL);*/
module_load(c, "module-cli", NULL); pa_module_load(c, "module-cli", NULL);
fprintf(stderr, "main: mainloop entry.\n"); fprintf(stderr, "main: mainloop entry.\n");
if (pa_mainloop_run(mainloop, &retval) < 0) if (pa_mainloop_run(mainloop, &retval) < 0)
retval = 1; retval = 1;
fprintf(stderr, "main: mainloop exit.\n"); fprintf(stderr, "main: mainloop exit.\n");
core_free(c); pa_core_free(c);
pa_signal_done(); pa_signal_done();
pa_mainloop_free(mainloop); pa_mainloop_free(mainloop);

View file

@ -1,6 +1,6 @@
#ifndef foomainhfoo #ifndef foomainhfoo
#define foomainhfoo #define foomainhfoo
extern int stdin_inuse, stdout_inuse; extern int pa_stdin_inuse, pa_stdout_inuse;
#endif #endif

View file

@ -63,8 +63,8 @@ int pa_signal_init(struct pa_mainloop_api *a) {
return -1; return -1;
} }
make_nonblock_fd(signal_pipe[0]); pa_make_nonblock_fd(signal_pipe[0]);
make_nonblock_fd(signal_pipe[1]); pa_make_nonblock_fd(signal_pipe[1]);
api = a; api = a;
mainloop_source = api->source_io(api, signal_pipe[0], PA_MAINLOOP_API_IO_EVENT_INPUT, callback, NULL); mainloop_source = api->source_io(api, signal_pipe[0], PA_MAINLOOP_API_IO_EVENT_INPUT, callback, NULL);

View file

@ -46,7 +46,7 @@ struct mainloop_source_time {
}; };
struct pa_mainloop { struct pa_mainloop {
struct idxset *io_sources, *fixed_sources, *idle_sources, *time_sources; struct pa_idxset *io_sources, *fixed_sources, *idle_sources, *time_sources;
int io_sources_scan_dead, fixed_sources_scan_dead, idle_sources_scan_dead, time_sources_scan_dead; int io_sources_scan_dead, fixed_sources_scan_dead, idle_sources_scan_dead, time_sources_scan_dead;
struct pollfd *pollfds; struct pollfd *pollfds;
@ -65,10 +65,10 @@ struct pa_mainloop *pa_mainloop_new(void) {
m = malloc(sizeof(struct pa_mainloop)); m = malloc(sizeof(struct pa_mainloop));
assert(m); assert(m);
m->io_sources = idxset_new(NULL, NULL); m->io_sources = pa_idxset_new(NULL, NULL);
m->fixed_sources = idxset_new(NULL, NULL); m->fixed_sources = pa_idxset_new(NULL, NULL);
m->idle_sources = idxset_new(NULL, NULL); m->idle_sources = pa_idxset_new(NULL, NULL);
m->time_sources = idxset_new(NULL, NULL); m->time_sources = pa_idxset_new(NULL, NULL);
assert(m->io_sources && m->fixed_sources && m->idle_sources && m->time_sources); assert(m->io_sources && m->fixed_sources && m->idle_sources && m->time_sources);
@ -100,15 +100,15 @@ static int foreach(void *p, uint32_t index, int *del, void*userdata) {
void pa_mainloop_free(struct pa_mainloop* m) { void pa_mainloop_free(struct pa_mainloop* m) {
int all = 1; int all = 1;
assert(m); assert(m);
idxset_foreach(m->io_sources, foreach, &all); pa_idxset_foreach(m->io_sources, foreach, &all);
idxset_foreach(m->fixed_sources, foreach, &all); pa_idxset_foreach(m->fixed_sources, foreach, &all);
idxset_foreach(m->idle_sources, foreach, &all); pa_idxset_foreach(m->idle_sources, foreach, &all);
idxset_foreach(m->time_sources, foreach, &all); pa_idxset_foreach(m->time_sources, foreach, &all);
idxset_free(m->io_sources, NULL, NULL); pa_idxset_free(m->io_sources, NULL, NULL);
idxset_free(m->fixed_sources, NULL, NULL); pa_idxset_free(m->fixed_sources, NULL, NULL);
idxset_free(m->idle_sources, NULL, NULL); pa_idxset_free(m->idle_sources, NULL, NULL);
idxset_free(m->time_sources, NULL, NULL); pa_idxset_free(m->time_sources, NULL, NULL);
free(m->pollfds); free(m->pollfds);
free(m); free(m);
@ -118,22 +118,22 @@ static void scan_dead(struct pa_mainloop *m) {
int all = 0; int all = 0;
assert(m); assert(m);
if (m->io_sources_scan_dead) if (m->io_sources_scan_dead)
idxset_foreach(m->io_sources, foreach, &all); pa_idxset_foreach(m->io_sources, foreach, &all);
if (m->fixed_sources_scan_dead) if (m->fixed_sources_scan_dead)
idxset_foreach(m->fixed_sources, foreach, &all); pa_idxset_foreach(m->fixed_sources, foreach, &all);
if (m->idle_sources_scan_dead) if (m->idle_sources_scan_dead)
idxset_foreach(m->idle_sources, foreach, &all); pa_idxset_foreach(m->idle_sources, foreach, &all);
if (m->time_sources_scan_dead) if (m->time_sources_scan_dead)
idxset_foreach(m->time_sources, foreach, &all); pa_idxset_foreach(m->time_sources, foreach, &all);
} }
static void rebuild_pollfds(struct pa_mainloop *m) { static void rebuild_pollfds(struct pa_mainloop *m) {
struct mainloop_source_io*s; struct mainloop_source_io*s;
struct pollfd *p; struct pollfd *p;
uint32_t index = IDXSET_INVALID; uint32_t index = PA_IDXSET_INVALID;
unsigned l; unsigned l;
l = idxset_ncontents(m->io_sources); l = pa_idxset_ncontents(m->io_sources);
if (m->max_pollfds < l) { if (m->max_pollfds < l) {
m->pollfds = realloc(m->pollfds, sizeof(struct pollfd)*l); m->pollfds = realloc(m->pollfds, sizeof(struct pollfd)*l);
m->max_pollfds = l; m->max_pollfds = l;
@ -141,7 +141,7 @@ static void rebuild_pollfds(struct pa_mainloop *m) {
m->n_pollfds = 0; m->n_pollfds = 0;
p = m->pollfds; p = m->pollfds;
for (s = idxset_first(m->io_sources, &index); s; s = idxset_next(m->io_sources, &index)) { for (s = pa_idxset_first(m->io_sources, &index); s; s = pa_idxset_next(m->io_sources, &index)) {
if (s->header.dead) { if (s->header.dead) {
s->pollfd = NULL; s->pollfd = NULL;
continue; continue;
@ -158,10 +158,10 @@ static void rebuild_pollfds(struct pa_mainloop *m) {
} }
static void dispatch_pollfds(struct pa_mainloop *m) { static void dispatch_pollfds(struct pa_mainloop *m) {
uint32_t index = IDXSET_INVALID; uint32_t index = PA_IDXSET_INVALID;
struct mainloop_source_io *s; struct mainloop_source_io *s;
for (s = idxset_first(m->io_sources, &index); s; s = idxset_next(m->io_sources, &index)) { for (s = pa_idxset_first(m->io_sources, &index); s; s = pa_idxset_next(m->io_sources, &index)) {
if (s->header.dead || !s->pollfd || !s->pollfd->revents) if (s->header.dead || !s->pollfd || !s->pollfd->revents)
continue; continue;
@ -173,11 +173,11 @@ static void dispatch_pollfds(struct pa_mainloop *m) {
} }
} }
static void run_fixed_or_idle(struct pa_mainloop *m, struct idxset *i) { static void run_fixed_or_idle(struct pa_mainloop *m, struct pa_idxset *i) {
uint32_t index = IDXSET_INVALID; uint32_t index = PA_IDXSET_INVALID;
struct mainloop_source_fixed_or_idle *s; struct mainloop_source_fixed_or_idle *s;
for (s = idxset_first(i, &index); s; s = idxset_next(i, &index)) { for (s = pa_idxset_first(i, &index); s; s = pa_idxset_next(i, &index)) {
if (s->header.dead || !s->enabled) if (s->header.dead || !s->enabled)
continue; continue;
@ -187,17 +187,17 @@ static void run_fixed_or_idle(struct pa_mainloop *m, struct idxset *i) {
} }
static int calc_next_timeout(struct pa_mainloop *m) { static int calc_next_timeout(struct pa_mainloop *m) {
uint32_t index = IDXSET_INVALID; uint32_t index = PA_IDXSET_INVALID;
struct mainloop_source_time *s; struct mainloop_source_time *s;
struct timeval now; struct timeval now;
int t = -1; int t = -1;
if (idxset_isempty(m->time_sources)) if (pa_idxset_isempty(m->time_sources))
return -1; return -1;
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
for (s = idxset_first(m->time_sources, &index); s; s = idxset_next(m->time_sources, &index)) { for (s = pa_idxset_first(m->time_sources, &index); s; s = pa_idxset_next(m->time_sources, &index)) {
int tmp; int tmp;
if (s->header.dead || !s->enabled) if (s->header.dead || !s->enabled)
@ -223,16 +223,16 @@ static int calc_next_timeout(struct pa_mainloop *m) {
} }
static void dispatch_timeout(struct pa_mainloop *m) { static void dispatch_timeout(struct pa_mainloop *m) {
uint32_t index = IDXSET_INVALID; uint32_t index = PA_IDXSET_INVALID;
struct mainloop_source_time *s; struct mainloop_source_time *s;
struct timeval now; struct timeval now;
assert(m); assert(m);
if (idxset_isempty(m->time_sources)) if (pa_idxset_isempty(m->time_sources))
return; return;
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
for (s = idxset_first(m->time_sources, &index); s; s = idxset_next(m->time_sources, &index)) { for (s = pa_idxset_first(m->time_sources, &index); s; s = pa_idxset_next(m->time_sources, &index)) {
if (s->header.dead || !s->enabled) if (s->header.dead || !s->enabled)
continue; continue;
@ -251,7 +251,7 @@ static int any_idle_sources(struct pa_mainloop *m) {
uint32_t index; uint32_t index;
assert(m); assert(m);
for (s = idxset_first(m->idle_sources, &index); s; s = idxset_next(m->idle_sources, &index)) for (s = pa_idxset_first(m->idle_sources, &index); s; s = pa_idxset_next(m->idle_sources, &index))
if (!s->header.dead && s->enabled) if (!s->header.dead && s->enabled)
return 1; return 1;
@ -334,7 +334,7 @@ static void* mainloop_source_io(struct pa_mainloop_api*a, int fd, enum pa_mainlo
s->userdata = userdata; s->userdata = userdata;
s->pollfd = NULL; s->pollfd = NULL;
idxset_put(m->io_sources, s, NULL); pa_idxset_put(m->io_sources, s, NULL);
m->rebuild_pollfds = 1; m->rebuild_pollfds = 1;
return s; return s;
} }
@ -380,7 +380,7 @@ static void* mainloop_source_fixed(struct pa_mainloop_api*a, void (*callback) (s
s->callback = callback; s->callback = callback;
s->userdata = userdata; s->userdata = userdata;
idxset_put(m->fixed_sources, s, NULL); pa_idxset_put(m->fixed_sources, s, NULL);
return s; return s;
} }
@ -422,7 +422,7 @@ static void* mainloop_source_idle(struct pa_mainloop_api*a, void (*callback) (st
s->callback = callback; s->callback = callback;
s->userdata = userdata; s->userdata = userdata;
idxset_put(m->idle_sources, s, NULL); pa_idxset_put(m->idle_sources, s, NULL);
return s; return s;
} }
@ -457,7 +457,7 @@ static void* mainloop_source_time(struct pa_mainloop_api*a, const struct timeval
s->callback = callback; s->callback = callback;
s->userdata = userdata; s->userdata = userdata;
idxset_put(m->time_sources, s, NULL); pa_idxset_put(m->time_sources, s, NULL);
return s; return s;
} }

View file

@ -5,69 +5,69 @@
#include "memblock.h" #include "memblock.h"
unsigned memblock_count = 0, memblock_total = 0; unsigned pa_memblock_count = 0, pa_memblock_total = 0;
struct memblock *memblock_new(size_t length) { struct pa_memblock *pa_memblock_new(size_t length) {
struct memblock *b = malloc(sizeof(struct memblock)+length); struct pa_memblock *b = malloc(sizeof(struct pa_memblock)+length);
b->type = MEMBLOCK_APPENDED; b->type = PA_MEMBLOCK_APPENDED;
b->ref = 1; b->ref = 1;
b->length = length; b->length = length;
b->data = b+1; b->data = b+1;
memblock_count++; pa_memblock_count++;
memblock_total += length; pa_memblock_total += length;
return b; return b;
} }
struct memblock *memblock_new_fixed(void *d, size_t length) { struct pa_memblock *pa_memblock_new_fixed(void *d, size_t length) {
struct memblock *b = malloc(sizeof(struct memblock)); struct pa_memblock *b = malloc(sizeof(struct pa_memblock));
b->type = MEMBLOCK_FIXED; b->type = PA_MEMBLOCK_FIXED;
b->ref = 1; b->ref = 1;
b->length = length; b->length = length;
b->data = d; b->data = d;
memblock_count++; pa_memblock_count++;
memblock_total += length; pa_memblock_total += length;
return b; return b;
} }
struct memblock *memblock_new_dynamic(void *d, size_t length) { struct pa_memblock *pa_memblock_new_dynamic(void *d, size_t length) {
struct memblock *b = malloc(sizeof(struct memblock)); struct pa_memblock *b = malloc(sizeof(struct pa_memblock));
b->type = MEMBLOCK_DYNAMIC; b->type = PA_MEMBLOCK_DYNAMIC;
b->ref = 1; b->ref = 1;
b->length = length; b->length = length;
b->data = d; b->data = d;
memblock_count++; pa_memblock_count++;
memblock_total += length; pa_memblock_total += length;
return b; return b;
} }
struct memblock* memblock_ref(struct memblock*b) { struct pa_memblock* pa_memblock_ref(struct pa_memblock*b) {
assert(b && b->ref >= 1); assert(b && b->ref >= 1);
b->ref++; b->ref++;
return b; return b;
} }
void memblock_unref(struct memblock*b) { void pa_memblock_unref(struct pa_memblock*b) {
assert(b && b->ref >= 1); assert(b && b->ref >= 1);
b->ref--; b->ref--;
if (b->ref == 0) { if (b->ref == 0) {
if (b->type == MEMBLOCK_DYNAMIC) if (b->type == PA_MEMBLOCK_DYNAMIC)
free(b->data); free(b->data);
memblock_count--; pa_memblock_count--;
memblock_total -= b->length; pa_memblock_total -= b->length;
free(b); free(b);
} }
} }
void memblock_unref_fixed(struct memblock *b) { void pa_memblock_unref_fixed(struct pa_memblock *b) {
void *d; void *d;
assert(b && b->ref >= 1); assert(b && b->ref >= 1);
if (b->ref == 1) { if (b->ref == 1) {
memblock_unref(b); pa_memblock_unref(b);
return; return;
} }
@ -75,6 +75,6 @@ void memblock_unref_fixed(struct memblock *b) {
assert(d); assert(d);
memcpy(d, b->data, b->length); memcpy(d, b->data, b->length);
b->data = d; b->data = d;
b->type = MEMBLOCK_DYNAMIC; b->type = PA_MEMBLOCK_DYNAMIC;
} }

View file

@ -4,26 +4,26 @@
#include <sys/types.h> #include <sys/types.h>
#include <inttypes.h> #include <inttypes.h>
enum memblock_type { MEMBLOCK_FIXED, MEMBLOCK_APPENDED, MEMBLOCK_DYNAMIC }; enum pa_memblock_type { PA_MEMBLOCK_FIXED, PA_MEMBLOCK_APPENDED, PA_MEMBLOCK_DYNAMIC };
struct memblock { struct pa_memblock {
enum memblock_type type; enum pa_memblock_type type;
unsigned ref; unsigned ref;
size_t length; size_t length;
void *data; void *data;
}; };
struct memblock *memblock_new(size_t length); struct pa_memblock *pa_memblock_new(size_t length);
struct memblock *memblock_new_fixed(void *data, size_t length); struct pa_memblock *pa_memblock_new_fixed(void *data, size_t length);
struct memblock *memblock_new_dynamic(void *data, size_t length); struct pa_memblock *pa_memblock_new_dynamic(void *data, size_t length);
void memblock_unref(struct memblock*b); void pa_memblock_unref(struct pa_memblock*b);
struct memblock* memblock_ref(struct memblock*b); struct pa_memblock* pa_memblock_ref(struct pa_memblock*b);
void memblock_unref_fixed(struct memblock*b); void pa_memblock_unref_fixed(struct pa_memblock*b);
#define memblock_assert_exclusive(b) assert((b)->ref == 1) #define pa_memblock_assert_exclusive(b) assert((b)->ref == 1)
extern unsigned memblock_count, memblock_total; extern unsigned pa_memblock_count, pa_memblock_total;
#endif #endif

View file

@ -8,24 +8,24 @@
struct memblock_list { struct memblock_list {
struct memblock_list *next; struct memblock_list *next;
struct memchunk chunk; struct pa_memchunk chunk;
struct timeval stamp; struct timeval stamp;
}; };
struct memblockq { struct pa_memblockq {
struct memblock_list *blocks, *blocks_tail; struct memblock_list *blocks, *blocks_tail;
unsigned n_blocks; unsigned n_blocks;
size_t total_length, maxlength, base, prebuf; size_t total_length, maxlength, base, prebuf;
int measure_delay; int measure_delay;
uint32_t delay; uint32_t delay;
struct mcalign *mcalign; struct pa_mcalign *mcalign;
}; };
struct memblockq* memblockq_new(size_t maxlength, size_t base, size_t prebuf) { struct pa_memblockq* pa_memblockq_new(size_t maxlength, size_t base, size_t prebuf) {
struct memblockq* bq; struct pa_memblockq* bq;
assert(maxlength && base); assert(maxlength && base);
bq = malloc(sizeof(struct memblockq)); bq = malloc(sizeof(struct pa_memblockq));
assert(bq); assert(bq);
bq->blocks = bq->blocks_tail = 0; bq->blocks = bq->blocks_tail = 0;
bq->n_blocks = 0; bq->n_blocks = 0;
@ -47,23 +47,23 @@ struct memblockq* memblockq_new(size_t maxlength, size_t base, size_t prebuf) {
return bq; return bq;
} }
void memblockq_free(struct memblockq* bq) { void pa_memblockq_free(struct pa_memblockq* bq) {
struct memblock_list *l; struct memblock_list *l;
assert(bq); assert(bq);
if (bq->mcalign) if (bq->mcalign)
mcalign_free(bq->mcalign); pa_mcalign_free(bq->mcalign);
while ((l = bq->blocks)) { while ((l = bq->blocks)) {
bq->blocks = l->next; bq->blocks = l->next;
memblock_unref(l->chunk.memblock); pa_memblock_unref(l->chunk.memblock);
free(l); free(l);
} }
free(bq); free(bq);
} }
void memblockq_push(struct memblockq* bq, const struct memchunk *chunk, size_t delta) { void pa_memblockq_push(struct pa_memblockq* bq, const struct pa_memchunk *chunk, size_t delta) {
struct memblock_list *q; struct memblock_list *q;
assert(bq && chunk && chunk->memblock && chunk->length && (chunk->length % bq->base) == 0); assert(bq && chunk && chunk->memblock && chunk->length && (chunk->length % bq->base) == 0);
@ -76,7 +76,7 @@ void memblockq_push(struct memblockq* bq, const struct memchunk *chunk, size_t d
timerclear(&q->stamp); timerclear(&q->stamp);
q->chunk = *chunk; q->chunk = *chunk;
memblock_ref(q->chunk.memblock); pa_memblock_ref(q->chunk.memblock);
assert(q->chunk.index+q->chunk.length <= q->chunk.memblock->length); assert(q->chunk.index+q->chunk.length <= q->chunk.memblock->length);
q->next = NULL; q->next = NULL;
@ -90,10 +90,10 @@ void memblockq_push(struct memblockq* bq, const struct memchunk *chunk, size_t d
bq->n_blocks++; bq->n_blocks++;
bq->total_length += chunk->length; bq->total_length += chunk->length;
memblockq_shorten(bq, bq->maxlength); pa_memblockq_shorten(bq, bq->maxlength);
} }
int memblockq_peek(struct memblockq* bq, struct memchunk *chunk) { int pa_memblockq_peek(struct pa_memblockq* bq, struct pa_memchunk *chunk) {
assert(bq && chunk); assert(bq && chunk);
if (!bq->blocks || bq->total_length < bq->prebuf) if (!bq->blocks || bq->total_length < bq->prebuf)
@ -102,16 +102,16 @@ int memblockq_peek(struct memblockq* bq, struct memchunk *chunk) {
bq->prebuf = 0; bq->prebuf = 0;
*chunk = bq->blocks->chunk; *chunk = bq->blocks->chunk;
memblock_ref(chunk->memblock); pa_memblock_ref(chunk->memblock);
if (chunk->memblock->ref != 2) /* if (chunk->memblock->ref != 2) */
fprintf(stderr, "block %p with ref %u peeked.\n", chunk->memblock, chunk->memblock->ref); /* fprintf(stderr, "block %p with ref %u peeked.\n", chunk->memblock, chunk->memblock->ref); */
return 0; return 0;
} }
/* /*
int memblockq_pop(struct memblockq* bq, struct memchunk *chunk) { int memblockq_pop(struct memblockq* bq, struct pa_memchunk *chunk) {
struct memblock_list *q; struct memblock_list *q;
assert(bq && chunk); assert(bq && chunk);
@ -154,7 +154,7 @@ static uint32_t age(struct timeval *tv) {
return r; return r;
} }
void memblockq_drop(struct memblockq *bq, size_t length) { void pa_memblockq_drop(struct pa_memblockq *bq, size_t length) {
assert(bq && length && (length % bq->base) == 0); assert(bq && length && (length % bq->base) == 0);
while (length > 0) { while (length > 0) {
@ -178,7 +178,7 @@ void memblockq_drop(struct memblockq *bq, size_t length) {
bq->blocks = bq->blocks->next; bq->blocks = bq->blocks->next;
if (bq->blocks == NULL) if (bq->blocks == NULL)
bq->blocks_tail = NULL; bq->blocks_tail = NULL;
memblock_unref(q->chunk.memblock); pa_memblock_unref(q->chunk.memblock);
free(q); free(q);
bq->n_blocks--; bq->n_blocks--;
@ -188,52 +188,52 @@ void memblockq_drop(struct memblockq *bq, size_t length) {
} }
} }
void memblockq_shorten(struct memblockq *bq, size_t length) { void pa_memblockq_shorten(struct pa_memblockq *bq, size_t length) {
size_t l; size_t l;
assert(bq); assert(bq);
if (bq->total_length <= length) if (bq->total_length <= length)
return; return;
fprintf(stderr, "Warning! memblockq_shorten()\n"); fprintf(stderr, "Warning! pa_memblockq_shorten()\n");
l = bq->total_length - length; l = bq->total_length - length;
l /= bq->base; l /= bq->base;
l *= bq->base; l *= bq->base;
memblockq_drop(bq, l); pa_memblockq_drop(bq, l);
} }
void memblockq_empty(struct memblockq *bq) { void pa_memblockq_empty(struct pa_memblockq *bq) {
assert(bq); assert(bq);
memblockq_shorten(bq, 0); pa_memblockq_shorten(bq, 0);
} }
int memblockq_is_readable(struct memblockq *bq) { int pa_memblockq_is_readable(struct pa_memblockq *bq) {
assert(bq); assert(bq);
return bq->total_length >= bq->prebuf; return bq->total_length >= bq->prebuf;
} }
int memblockq_is_writable(struct memblockq *bq, size_t length) { int pa_memblockq_is_writable(struct pa_memblockq *bq, size_t length) {
assert(bq); assert(bq);
assert(length <= bq->maxlength); assert(length <= bq->maxlength);
return bq->total_length + length <= bq->maxlength; return bq->total_length + length <= bq->maxlength;
} }
uint32_t memblockq_get_delay(struct memblockq *bq) { uint32_t pa_memblockq_get_delay(struct pa_memblockq *bq) {
assert(bq); assert(bq);
return bq->delay; return bq->delay;
} }
uint32_t memblockq_get_length(struct memblockq *bq) { uint32_t pa_memblockq_get_length(struct pa_memblockq *bq) {
assert(bq); assert(bq);
return bq->total_length; return bq->total_length;
} }
uint32_t memblockq_missing_to(struct memblockq *bq, size_t qlen) { uint32_t pa_memblockq_missing_to(struct pa_memblockq *bq, size_t qlen) {
assert(bq && qlen); assert(bq && qlen);
if (bq->total_length >= qlen) if (bq->total_length >= qlen)
@ -242,25 +242,25 @@ uint32_t memblockq_missing_to(struct memblockq *bq, size_t qlen) {
return qlen - bq->total_length; return qlen - bq->total_length;
} }
void memblockq_push_align(struct memblockq* bq, const struct memchunk *chunk, size_t delta) { void pa_memblockq_push_align(struct pa_memblockq* bq, const struct pa_memchunk *chunk, size_t delta) {
struct memchunk rchunk; struct pa_memchunk rchunk;
assert(bq && chunk && bq->base); assert(bq && chunk && bq->base);
if (bq->base == 1) { if (bq->base == 1) {
memblockq_push(bq, chunk, delta); pa_memblockq_push(bq, chunk, delta);
return; return;
} }
if (!bq->mcalign) { if (!bq->mcalign) {
bq->mcalign = mcalign_new(bq->base); bq->mcalign = pa_mcalign_new(bq->base);
assert(bq->mcalign); assert(bq->mcalign);
} }
mcalign_push(bq->mcalign, chunk); pa_mcalign_push(bq->mcalign, chunk);
while (mcalign_pop(bq->mcalign, &rchunk) >= 0) { while (pa_mcalign_pop(bq->mcalign, &rchunk) >= 0) {
memblockq_push(bq, &rchunk, delta); pa_memblockq_push(bq, &rchunk, delta);
memblock_unref(rchunk.memblock); pa_memblock_unref(rchunk.memblock);
delta = 0; delta = 0;
} }
} }

View file

@ -6,46 +6,46 @@
#include "memblock.h" #include "memblock.h"
#include "memchunk.h" #include "memchunk.h"
struct memblockq; struct pa_memblockq;
/* Parameters: the maximum length of the memblock queue, a base value /* Parameters: the maximum length of the memblock queue, a base value
for all operations (that is, all byte operations shall work on for all operations (that is, all byte operations shall work on
multiples of this base value) and an amount of bytes to prebuffer multiples of this base value) and an amount of bytes to prebuffer
before having memblockq_peek() succeed. */ before having pa_memblockq_peek() succeed. */
struct memblockq* memblockq_new(size_t maxlength, size_t base, size_t prebuf); struct pa_memblockq* pa_memblockq_new(size_t maxlength, size_t base, size_t prebuf);
void memblockq_free(struct memblockq*bq); void pa_memblockq_free(struct pa_memblockq*bq);
/* Push a new memory chunk into the queue. Optionally specify a value for future cancellation. This is currently not implemented, however! */ /* Push a new memory chunk into the queue. Optionally specify a value for future cancellation. This is currently not implemented, however! */
void memblockq_push(struct memblockq* bq, const struct memchunk *chunk, size_t delta); void pa_memblockq_push(struct pa_memblockq* bq, const struct pa_memchunk *chunk, size_t delta);
/* Same as memblockq_push(), however chunks are filtered through a mcalign object, and thus aligned to multiples of base */ /* Same as pa_memblockq_push(), however chunks are filtered through a mcalign object, and thus aligned to multiples of base */
void memblockq_push_align(struct memblockq* bq, const struct memchunk *chunk, size_t delta); void pa_memblockq_push_align(struct pa_memblockq* bq, const struct pa_memchunk *chunk, size_t delta);
/* Return a copy of the next memory chunk in the queue. It is not removed from the queue */ /* Return a copy of the next memory chunk in the queue. It is not removed from the queue */
int memblockq_peek(struct memblockq* bq, struct memchunk *chunk); int pa_memblockq_peek(struct pa_memblockq* bq, struct pa_memchunk *chunk);
/* Drop the specified bytes from the queue */ /* Drop the specified bytes from the queue */
void memblockq_drop(struct memblockq *bq, size_t length); void pa_memblockq_drop(struct pa_memblockq *bq, size_t length);
/* Shorten the memblockq to the specified length by dropping data at the end of the queue */ /* Shorten the pa_memblockq to the specified length by dropping data at the end of the queue */
void memblockq_shorten(struct memblockq *bq, size_t length); void pa_memblockq_shorten(struct pa_memblockq *bq, size_t length);
/* Empty the memblockq */ /* Empty the pa_memblockq */
void memblockq_empty(struct memblockq *bq); void pa_memblockq_empty(struct pa_memblockq *bq);
/* Test if the memblockq is currently readable, that is, more data than base */ /* Test if the pa_memblockq is currently readable, that is, more data than base */
int memblockq_is_readable(struct memblockq *bq); int pa_memblockq_is_readable(struct pa_memblockq *bq);
/* Test if the memblockq is currently writable for the specified amount of bytes */ /* Test if the pa_memblockq is currently writable for the specified amount of bytes */
int memblockq_is_writable(struct memblockq *bq, size_t length); int pa_memblockq_is_writable(struct pa_memblockq *bq, size_t length);
/* The time memory chunks stay in the queue until they are removed completely in usecs */ /* The time memory chunks stay in the queue until they are removed completely in usecs */
uint32_t memblockq_get_delay(struct memblockq *bq); uint32_t pa_memblockq_get_delay(struct pa_memblockq *bq);
/* Return the length of the queue in bytes */ /* Return the length of the queue in bytes */
uint32_t memblockq_get_length(struct memblockq *bq); uint32_t pa_memblockq_get_length(struct pa_memblockq *bq);
/* Return how many bytes are missing in queue to the specified fill amount */ /* Return how many bytes are missing in queue to the specified fill amount */
uint32_t memblockq_missing_to(struct memblockq *bq, size_t qlen); uint32_t pa_memblockq_missing_to(struct pa_memblockq *bq, size_t qlen);
#endif #endif

View file

@ -5,34 +5,34 @@
#include "memchunk.h" #include "memchunk.h"
void memchunk_make_writable(struct memchunk *c) { void pa_memchunk_make_writable(struct pa_memchunk *c) {
struct memblock *n; struct pa_memblock *n;
assert(c && c->memblock && c->memblock->ref >= 1); assert(c && c->memblock && c->memblock->ref >= 1);
if (c->memblock->ref == 1) if (c->memblock->ref == 1)
return; return;
n = memblock_new(c->length); n = pa_memblock_new(c->length);
assert(n); assert(n);
memcpy(n->data, c->memblock->data+c->index, c->length); memcpy(n->data, c->memblock->data+c->index, c->length);
memblock_unref(c->memblock); pa_memblock_unref(c->memblock);
c->memblock = n; c->memblock = n;
c->index = 0; c->index = 0;
} }
struct mcalign { struct pa_mcalign {
size_t base; size_t base;
struct memchunk chunk; struct pa_memchunk chunk;
uint8_t *buffer; uint8_t *buffer;
size_t buffer_fill; size_t buffer_fill;
}; };
struct mcalign *mcalign_new(size_t base) { struct pa_mcalign *pa_mcalign_new(size_t base) {
struct mcalign *m; struct pa_mcalign *m;
assert(base); assert(base);
m = malloc(sizeof(struct mcalign)); m = malloc(sizeof(struct pa_mcalign));
assert(m); assert(m);
m->base = base; m->base = base;
m->chunk.memblock = NULL; m->chunk.memblock = NULL;
@ -42,25 +42,25 @@ struct mcalign *mcalign_new(size_t base) {
return m; return m;
} }
void mcalign_free(struct mcalign *m) { void pa_mcalign_free(struct pa_mcalign *m) {
assert(m); assert(m);
free(m->buffer); free(m->buffer);
if (m->chunk.memblock) if (m->chunk.memblock)
memblock_unref(m->chunk.memblock); pa_memblock_unref(m->chunk.memblock);
free(m); free(m);
} }
void mcalign_push(struct mcalign *m, const struct memchunk *c) { void pa_mcalign_push(struct pa_mcalign *m, const struct pa_memchunk *c) {
assert(m && c && !m->chunk.memblock && c->memblock && c->length); assert(m && c && !m->chunk.memblock && c->memblock && c->length);
m->chunk = *c; m->chunk = *c;
memblock_ref(m->chunk.memblock); pa_memblock_ref(m->chunk.memblock);
} }
int mcalign_pop(struct mcalign *m, struct memchunk *c) { int pa_mcalign_pop(struct pa_mcalign *m, struct pa_memchunk *c) {
assert(m && c && m->base > m->buffer_fill); assert(m && c && m->base > m->buffer_fill);
int ret; int ret;
@ -80,13 +80,13 @@ int mcalign_pop(struct mcalign *m, struct memchunk *c) {
if (m->chunk.length == 0) { if (m->chunk.length == 0) {
m->chunk.length = m->chunk.index = 0; m->chunk.length = m->chunk.index = 0;
memblock_unref(m->chunk.memblock); pa_memblock_unref(m->chunk.memblock);
m->chunk.memblock = NULL; m->chunk.memblock = NULL;
} }
assert(m->buffer_fill <= m->base); assert(m->buffer_fill <= m->base);
if (m->buffer_fill == m->base) { if (m->buffer_fill == m->base) {
c->memblock = memblock_new_dynamic(m->buffer, m->base); c->memblock = pa_memblock_new_dynamic(m->buffer, m->base);
assert(c->memblock); assert(c->memblock);
c->index = 0; c->index = 0;
c->length = m->base; c->length = m->base;
@ -111,13 +111,13 @@ int mcalign_pop(struct mcalign *m, struct memchunk *c) {
if (m->chunk.length) { if (m->chunk.length) {
*c = m->chunk; *c = m->chunk;
memblock_ref(c->memblock); pa_memblock_ref(c->memblock);
ret = 0; ret = 0;
} else } else
ret = -1; ret = -1;
m->chunk.length = m->chunk.index = 0; m->chunk.length = m->chunk.index = 0;
memblock_unref(m->chunk.memblock); pa_memblock_unref(m->chunk.memblock);
m->chunk.memblock = NULL; m->chunk.memblock = NULL;
return ret; return ret;

View file

@ -3,18 +3,18 @@
#include "memblock.h" #include "memblock.h"
struct memchunk { struct pa_memchunk {
struct memblock *memblock; struct pa_memblock *memblock;
size_t index, length; size_t index, length;
}; };
void memchunk_make_writable(struct memchunk *c); void pa_memchunk_make_writable(struct pa_memchunk *c);
struct mcalign; struct pa_mcalign;
struct mcalign *mcalign_new(size_t base); struct pa_mcalign *pa_mcalign_new(size_t base);
void mcalign_free(struct mcalign *m); void pa_mcalign_free(struct pa_mcalign *m);
void mcalign_push(struct mcalign *m, const struct memchunk *c); void pa_mcalign_push(struct pa_mcalign *m, const struct pa_memchunk *c);
int mcalign_pop(struct mcalign *m, struct memchunk *c); int pa_mcalign_pop(struct pa_mcalign *m, struct pa_memchunk *c);
#endif #endif

View file

@ -7,29 +7,29 @@
#include "iochannel.h" #include "iochannel.h"
#include "cli.h" #include "cli.h"
int module_init(struct core *c, struct module*m) { int module_init(struct pa_core *c, struct pa_module*m) {
struct iochannel *io; struct pa_iochannel *io;
assert(c && m); assert(c && m);
if (stdin_inuse || stdout_inuse) { if (pa_stdin_inuse || pa_stdout_inuse) {
fprintf(stderr, "STDIN/STDUSE already used\n"); fprintf(stderr, "STDIN/STDUSE already used\n");
return -1; return -1;
} }
stdin_inuse = stdout_inuse = 1; pa_stdin_inuse = pa_stdout_inuse = 1;
io = iochannel_new(c->mainloop, STDIN_FILENO, STDOUT_FILENO); io = pa_iochannel_new(c->mainloop, STDIN_FILENO, STDOUT_FILENO);
assert(io); assert(io);
iochannel_set_noclose(io, 1); pa_iochannel_set_noclose(io, 1);
m->userdata = cli_new(c, io); m->userdata = pa_cli_new(c, io);
assert(m->userdata); assert(m->userdata);
return 0; return 0;
} }
void module_done(struct core *c, struct module*m) { void module_done(struct pa_core *c, struct pa_module*m) {
assert(c && m); assert(c && m);
cli_free(m->userdata); pa_cli_free(m->userdata);
assert(stdin_inuse && stdout_inuse); assert(pa_stdin_inuse && pa_stdout_inuse);
stdin_inuse = stdout_inuse = 0; pa_stdin_inuse = pa_stdout_inuse = 0;
} }

View file

@ -19,9 +19,9 @@
#include "sample-util.h" #include "sample-util.h"
struct userdata { struct userdata {
struct sink *sink; struct pa_sink *sink;
struct source *source; struct pa_source *source;
struct core *core; struct pa_core *core;
struct pa_sample_spec sample_spec; struct pa_sample_spec sample_spec;
size_t in_fragment_size, out_fragment_size, in_fragments, out_fragments, out_fill; size_t in_fragment_size, out_fragment_size, in_fragments, out_fragments, out_fill;
@ -31,13 +31,13 @@ struct userdata {
void *in_mmap, *out_mmap; void *in_mmap, *out_mmap;
size_t in_mmap_length, out_mmap_length; size_t in_mmap_length, out_mmap_length;
struct mainloop_source *mainloop_source; void *mainloop_source;
struct memblock **in_memblocks, **out_memblocks; struct pa_memblock **in_memblocks, **out_memblocks;
unsigned out_current, in_current; unsigned out_current, in_current;
}; };
void module_done(struct core *c, struct module*m); void module_done(struct pa_core *c, struct pa_module*m);
static void out_clear_memblocks(struct userdata*u, unsigned n) { static void out_clear_memblocks(struct userdata*u, unsigned n) {
unsigned i = u->out_current; unsigned i = u->out_current;
@ -48,7 +48,7 @@ static void out_clear_memblocks(struct userdata*u, unsigned n) {
while (n > 0) { while (n > 0) {
if (u->out_memblocks[i]) { if (u->out_memblocks[i]) {
memblock_unref_fixed(u->out_memblocks[i]); pa_memblock_unref_fixed(u->out_memblocks[i]);
u->out_memblocks[i] = NULL; u->out_memblocks[i] = NULL;
} }
@ -64,15 +64,15 @@ static void out_fill_memblocks(struct userdata *u, unsigned n) {
assert(u && u->out_memblocks); assert(u && u->out_memblocks);
while (n > 0) { while (n > 0) {
struct memchunk chunk; struct pa_memchunk chunk;
if (!u->out_memblocks[u->out_current]) { if (!u->out_memblocks[u->out_current]) {
u->out_memblocks[u->out_current] = chunk.memblock = memblock_new_fixed(u->out_mmap+u->out_fragment_size*u->out_current, u->out_fragment_size); u->out_memblocks[u->out_current] = chunk.memblock = pa_memblock_new_fixed(u->out_mmap+u->out_fragment_size*u->out_current, u->out_fragment_size);
chunk.length = chunk.memblock->length; chunk.length = chunk.memblock->length;
chunk.index = 0; chunk.index = 0;
sink_render_into_full(u->sink, &chunk); pa_sink_render_into_full(u->sink, &chunk);
} }
u->out_current++; u->out_current++;
@ -106,14 +106,14 @@ static void in_post_memblocks(struct userdata *u, unsigned n) {
assert(u && u->in_memblocks); assert(u && u->in_memblocks);
while (n > 0) { while (n > 0) {
struct memchunk chunk; struct pa_memchunk chunk;
if (!u->in_memblocks[u->in_current]) { if (!u->in_memblocks[u->in_current]) {
u->in_memblocks[u->in_current] = chunk.memblock = memblock_new_fixed(u->in_mmap+u->in_fragment_size*u->in_current, u->in_fragment_size); u->in_memblocks[u->in_current] = chunk.memblock = pa_memblock_new_fixed(u->in_mmap+u->in_fragment_size*u->in_current, u->in_fragment_size);
chunk.length = chunk.memblock->length; chunk.length = chunk.memblock->length;
chunk.index = 0; chunk.index = 0;
source_post(u->source, &chunk); pa_source_post(u->source, &chunk);
} }
u->in_current++; u->in_current++;
@ -133,7 +133,7 @@ static void in_clear_memblocks(struct userdata*u, unsigned n) {
while (n > 0) { while (n > 0) {
if (u->in_memblocks[i]) { if (u->in_memblocks[i]) {
memblock_unref_fixed(u->in_memblocks[i]); pa_memblock_unref_fixed(u->in_memblocks[i]);
u->in_memblocks[i] = NULL; u->in_memblocks[i] = NULL;
} }
@ -172,7 +172,7 @@ static void io_callback(struct pa_mainloop_api *m, void *id, int fd, enum pa_mai
do_write(u); do_write(u);
} }
static uint32_t sink_get_latency_cb(struct sink *s) { static uint32_t sink_get_latency_cb(struct pa_sink *s) {
struct userdata *u = s->userdata; struct userdata *u = s->userdata;
assert(s && u); assert(s && u);
@ -180,7 +180,7 @@ static uint32_t sink_get_latency_cb(struct sink *s) {
return pa_samples_usec(u->out_fill, &s->sample_spec); return pa_samples_usec(u->out_fill, &s->sample_spec);
} }
int module_init(struct core *c, struct module*m) { int module_init(struct pa_core *c, struct pa_module*m) {
struct audio_buf_info info; struct audio_buf_info info;
struct userdata *u = NULL; struct userdata *u = NULL;
char *p; char *p;
@ -240,7 +240,7 @@ int module_init(struct core *c, struct module*m) {
goto fail; goto fail;
} }
if (oss_auto_format(u->fd, &u->sample_spec) < 0) if (pa_oss_auto_format(u->fd, &u->sample_spec) < 0)
goto fail; goto fail;
if (mode != O_WRONLY) { if (mode != O_WRONLY) {
@ -262,12 +262,12 @@ int module_init(struct core *c, struct module*m) {
} }
} else { } else {
u->source = source_new(c, "dsp", 0, &u->sample_spec); u->source = pa_source_new(c, "dsp", 0, &u->sample_spec);
assert(u->source); assert(u->source);
u->source->userdata = u; u->source->userdata = u;
u->in_memblocks = malloc(sizeof(struct memblock *)*u->in_fragments); u->in_memblocks = malloc(sizeof(struct pa_memblock *)*u->in_fragments);
memset(u->in_memblocks, 0, sizeof(struct memblock *)*u->in_fragments); memset(u->in_memblocks, 0, sizeof(struct pa_memblock *)*u->in_fragments);
enable_bits |= PCM_ENABLE_INPUT; enable_bits |= PCM_ENABLE_INPUT;
} }
@ -291,15 +291,15 @@ int module_init(struct core *c, struct module*m) {
goto fail; goto fail;
} }
} else { } else {
silence_memory(u->out_mmap, u->out_mmap_length, &u->sample_spec); pa_silence_memory(u->out_mmap, u->out_mmap_length, &u->sample_spec);
u->sink = sink_new(c, "dsp", 0, &u->sample_spec); u->sink = pa_sink_new(c, "dsp", 0, &u->sample_spec);
assert(u->sink); assert(u->sink);
u->sink->get_latency = sink_get_latency_cb; u->sink->get_latency = sink_get_latency_cb;
u->sink->userdata = u; u->sink->userdata = u;
u->out_memblocks = malloc(sizeof(struct memblock *)*u->out_fragments); u->out_memblocks = malloc(sizeof(struct memblock *)*u->out_fragments);
memset(u->out_memblocks, 0, sizeof(struct memblock *)*u->out_fragments); memset(u->out_memblocks, 0, sizeof(struct pa_memblock *)*u->out_fragments);
enable_bits |= PCM_ENABLE_OUTPUT; enable_bits |= PCM_ENABLE_OUTPUT;
} }
@ -329,7 +329,7 @@ fail:
return -1; return -1;
} }
void module_done(struct core *c, struct module*m) { void pa_module_done(struct pa_core *c, struct pa_module*m) {
struct userdata *u; struct userdata *u;
assert(c && m); assert(c && m);
@ -353,10 +353,10 @@ void module_done(struct core *c, struct module*m) {
munmap(u->out_mmap, u->out_mmap_length); munmap(u->out_mmap, u->out_mmap_length);
if (u->sink) if (u->sink)
sink_free(u->sink); pa_sink_free(u->sink);
if (u->source) if (u->source)
source_free(u->source); pa_source_free(u->source);
if (u->mainloop_source) if (u->mainloop_source)
u->core->mainloop->cancel_io(u->core->mainloop, u->mainloop_source); u->core->mainloop->cancel_io(u->core->mainloop, u->mainloop_source);

View file

@ -18,12 +18,12 @@
#include "sample-util.h" #include "sample-util.h"
struct userdata { struct userdata {
struct sink *sink; struct pa_sink *sink;
struct source *source; struct pa_source *source;
struct iochannel *io; struct pa_iochannel *io;
struct core *core; struct pa_core *core;
struct memchunk memchunk, silence; struct pa_memchunk memchunk, silence;
uint32_t in_fragment_size, out_fragment_size, sample_size; uint32_t in_fragment_size, out_fragment_size, sample_size;
@ -31,15 +31,15 @@ struct userdata {
}; };
static void do_write(struct userdata *u) { static void do_write(struct userdata *u) {
struct memchunk *memchunk; struct pa_memchunk *memchunk;
ssize_t r; ssize_t r;
assert(u); assert(u);
if (!u->sink || !iochannel_is_writable(u->io)) if (!u->sink || !pa_iochannel_is_writable(u->io))
return; return;
if (!u->memchunk.length) { if (!u->memchunk.length) {
if (sink_render(u->sink, u->out_fragment_size, &u->memchunk) < 0) if (pa_sink_render(u->sink, u->out_fragment_size, &u->memchunk) < 0)
memchunk = &u->silence; memchunk = &u->silence;
else else
memchunk = &u->memchunk; memchunk = &u->memchunk;
@ -47,7 +47,7 @@ static void do_write(struct userdata *u) {
assert(memchunk->memblock && memchunk->length); assert(memchunk->memblock && memchunk->length);
if ((r = iochannel_write(u->io, memchunk->memblock->data + memchunk->index, memchunk->length)) < 0) { if ((r = pa_iochannel_write(u->io, memchunk->memblock->data + memchunk->index, memchunk->length)) < 0) {
fprintf(stderr, "write() failed: %s\n", strerror(errno)); fprintf(stderr, "write() failed: %s\n", strerror(errno));
return; return;
} }
@ -59,24 +59,24 @@ static void do_write(struct userdata *u) {
u->memchunk.length -= r; u->memchunk.length -= r;
if (u->memchunk.length <= 0) { if (u->memchunk.length <= 0) {
memblock_unref(u->memchunk.memblock); pa_memblock_unref(u->memchunk.memblock);
u->memchunk.memblock = NULL; u->memchunk.memblock = NULL;
} }
} }
} }
static void do_read(struct userdata *u) { static void do_read(struct userdata *u) {
struct memchunk memchunk; struct pa_memchunk memchunk;
ssize_t r; ssize_t r;
assert(u); assert(u);
if (!u->source || !iochannel_is_readable(u->io)) if (!u->source || !pa_iochannel_is_readable(u->io))
return; return;
memchunk.memblock = memblock_new(u->in_fragment_size); memchunk.memblock = pa_memblock_new(u->in_fragment_size);
assert(memchunk.memblock); assert(memchunk.memblock);
if ((r = iochannel_read(u->io, memchunk.memblock->data, memchunk.memblock->length)) < 0) { if ((r = pa_iochannel_read(u->io, memchunk.memblock->data, memchunk.memblock->length)) < 0) {
memblock_unref(memchunk.memblock); pa_memblock_unref(memchunk.memblock);
fprintf(stderr, "read() failed: %s\n", strerror(errno)); fprintf(stderr, "read() failed: %s\n", strerror(errno));
return; return;
} }
@ -85,18 +85,18 @@ static void do_read(struct userdata *u) {
memchunk.length = memchunk.memblock->length = r; memchunk.length = memchunk.memblock->length = r;
memchunk.index = 0; memchunk.index = 0;
source_post(u->source, &memchunk); pa_source_post(u->source, &memchunk);
memblock_unref(memchunk.memblock); pa_memblock_unref(memchunk.memblock);
}; };
static void io_callback(struct iochannel *io, void*userdata) { static void io_callback(struct pa_iochannel *io, void*userdata) {
struct userdata *u = userdata; struct userdata *u = userdata;
assert(u); assert(u);
do_write(u); do_write(u);
do_read(u); do_read(u);
} }
static uint32_t sink_get_latency_cb(struct sink *s) { static uint32_t sink_get_latency_cb(struct pa_sink *s) {
int arg; int arg;
struct userdata *u = s->userdata; struct userdata *u = s->userdata;
assert(s && u && u->sink); assert(s && u && u->sink);
@ -110,7 +110,7 @@ static uint32_t sink_get_latency_cb(struct sink *s) {
return pa_samples_usec(arg, &s->sample_spec); return pa_samples_usec(arg, &s->sample_spec);
} }
int module_init(struct core *c, struct module*m) { int module_init(struct pa_core *c, struct pa_module*m) {
struct audio_buf_info info; struct audio_buf_info info;
struct userdata *u = NULL; struct userdata *u = NULL;
char *p; char *p;
@ -154,7 +154,7 @@ int module_init(struct core *c, struct module*m) {
goto fail; goto fail;
} }
if (oss_auto_format(fd, &ss) < 0) if (pa_oss_auto_format(fd, &ss) < 0)
goto fail; goto fail;
if (ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &frag_size) < 0) { if (ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &frag_size) < 0) {
@ -180,7 +180,7 @@ int module_init(struct core *c, struct module*m) {
u->core = c; u->core = c;
if (mode != O_RDONLY) { if (mode != O_RDONLY) {
u->sink = sink_new(c, "dsp", 0, &ss); u->sink = pa_sink_new(c, "dsp", 0, &ss);
assert(u->sink); assert(u->sink);
u->sink->get_latency = sink_get_latency_cb; u->sink->get_latency = sink_get_latency_cb;
u->sink->userdata = u; u->sink->userdata = u;
@ -188,7 +188,7 @@ int module_init(struct core *c, struct module*m) {
u->sink = NULL; u->sink = NULL;
if (mode != O_WRONLY) { if (mode != O_WRONLY) {
u->source = source_new(c, "dsp", 0, &ss); u->source = pa_source_new(c, "dsp", 0, &ss);
assert(u->source); assert(u->source);
u->source->userdata = u; u->source->userdata = u;
} else } else
@ -196,9 +196,9 @@ int module_init(struct core *c, struct module*m) {
assert(u->source || u->sink); assert(u->source || u->sink);
u->io = iochannel_new(c->mainloop, u->source ? fd : -1, u->sink ? fd : 0); u->io = pa_iochannel_new(c->mainloop, u->source ? fd : -1, u->sink ? fd : 0);
assert(u->io); assert(u->io);
iochannel_set_callback(u->io, io_callback, u); pa_iochannel_set_callback(u->io, io_callback, u);
u->fd = fd; u->fd = fd;
u->memchunk.memblock = NULL; u->memchunk.memblock = NULL;
@ -207,9 +207,9 @@ int module_init(struct core *c, struct module*m) {
u->out_fragment_size = out_frag_size; u->out_fragment_size = out_frag_size;
u->in_fragment_size = in_frag_size; u->in_fragment_size = in_frag_size;
u->silence.memblock = memblock_new(u->silence.length = u->out_fragment_size); u->silence.memblock = pa_memblock_new(u->silence.length = u->out_fragment_size);
assert(u->silence.memblock); assert(u->silence.memblock);
silence_memblock(u->silence.memblock, &ss); pa_silence_memblock(u->silence.memblock, &ss);
u->silence.index = 0; u->silence.index = 0;
m->userdata = u; m->userdata = u;
@ -223,7 +223,7 @@ fail:
return -1; return -1;
} }
void module_done(struct core *c, struct module*m) { void module_done(struct pa_core *c, struct pa_module*m) {
struct userdata *u; struct userdata *u;
assert(c && m); assert(c && m);
@ -231,14 +231,14 @@ void module_done(struct core *c, struct module*m) {
assert(u); assert(u);
if (u->memchunk.memblock) if (u->memchunk.memblock)
memblock_unref(u->memchunk.memblock); pa_memblock_unref(u->memchunk.memblock);
if (u->silence.memblock) if (u->silence.memblock)
memblock_unref(u->silence.memblock); pa_memblock_unref(u->silence.memblock);
if (u->sink) if (u->sink)
sink_free(u->sink); pa_sink_free(u->sink);
if (u->source) if (u->source)
source_free(u->source); pa_source_free(u->source);
iochannel_free(u->io); pa_iochannel_free(u->io);
free(u); free(u);
} }

View file

@ -15,13 +15,13 @@
struct userdata { struct userdata {
char *filename; char *filename;
struct sink *sink; struct pa_sink *sink;
struct iochannel *io; struct pa_iochannel *io;
struct core *core; struct pa_core *core;
void *mainloop_source; void *mainloop_source;
struct pa_mainloop_api *mainloop; struct pa_mainloop_api *mainloop;
struct memchunk memchunk; struct pa_memchunk memchunk;
}; };
static void do_write(struct userdata *u) { static void do_write(struct userdata *u) {
@ -30,16 +30,16 @@ static void do_write(struct userdata *u) {
u->mainloop->enable_fixed(u->mainloop, u->mainloop_source, 0); u->mainloop->enable_fixed(u->mainloop, u->mainloop_source, 0);
if (!iochannel_is_writable(u->io)) if (!pa_iochannel_is_writable(u->io))
return; return;
if (!u->memchunk.length) if (!u->memchunk.length)
if (sink_render(u->sink, PIPE_BUF, &u->memchunk) < 0) if (pa_sink_render(u->sink, PIPE_BUF, &u->memchunk) < 0)
return; return;
assert(u->memchunk.memblock && u->memchunk.length); assert(u->memchunk.memblock && u->memchunk.length);
if ((r = iochannel_write(u->io, u->memchunk.memblock->data + u->memchunk.index, u->memchunk.length)) < 0) { if ((r = pa_iochannel_write(u->io, u->memchunk.memblock->data + u->memchunk.index, u->memchunk.length)) < 0) {
fprintf(stderr, "write() failed: %s\n", strerror(errno)); fprintf(stderr, "write() failed: %s\n", strerror(errno));
return; return;
} }
@ -48,16 +48,16 @@ static void do_write(struct userdata *u) {
u->memchunk.length -= r; u->memchunk.length -= r;
if (u->memchunk.length <= 0) { if (u->memchunk.length <= 0) {
memblock_unref(u->memchunk.memblock); pa_memblock_unref(u->memchunk.memblock);
u->memchunk.memblock = NULL; u->memchunk.memblock = NULL;
} }
} }
static void notify_cb(struct sink*s) { static void notify_cb(struct pa_sink*s) {
struct userdata *u = s->userdata; struct userdata *u = s->userdata;
assert(s && u); assert(s && u);
if (iochannel_is_writable(u->io)) if (pa_iochannel_is_writable(u->io))
u->mainloop->enable_fixed(u->mainloop, u->mainloop_source, 1); u->mainloop->enable_fixed(u->mainloop, u->mainloop_source, 1);
} }
@ -67,13 +67,13 @@ static void fixed_callback(struct pa_mainloop_api *m, void *id, void *userdata)
do_write(u); do_write(u);
} }
static void io_callback(struct iochannel *io, void*userdata) { static void io_callback(struct pa_iochannel *io, void*userdata) {
struct userdata *u = userdata; struct userdata *u = userdata;
assert(u); assert(u);
do_write(u); do_write(u);
} }
int module_init(struct core *c, struct module*m) { int module_init(struct pa_core *c, struct pa_module*m) {
struct userdata *u = NULL; struct userdata *u = NULL;
struct stat st; struct stat st;
char *p; char *p;
@ -109,14 +109,14 @@ int module_init(struct core *c, struct module*m) {
u->filename = strdup(p); u->filename = strdup(p);
assert(u->filename); assert(u->filename);
u->core = c; u->core = c;
u->sink = sink_new(c, "fifo", 0, &ss); u->sink = pa_sink_new(c, "fifo", 0, &ss);
assert(u->sink); assert(u->sink);
u->sink->notify = notify_cb; u->sink->notify = notify_cb;
u->sink->userdata = u; u->sink->userdata = u;
u->io = iochannel_new(c->mainloop, -1, fd); u->io = pa_iochannel_new(c->mainloop, -1, fd);
assert(u->io); assert(u->io);
iochannel_set_callback(u->io, io_callback, u); pa_iochannel_set_callback(u->io, io_callback, u);
u->memchunk.memblock = NULL; u->memchunk.memblock = NULL;
u->memchunk.length = 0; u->memchunk.length = 0;
@ -137,7 +137,7 @@ fail:
return -1; return -1;
} }
void module_done(struct core *c, struct module*m) { void module_done(struct pa_core *c, struct pa_module*m) {
struct userdata *u; struct userdata *u;
assert(c && m); assert(c && m);
@ -145,10 +145,10 @@ void module_done(struct core *c, struct module*m) {
assert(u); assert(u);
if (u->memchunk.memblock) if (u->memchunk.memblock)
memblock_unref(u->memchunk.memblock); pa_memblock_unref(u->memchunk.memblock);
sink_free(u->sink); pa_sink_free(u->sink);
iochannel_free(u->io); pa_iochannel_free(u->io);
u->mainloop->cancel_fixed(u->mainloop, u->mainloop_source); u->mainloop->cancel_fixed(u->mainloop, u->mainloop_source);
assert(u->filename); assert(u->filename);

View file

@ -9,23 +9,23 @@
#ifdef USE_PROTOCOL_SIMPLE #ifdef USE_PROTOCOL_SIMPLE
#include "protocol-simple.h" #include "protocol-simple.h"
#define protocol_free protocol_simple_free #define protocol_free pa_protocol_simple_free
#define IPV4_PORT 4711 #define IPV4_PORT 4711
#define UNIX_SOCKET_DIR "/tmp/polypaudio" #define UNIX_SOCKET_DIR "/tmp/polypaudio"
#define UNIX_SOCKET "/tmp/polypaudio/simple" #define UNIX_SOCKET "/tmp/polypaudio/simple"
#else #else
#ifdef USE_PROTOCOL_CLI #ifdef USE_PROTOCOL_CLI
#include "protocol-cli.h" #include "protocol-cli.h"
#define protocol_new protocol_cli_new #define protocol_new pa_protocol_cli_new
#define protocol_free protocol_cli_free #define protocol_free pa_protocol_cli_free
#define IPV4_PORT 4712 #define IPV4_PORT 4712
#define UNIX_SOCKET_DIR "/tmp/polypaudio" #define UNIX_SOCKET_DIR "/tmp/polypaudio"
#define UNIX_SOCKET "/tmp/polypaudio/cli" #define UNIX_SOCKET "/tmp/polypaudio/cli"
#else #else
#ifdef USE_PROTOCOL_NATIVE #ifdef USE_PROTOCOL_NATIVE
#include "protocol-native.h" #include "protocol-native.h"
#define protocol_new protocol_native_new #define protocol_new pa_protocol_native_new
#define protocol_free protocol_native_free #define protocol_free pa_protocol_native_free
#define IPV4_PORT 4713 #define IPV4_PORT 4713
#define UNIX_SOCKET_DIR "/tmp/polypaudio" #define UNIX_SOCKET_DIR "/tmp/polypaudio"
#define UNIX_SOCKET "/tmp/polypaudio/native" #define UNIX_SOCKET "/tmp/polypaudio/native"
@ -33,8 +33,8 @@
#ifdef USE_PROTOCOL_ESOUND #ifdef USE_PROTOCOL_ESOUND
#include "protocol-esound.h" #include "protocol-esound.h"
#include "esound-spec.h" #include "esound-spec.h"
#define protocol_new protocol_esound_new #define protocol_new pa_protocol_esound_new
#define protocol_free protocol_esound_free #define protocol_free pa_protocol_esound_free
#define IPV4_PORT ESD_DEFAULT_PORT #define IPV4_PORT ESD_DEFAULT_PORT
#define UNIX_SOCKET_DIR ESD_UNIX_SOCKET_DIR #define UNIX_SOCKET_DIR ESD_UNIX_SOCKET_DIR
#define UNIX_SOCKET ESD_UNIX_SOCKET_NAME #define UNIX_SOCKET ESD_UNIX_SOCKET_NAME
@ -45,27 +45,27 @@
#endif #endif
#endif #endif
int module_init(struct core *c, struct module*m) { int module_init(struct pa_core *c, struct pa_module*m) {
struct socket_server *s; struct pa_socket_server *s;
assert(c && m); assert(c && m);
#ifdef USE_TCP_SOCKETS #ifdef USE_TCP_SOCKETS
if (!(s = socket_server_new_ipv4(c->mainloop, INADDR_LOOPBACK, IPV4_PORT))) if (!(s = pa_socket_server_new_ipv4(c->mainloop, INADDR_LOOPBACK, IPV4_PORT)))
return -1; return -1;
#else #else
if (make_secure_dir(UNIX_SOCKET_DIR) < 0) { if (pa_make_secure_dir(UNIX_SOCKET_DIR) < 0) {
fprintf(stderr, "Failed to create secure socket directory.\n"); fprintf(stderr, "Failed to create secure socket directory.\n");
return -1; return -1;
} }
if (!(s = socket_server_new_unix(c->mainloop, UNIX_SOCKET))) { if (!(s = pa_socket_server_new_unix(c->mainloop, UNIX_SOCKET))) {
rmdir(UNIX_SOCKET_DIR); rmdir(UNIX_SOCKET_DIR);
return -1; return -1;
} }
#endif #endif
#ifdef USE_PROTOCOL_SIMPLE #ifdef USE_PROTOCOL_SIMPLE
m->userdata = protocol_simple_new(c, s, PROTOCOL_SIMPLE_PLAYBACK); m->userdata = pa_protocol_simple_new(c, s, PA_PROTOCOL_SIMPLE_PLAYBACK);
#else #else
m->userdata = protocol_new(c, s); m->userdata = protocol_new(c, s);
#endif #endif
@ -74,7 +74,7 @@ int module_init(struct core *c, struct module*m) {
return 0; return 0;
} }
void module_done(struct core *c, struct module*m) { void module_done(struct pa_core *c, struct pa_module*m) {
assert(c && m); assert(c && m);
protocol_free(m->userdata); protocol_free(m->userdata);

View file

@ -8,13 +8,13 @@
#include "module.h" #include "module.h"
#include "strbuf.h" #include "strbuf.h"
struct module* module_load(struct core *c, const char *name, const char *argument) { struct pa_module* pa_module_load(struct pa_core *c, const char *name, const char *argument) {
struct module *m = NULL; struct pa_module *m = NULL;
int r; int r;
assert(c && name); assert(c && name);
m = malloc(sizeof(struct module)); m = malloc(sizeof(struct pa_module));
assert(m); assert(m);
m->name = strdup(name); m->name = strdup(name);
@ -37,11 +37,11 @@ struct module* module_load(struct core *c, const char *name, const char *argumen
goto fail; goto fail;
if (!c->modules) if (!c->modules)
c->modules = idxset_new(NULL, NULL); c->modules = pa_idxset_new(NULL, NULL);
assert(c->modules); assert(c->modules);
r = idxset_put(c->modules, m, &m->index); r = pa_idxset_put(c->modules, m, &m->index);
assert(r >= 0 && m->index != IDXSET_INVALID); assert(r >= 0 && m->index != PA_IDXSET_INVALID);
fprintf(stderr, "module: loaded %u \"%s\" with argument \"%s\".\n", m->index, m->name, m->argument); fprintf(stderr, "module: loaded %u \"%s\" with argument \"%s\".\n", m->index, m->name, m->argument);
@ -61,7 +61,7 @@ fail:
return NULL; return NULL;
} }
static void module_free(struct module *m) { static void pa_module_free(struct pa_module *m) {
assert(m && m->done && m->core); assert(m && m->done && m->core);
m->done(m->core, m); m->done(m->core, m);
@ -75,75 +75,75 @@ static void module_free(struct module *m) {
} }
void module_unload(struct core *c, struct module *m) { void pa_module_unload(struct pa_core *c, struct pa_module *m) {
assert(c && m); assert(c && m);
assert(c->modules); assert(c->modules);
if (!(m = idxset_remove_by_data(c->modules, m, NULL))) if (!(m = pa_idxset_remove_by_data(c->modules, m, NULL)))
return; return;
module_free(m); pa_module_free(m);
} }
void module_unload_by_index(struct core *c, uint32_t index) { void pa_module_unload_by_index(struct pa_core *c, uint32_t index) {
struct module *m; struct pa_module *m;
assert(c && index != IDXSET_INVALID); assert(c && index != PA_IDXSET_INVALID);
assert(c->modules); assert(c->modules);
if (!(m = idxset_remove_by_index(c->modules, index))) if (!(m = pa_idxset_remove_by_index(c->modules, index)))
return; return;
module_free(m); pa_module_free(m);
} }
void free_callback(void *p, void *userdata) { static void free_callback(void *p, void *userdata) {
struct module *m = p; struct pa_module *m = p;
assert(m); assert(m);
module_free(m); pa_module_free(m);
} }
void module_unload_all(struct core *c) { void pa_module_unload_all(struct pa_core *c) {
assert(c); assert(c);
if (!c->modules) if (!c->modules)
return; return;
idxset_free(c->modules, free_callback, NULL); pa_idxset_free(c->modules, free_callback, NULL);
c->modules = NULL; c->modules = NULL;
} }
char *module_list_to_string(struct core *c) { char *pa_module_list_to_string(struct pa_core *c) {
struct strbuf *s; struct pa_strbuf *s;
struct module *m; struct pa_module *m;
uint32_t index = IDXSET_INVALID; uint32_t index = PA_IDXSET_INVALID;
assert(c); assert(c);
s = strbuf_new(); s = pa_strbuf_new();
assert(s); assert(s);
strbuf_printf(s, "%u module(s) loaded.\n", idxset_ncontents(c->modules)); pa_strbuf_printf(s, "%u module(s) loaded.\n", pa_idxset_ncontents(c->modules));
for (m = idxset_first(c->modules, &index); m; m = idxset_next(c->modules, &index)) for (m = pa_idxset_first(c->modules, &index); m; m = pa_idxset_next(c->modules, &index))
strbuf_printf(s, " index: %u, name: <%s>, argument: <%s>\n", m->index, m->name, m->argument); pa_strbuf_printf(s, " index: %u, name: <%s>, argument: <%s>\n", m->index, m->name, m->argument);
return strbuf_tostring_free(s); return pa_strbuf_tostring_free(s);
} }
struct once_info { struct once_info {
struct core *core; struct pa_core *core;
uint32_t index; uint32_t index;
}; };
void module_unload_once_callback(void *userdata) { static void module_unload_once_callback(void *userdata) {
struct once_info *i = userdata; struct once_info *i = userdata;
assert(i); assert(i);
module_unload_by_index(i->core, i->index); pa_module_unload_by_index(i->core, i->index);
free(i); free(i);
} }
void module_unload_request(struct core *c, struct module *m) { void pa_module_unload_request(struct pa_core *c, struct pa_module *m) {
struct once_info *i; struct once_info *i;
assert(c && m); assert(c && m);

View file

@ -6,28 +6,28 @@
#include "core.h" #include "core.h"
struct module { struct pa_module {
struct core *core; struct pa_core *core;
char *name, *argument; char *name, *argument;
uint32_t index; uint32_t index;
lt_dlhandle dl; lt_dlhandle dl;
int (*init)(struct core *c, struct module*m); int (*init)(struct pa_core *c, struct pa_module*m);
void (*done)(struct core *c, struct module*m); void (*done)(struct pa_core *c, struct pa_module*m);
void *userdata; void *userdata;
}; };
struct module* module_load(struct core *c, const char *name, const char*argument); struct pa_module* pa_module_load(struct pa_core *c, const char *name, const char*argument);
void module_unload(struct core *c, struct module *m); void pa_module_unload(struct pa_core *c, struct pa_module *m);
void module_unload_by_index(struct core *c, uint32_t index); void pa_module_unload_by_index(struct pa_core *c, uint32_t index);
void module_unload_all(struct core *c); void pa_module_unload_all(struct pa_core *c);
char *module_list_to_string(struct core *c); char *pa_module_list_to_string(struct pa_core *c);
void module_unload_request(struct core *c, struct module *m); void pa_module_unload_request(struct pa_core *c, struct pa_module *m);
#endif #endif

View file

@ -8,20 +8,20 @@
#include "namereg.h" #include "namereg.h"
struct namereg_entry { struct namereg_entry {
enum namereg_type type; enum pa_namereg_type type;
char *name; char *name;
void *data; void *data;
}; };
void namereg_free(struct core *c) { void pa_namereg_free(struct pa_core *c) {
assert(c); assert(c);
if (!c->namereg) if (!c->namereg)
return; return;
assert(hashset_ncontents(c->namereg) == 0); assert(pa_hashset_ncontents(c->namereg) == 0);
hashset_free(c->namereg, NULL, NULL); pa_hashset_free(c->namereg, NULL, NULL);
} }
const char *namereg_register(struct core *c, const char *name, enum namereg_type type, void *data, int fail) { const char *pa_namereg_register(struct pa_core *c, const char *name, enum pa_namereg_type type, void *data, int fail) {
struct namereg_entry *e; struct namereg_entry *e;
char *n = NULL; char *n = NULL;
int r; int r;
@ -29,11 +29,11 @@ const char *namereg_register(struct core *c, const char *name, enum namereg_type
assert(c && name && data); assert(c && name && data);
if (!c->namereg) { if (!c->namereg) {
c->namereg = hashset_new(idxset_string_hash_func, idxset_string_compare_func); c->namereg = pa_hashset_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
assert(c->namereg); assert(c->namereg);
} }
if ((e = hashset_get(c->namereg, name)) && fail) if ((e = pa_hashset_get(c->namereg, name)) && fail)
return NULL; return NULL;
if (!e) if (!e)
@ -47,7 +47,7 @@ const char *namereg_register(struct core *c, const char *name, enum namereg_type
for (i = 1; i <= 99; i++) { for (i = 1; i <= 99; i++) {
snprintf(n, l+2, "%s%u", name, i); snprintf(n, l+2, "%s%u", name, i);
if (!(e = hashset_get(c->namereg, n))) if (!(e = pa_hashset_get(c->namereg, n)))
break; break;
} }
@ -64,36 +64,36 @@ const char *namereg_register(struct core *c, const char *name, enum namereg_type
e->name = n; e->name = n;
e->data = data; e->data = data;
r = hashset_put(c->namereg, e->name, e); r = pa_hashset_put(c->namereg, e->name, e);
assert (r >= 0); assert (r >= 0);
return e->name; return e->name;
} }
void namereg_unregister(struct core *c, const char *name) { void pa_namereg_unregister(struct pa_core *c, const char *name) {
struct namereg_entry *e; struct namereg_entry *e;
int r; int r;
assert(c && name); assert(c && name);
e = hashset_get(c->namereg, name); e = pa_hashset_get(c->namereg, name);
assert(e); assert(e);
r = hashset_remove(c->namereg, name); r = pa_hashset_remove(c->namereg, name);
assert(r >= 0); assert(r >= 0);
free(e->name); free(e->name);
free(e); free(e);
} }
void* namereg_get(struct core *c, const char *name, enum namereg_type type) { void* pa_namereg_get(struct pa_core *c, const char *name, enum pa_namereg_type type) {
struct namereg_entry *e; struct namereg_entry *e;
uint32_t index; uint32_t index;
char *x = NULL; char *x = NULL;
void *d = NULL; void *d = NULL;
assert(c && name); assert(c && name);
if ((e = hashset_get(c->namereg, name))) if ((e = pa_hashset_get(c->namereg, name)))
if (e->type == e->type) if (e->type == e->type)
return e->data; return e->data;
@ -102,10 +102,10 @@ void* namereg_get(struct core *c, const char *name, enum namereg_type type) {
if (!x || *x != 0) if (!x || *x != 0)
return NULL; return NULL;
if (type == NAMEREG_SINK) if (type == PA_NAMEREG_SINK)
d = idxset_get_by_index(c->sinks, index); d = pa_idxset_get_by_index(c->sinks, index);
else if (type == NAMEREG_SOURCE) else if (type == PA_NAMEREG_SOURCE)
d = idxset_get_by_index(c->sources, index); d = pa_idxset_get_by_index(c->sources, index);
return d; return d;
} }

View file

@ -3,15 +3,15 @@
#include "core.h" #include "core.h"
enum namereg_type { enum pa_namereg_type {
NAMEREG_SINK, PA_NAMEREG_SINK,
NAMEREG_SOURCE PA_NAMEREG_SOURCE
}; };
void namereg_free(struct core *c); void pa_namereg_free(struct pa_core *c);
const char *namereg_register(struct core *c, const char *name, enum namereg_type type, void *data, int fail); const char *pa_namereg_register(struct pa_core *c, const char *name, enum pa_namereg_type type, void *data, int fail);
void namereg_unregister(struct core *c, const char *name); void pa_namereg_unregister(struct pa_core *c, const char *name);
void* namereg_get(struct core *c, const char *name, enum namereg_type type); void* pa_namereg_get(struct pa_core *c, const char *name, enum pa_namereg_type type);
#endif #endif

View file

@ -7,7 +7,7 @@
#include "oss-util.h" #include "oss-util.h"
int oss_auto_format(int fd, struct pa_sample_spec *ss) { int pa_oss_auto_format(int fd, struct pa_sample_spec *ss) {
int format, channels, speed; int format, channels, speed;
assert(fd >= 0 && ss); assert(fd >= 0 && ss);

View file

@ -3,6 +3,6 @@
#include "sample.h" #include "sample.h"
int oss_auto_format(int fd, struct pa_sample_spec *ss); int pa_oss_auto_format(int fd, struct pa_sample_spec *ss);
#endif #endif

View file

@ -75,9 +75,9 @@ static void stream_complete_callback(struct pa_context*c, struct pa_stream *s, v
static void context_complete_callback(struct pa_context *c, int success, void *userdata) { static void context_complete_callback(struct pa_context *c, int success, void *userdata) {
static const struct pa_sample_spec ss = { static const struct pa_sample_spec ss = {
.format = PA_SAMPLE_S16NE, .format = PA_SAMPLE_S16LE,
.rate = 44100, .rate = 44100,
.channels = 1 .channels = 2
}; };
assert(c && !stream); assert(c && !stream);

View file

@ -3,44 +3,44 @@
#include "packet.h" #include "packet.h"
struct packet* packet_new(size_t length) { struct pa_packet* pa_packet_new(size_t length) {
struct packet *p; struct pa_packet *p;
assert(length); assert(length);
p = malloc(sizeof(struct packet)+length); p = malloc(sizeof(struct pa_packet)+length);
assert(p); assert(p);
p->ref = 1; p->ref = 1;
p->length = length; p->length = length;
p->data = (uint8_t*) (p+1); p->data = (uint8_t*) (p+1);
p->type = PACKET_APPENDED; p->type = PA_PACKET_APPENDED;
return p; return p;
} }
struct packet* packet_new_dynamic(uint8_t* data, size_t length) { struct pa_packet* pa_packet_new_dynamic(uint8_t* data, size_t length) {
struct packet *p; struct pa_packet *p;
assert(data && length); assert(data && length);
p = malloc(sizeof(struct packet)); p = malloc(sizeof(struct pa_packet));
assert(p); assert(p);
p->ref = 1; p->ref = 1;
p->length = length; p->length = length;
p->data = data; p->data = data;
p->type = PACKET_DYNAMIC; p->type = PA_PACKET_DYNAMIC;
return p; return p;
} }
struct packet* packet_ref(struct packet *p) { struct pa_packet* pa_packet_ref(struct pa_packet *p) {
assert(p && p->ref >= 1); assert(p && p->ref >= 1);
p->ref++; p->ref++;
return p; return p;
} }
void packet_unref(struct packet *p) { void pa_packet_unref(struct pa_packet *p) {
assert(p && p->ref >= 1); assert(p && p->ref >= 1);
p->ref--; p->ref--;
if (p->ref == 0) { if (p->ref == 0) {
if (p->type == PACKET_DYNAMIC) if (p->type == PA_PACKET_DYNAMIC)
free(p->data); free(p->data);
free(p); free(p);
} }

View file

@ -4,17 +4,17 @@
#include <sys/types.h> #include <sys/types.h>
#include <stdint.h> #include <stdint.h>
struct packet { struct pa_packet {
enum { PACKET_APPENDED, PACKET_DYNAMIC } type; enum { PA_PACKET_APPENDED, PA_PACKET_DYNAMIC } type;
unsigned ref; unsigned ref;
size_t length; size_t length;
uint8_t *data; uint8_t *data;
}; };
struct packet* packet_new(size_t length); struct pa_packet* pa_packet_new(size_t length);
struct packet* packet_new_dynamic(uint8_t* data, size_t length); struct pa_packet* pa_packet_new_dynamic(uint8_t* data, size_t length);
struct packet* packet_ref(struct packet *p); struct pa_packet* pa_packet_ref(struct pa_packet *p);
void packet_unref(struct packet *p); void pa_packet_unref(struct pa_packet *p);
#endif #endif

View file

@ -5,17 +5,17 @@
#include "protocol-native-spec.h" #include "protocol-native-spec.h"
struct reply_info { struct reply_info {
struct pdispatch *pdispatch; struct pa_pdispatch *pdispatch;
struct reply_info *next, *previous; struct reply_info *next, *previous;
int (*callback)(struct pdispatch *pd, uint32_t command, uint32_t tag, struct tagstruct *t, void *userdata); int (*callback)(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
void *userdata; void *userdata;
uint32_t tag; uint32_t tag;
void *mainloop_timeout; void *mainloop_timeout;
}; };
struct pdispatch { struct pa_pdispatch {
struct pa_mainloop_api *mainloop; struct pa_mainloop_api *mainloop;
const struct pdispatch_command *command_table; const struct pa_pdispatch_command *command_table;
unsigned n_commands; unsigned n_commands;
struct reply_info *replies; struct reply_info *replies;
}; };
@ -37,13 +37,13 @@ static void reply_info_free(struct reply_info *r) {
free(r); free(r);
} }
struct pdispatch* pdispatch_new(struct pa_mainloop_api *mainloop, const struct pdispatch_command*table, unsigned entries) { struct pa_pdispatch* pa_pdispatch_new(struct pa_mainloop_api *mainloop, const struct pa_pdispatch_command*table, unsigned entries) {
struct pdispatch *pd; struct pa_pdispatch *pd;
assert(mainloop); assert(mainloop);
assert((entries && table) || (!entries && !table)); assert((entries && table) || (!entries && !table));
pd = malloc(sizeof(struct pdispatch)); pd = malloc(sizeof(struct pa_pdispatch));
assert(pd); assert(pd);
pd->mainloop = mainloop; pd->mainloop = mainloop;
pd->command_table = table; pd->command_table = table;
@ -52,27 +52,27 @@ struct pdispatch* pdispatch_new(struct pa_mainloop_api *mainloop, const struct p
return pd; return pd;
} }
void pdispatch_free(struct pdispatch *pd) { void pa_pdispatch_free(struct pa_pdispatch *pd) {
assert(pd); assert(pd);
while (pd->replies) while (pd->replies)
reply_info_free(pd->replies); reply_info_free(pd->replies);
free(pd); free(pd);
} }
int pdispatch_run(struct pdispatch *pd, struct packet*packet, void *userdata) { int pa_pdispatch_run(struct pa_pdispatch *pd, struct pa_packet*packet, void *userdata) {
uint32_t tag, command; uint32_t tag, command;
assert(pd && packet); assert(pd && packet);
struct tagstruct *ts = NULL; struct pa_tagstruct *ts = NULL;
assert(pd && packet && packet->data); assert(pd && packet && packet->data);
if (packet->length <= 8) if (packet->length <= 8)
goto fail; goto fail;
ts = tagstruct_new(packet->data, packet->length); ts = pa_tagstruct_new(packet->data, packet->length);
assert(ts); assert(ts);
if (tagstruct_getu32(ts, &command) < 0 || if (pa_tagstruct_getu32(ts, &command) < 0 ||
tagstruct_getu32(ts, &tag) < 0) pa_tagstruct_getu32(ts, &tag) < 0)
goto fail; goto fail;
if (command == PA_COMMAND_ERROR || command == PA_COMMAND_REPLY) { if (command == PA_COMMAND_ERROR || command == PA_COMMAND_REPLY) {
@ -96,7 +96,7 @@ int pdispatch_run(struct pdispatch *pd, struct packet*packet, void *userdata) {
goto fail; goto fail;
} else if (pd->command_table && command < pd->n_commands) { } else if (pd->command_table && command < pd->n_commands) {
const struct pdispatch_command *c = pd->command_table+command; const struct pa_pdispatch_command *c = pd->command_table+command;
if (!c->proc) if (!c->proc)
goto fail; goto fail;
@ -106,13 +106,13 @@ int pdispatch_run(struct pdispatch *pd, struct packet*packet, void *userdata) {
} else } else
goto fail; goto fail;
tagstruct_free(ts); pa_tagstruct_free(ts);
return 0; return 0;
fail: fail:
if (ts) if (ts)
tagstruct_free(ts); pa_tagstruct_free(ts);
return -1; return -1;
} }
@ -125,7 +125,7 @@ static void timeout_callback(struct pa_mainloop_api*m, void *id, const struct ti
reply_info_free(r); reply_info_free(r);
} }
void pdispatch_register_reply(struct pdispatch *pd, uint32_t tag, int timeout, int (*cb)(struct pdispatch *pd, uint32_t command, uint32_t tag, struct tagstruct *t, void *userdata), void *userdata) { void pa_pdispatch_register_reply(struct pa_pdispatch *pd, uint32_t tag, int timeout, int (*cb)(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata), void *userdata) {
struct reply_info *r; struct reply_info *r;
struct timeval tv; struct timeval tv;
assert(pd && cb); assert(pd && cb);

View file

@ -6,17 +6,17 @@
#include "packet.h" #include "packet.h"
#include "mainloop-api.h" #include "mainloop-api.h"
struct pdispatch; struct pa_pdispatch;
struct pdispatch_command { struct pa_pdispatch_command {
int (*proc)(struct pdispatch *pd, uint32_t command, uint32_t tag, struct tagstruct *t, void *userdata); int (*proc)(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
}; };
struct pdispatch* pdispatch_new(struct pa_mainloop_api *m, const struct pdispatch_command*table, unsigned entries); struct pa_pdispatch* pa_pdispatch_new(struct pa_mainloop_api *m, const struct pa_pdispatch_command*table, unsigned entries);
void pdispatch_free(struct pdispatch *pd); void pa_pdispatch_free(struct pa_pdispatch *pd);
int pdispatch_run(struct pdispatch *pd, struct packet*p, void *userdata); int pa_pdispatch_run(struct pa_pdispatch *pd, struct pa_packet*p, void *userdata);
void pdispatch_register_reply(struct pdispatch *pd, uint32_t tag, int timeout, int (*cb)(struct pdispatch *pd, uint32_t command, uint32_t tag, struct tagstruct *t, void *userdata), void *userdata); void pa_pdispatch_register_reply(struct pa_pdispatch *pd, uint32_t tag, int timeout, int (*cb)(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata), void *userdata);
#endif #endif

View file

@ -20,10 +20,10 @@
struct pa_context { struct pa_context {
char *name; char *name;
struct pa_mainloop_api* mainloop; struct pa_mainloop_api* mainloop;
struct socket_client *client; struct pa_socket_client *client;
struct pstream *pstream; struct pa_pstream *pstream;
struct pdispatch *pdispatch; struct pa_pdispatch *pdispatch;
struct dynarray *streams; struct pa_dynarray *streams;
struct pa_stream *first_stream; struct pa_stream *first_stream;
uint32_t ctag; uint32_t ctag;
uint32_t errno; uint32_t errno;
@ -59,9 +59,9 @@ struct pa_stream {
void *die_userdata; void *die_userdata;
}; };
static int command_request(struct pdispatch *pd, uint32_t command, uint32_t tag, struct tagstruct *t, void *userdata); static int command_request(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static const struct pdispatch_command command_table[PA_COMMAND_MAX] = { static const struct pa_pdispatch_command command_table[PA_COMMAND_MAX] = {
[PA_COMMAND_ERROR] = { NULL }, [PA_COMMAND_ERROR] = { NULL },
[PA_COMMAND_REPLY] = { NULL }, [PA_COMMAND_REPLY] = { NULL },
[PA_COMMAND_CREATE_PLAYBACK_STREAM] = { NULL }, [PA_COMMAND_CREATE_PLAYBACK_STREAM] = { NULL },
@ -82,7 +82,7 @@ struct pa_context *pa_context_new(struct pa_mainloop_api *mainloop, const char *
c->client = NULL; c->client = NULL;
c->pstream = NULL; c->pstream = NULL;
c->pdispatch = NULL; c->pdispatch = NULL;
c->streams = dynarray_new(); c->streams = pa_dynarray_new();
assert(c->streams); assert(c->streams);
c->first_stream = NULL; c->first_stream = NULL;
c->errno = PA_ERROR_OK; c->errno = PA_ERROR_OK;
@ -105,13 +105,13 @@ void pa_context_free(struct pa_context *c) {
pa_stream_free(c->first_stream); pa_stream_free(c->first_stream);
if (c->client) if (c->client)
socket_client_free(c->client); pa_socket_client_free(c->client);
if (c->pdispatch) if (c->pdispatch)
pdispatch_free(c->pdispatch); pa_pdispatch_free(c->pdispatch);
if (c->pstream) if (c->pstream)
pstream_free(c->pstream); pa_pstream_free(c->pstream);
if (c->streams) if (c->streams)
dynarray_free(c->streams, NULL, NULL); pa_dynarray_free(c->streams, NULL, NULL);
free(c->name); free(c->name);
free(c); free(c);
@ -141,7 +141,7 @@ static void context_dead(struct pa_context *c) {
c->die_callback(c, c->die_userdata); c->die_callback(c, c->die_userdata);
} }
static void pstream_die_callback(struct pstream *p, void *userdata) { static void pstream_die_callback(struct pa_pstream *p, void *userdata) {
struct pa_context *c = userdata; struct pa_context *c = userdata;
assert(p && c); assert(p && c);
@ -152,11 +152,11 @@ static void pstream_die_callback(struct pstream *p, void *userdata) {
context_dead(c); context_dead(c);
} }
static int pstream_packet_callback(struct pstream *p, struct packet *packet, void *userdata) { static int pstream_packet_callback(struct pa_pstream *p, struct pa_packet *packet, void *userdata) {
struct pa_context *c = userdata; struct pa_context *c = userdata;
assert(p && packet && c); assert(p && packet && c);
if (pdispatch_run(c->pdispatch, packet, c) < 0) { if (pa_pdispatch_run(c->pdispatch, packet, c) < 0) {
fprintf(stderr, "polyp.c: invalid packet.\n"); fprintf(stderr, "polyp.c: invalid packet.\n");
return -1; return -1;
} }
@ -164,12 +164,12 @@ static int pstream_packet_callback(struct pstream *p, struct packet *packet, voi
return 0; return 0;
} }
static int pstream_memblock_callback(struct pstream *p, uint32_t channel, int32_t delta, struct memchunk *chunk, void *userdata) { static int pstream_memblock_callback(struct pa_pstream *p, uint32_t channel, int32_t delta, struct pa_memchunk *chunk, void *userdata) {
struct pa_context *c = userdata; struct pa_context *c = userdata;
struct pa_stream *s; struct pa_stream *s;
assert(p && chunk && c && chunk->memblock && chunk->memblock->data); assert(p && chunk && c && chunk->memblock && chunk->memblock->data);
if (!(s = dynarray_get(c->streams, channel))) if (!(s = pa_dynarray_get(c->streams, channel)))
return -1; return -1;
if (s->read_callback) if (s->read_callback)
@ -178,11 +178,11 @@ static int pstream_memblock_callback(struct pstream *p, uint32_t channel, int32_
return 0; return 0;
} }
static void on_connection(struct socket_client *client, struct iochannel*io, void *userdata) { static void on_connection(struct pa_socket_client *client, struct pa_iochannel*io, void *userdata) {
struct pa_context *c = userdata; struct pa_context *c = userdata;
assert(client && io && c && c->state == CONTEXT_CONNECTING); assert(client && io && c && c->state == CONTEXT_CONNECTING);
socket_client_free(client); pa_socket_client_free(client);
c->client = NULL; c->client = NULL;
if (!io) { if (!io) {
@ -195,13 +195,13 @@ static void on_connection(struct socket_client *client, struct iochannel*io, voi
return; return;
} }
c->pstream = pstream_new(c->mainloop, io); c->pstream = pa_pstream_new(c->mainloop, io);
assert(c->pstream); assert(c->pstream);
pstream_set_die_callback(c->pstream, pstream_die_callback, c); pa_pstream_set_die_callback(c->pstream, pstream_die_callback, c);
pstream_set_recieve_packet_callback(c->pstream, pstream_packet_callback, c); pa_pstream_set_recieve_packet_callback(c->pstream, pstream_packet_callback, c);
pstream_set_recieve_memblock_callback(c->pstream, pstream_memblock_callback, c); pa_pstream_set_recieve_memblock_callback(c->pstream, pstream_memblock_callback, c);
c->pdispatch = pdispatch_new(c->mainloop, command_table, PA_COMMAND_MAX); c->pdispatch = pa_pdispatch_new(c->mainloop, command_table, PA_COMMAND_MAX);
assert(c->pdispatch); assert(c->pdispatch);
c->state = CONTEXT_READY; c->state = CONTEXT_READY;
@ -214,7 +214,7 @@ int pa_context_connect(struct pa_context *c, const char *server, void (*complete
assert(c && c->state == CONTEXT_UNCONNECTED); assert(c && c->state == CONTEXT_UNCONNECTED);
assert(!c->client); assert(!c->client);
if (!(c->client = socket_client_new_unix(c->mainloop, server ? server : DEFAULT_SERVER))) { if (!(c->client = pa_socket_client_new_unix(c->mainloop, server ? server : DEFAULT_SERVER))) {
c->errno = PA_ERROR_CONNECTIONREFUSED; c->errno = PA_ERROR_CONNECTIONREFUSED;
return -1; return -1;
} }
@ -222,7 +222,7 @@ int pa_context_connect(struct pa_context *c, const char *server, void (*complete
c->connect_complete_callback = complete; c->connect_complete_callback = complete;
c->connect_complete_userdata = userdata; c->connect_complete_userdata = userdata;
socket_client_set_callback(c->client, on_connection, c); pa_socket_client_set_callback(c->client, on_connection, c);
c->state = CONTEXT_CONNECTING; c->state = CONTEXT_CONNECTING;
return 0; return 0;
@ -249,20 +249,20 @@ void pa_context_set_die_callback(struct pa_context *c, void (*cb)(struct pa_cont
c->die_userdata = userdata; c->die_userdata = userdata;
} }
static int command_request(struct pdispatch *pd, uint32_t command, uint32_t tag, struct tagstruct *t, void *userdata) { static int command_request(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
struct pa_stream *s; struct pa_stream *s;
struct pa_context *c = userdata; struct pa_context *c = userdata;
uint32_t bytes, channel; uint32_t bytes, channel;
assert(pd && command == PA_COMMAND_REQUEST && t && c); assert(pd && command == PA_COMMAND_REQUEST && t && c);
if (tagstruct_getu32(t, &channel) < 0 || if (pa_tagstruct_getu32(t, &channel) < 0 ||
tagstruct_getu32(t, &bytes) < 0 || pa_tagstruct_getu32(t, &bytes) < 0 ||
!tagstruct_eof(t)) { !pa_tagstruct_eof(t)) {
c->errno = PA_ERROR_PROTOCOL; c->errno = PA_ERROR_PROTOCOL;
return -1; return -1;
} }
if (!(s = dynarray_get(c->streams, channel))) { if (!(s = pa_dynarray_get(c->streams, channel))) {
c->errno = PA_ERROR_PROTOCOL; c->errno = PA_ERROR_PROTOCOL;
return -1; return -1;
} }
@ -277,7 +277,7 @@ static int command_request(struct pdispatch *pd, uint32_t command, uint32_t tag,
return 0; return 0;
} }
static int create_playback_callback(struct pdispatch *pd, uint32_t command, uint32_t tag, struct tagstruct *t, void *userdata) { static int create_playback_callback(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
int ret = 0; int ret = 0;
struct pa_stream *s = userdata; struct pa_stream *s = userdata;
assert(pd && s && s->state == STREAM_CREATING); assert(pd && s && s->state == STREAM_CREATING);
@ -286,7 +286,7 @@ static int create_playback_callback(struct pdispatch *pd, uint32_t command, uint
struct pa_context *c = s->context; struct pa_context *c = s->context;
assert(c); assert(c);
if (command == PA_COMMAND_ERROR && tagstruct_getu32(t, &s->context->errno) < 0) { if (command == PA_COMMAND_ERROR && pa_tagstruct_getu32(t, &s->context->errno) < 0) {
s->context->errno = PA_ERROR_PROTOCOL; s->context->errno = PA_ERROR_PROTOCOL;
ret = -1; ret = -1;
} else if (command == PA_COMMAND_TIMEOUT) { } else if (command == PA_COMMAND_TIMEOUT) {
@ -297,16 +297,16 @@ static int create_playback_callback(struct pdispatch *pd, uint32_t command, uint
goto fail; goto fail;
} }
if (tagstruct_getu32(t, &s->channel) < 0 || if (pa_tagstruct_getu32(t, &s->channel) < 0 ||
tagstruct_getu32(t, &s->device_index) < 0 || pa_tagstruct_getu32(t, &s->device_index) < 0 ||
!tagstruct_eof(t)) { !pa_tagstruct_eof(t)) {
s->context->errno = PA_ERROR_PROTOCOL; s->context->errno = PA_ERROR_PROTOCOL;
ret = -1; ret = -1;
goto fail; goto fail;
} }
s->channel_valid = 1; s->channel_valid = 1;
dynarray_put(s->context->streams, s->channel, s); pa_dynarray_put(s->context->streams, s->channel, s);
s->state = STREAM_READY; s->state = STREAM_READY;
assert(s->create_complete_callback); assert(s->create_complete_callback);
@ -331,7 +331,7 @@ int pa_stream_new(
void *userdata) { void *userdata) {
struct pa_stream *s; struct pa_stream *s;
struct tagstruct *t; struct pa_tagstruct *t;
uint32_t tag; uint32_t tag;
assert(c && name && ss && c->state == CONTEXT_READY && complete); assert(c && name && ss && c->state == CONTEXT_READY && complete);
@ -356,21 +356,21 @@ int pa_stream_new(
s->device_index = (uint32_t) -1; s->device_index = (uint32_t) -1;
s->direction = dir; s->direction = dir;
t = tagstruct_new(NULL, 0); t = pa_tagstruct_new(NULL, 0);
assert(t); assert(t);
tagstruct_putu32(t, dir == PA_STREAM_PLAYBACK ? PA_COMMAND_CREATE_PLAYBACK_STREAM : PA_COMMAND_CREATE_RECORD_STREAM); pa_tagstruct_putu32(t, dir == PA_STREAM_PLAYBACK ? PA_COMMAND_CREATE_PLAYBACK_STREAM : PA_COMMAND_CREATE_RECORD_STREAM);
tagstruct_putu32(t, tag = c->ctag++); pa_tagstruct_putu32(t, tag = c->ctag++);
tagstruct_puts(t, name); pa_tagstruct_puts(t, name);
tagstruct_put_sample_spec(t, ss); pa_tagstruct_put_sample_spec(t, ss);
tagstruct_putu32(t, (uint32_t) -1); pa_tagstruct_putu32(t, (uint32_t) -1);
tagstruct_putu32(t, attr ? attr->queue_length : DEFAULT_QUEUE_LENGTH); pa_tagstruct_putu32(t, attr ? attr->queue_length : DEFAULT_QUEUE_LENGTH);
tagstruct_putu32(t, attr ? attr->max_length : DEFAULT_MAX_LENGTH); pa_tagstruct_putu32(t, attr ? attr->max_length : DEFAULT_MAX_LENGTH);
tagstruct_putu32(t, attr ? attr->prebuf : DEFAULT_PREBUF); pa_tagstruct_putu32(t, attr ? attr->prebuf : DEFAULT_PREBUF);
pstream_send_tagstruct(c->pstream, t); pa_pstream_send_tagstruct(c->pstream, t);
pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, create_playback_callback, s); pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, create_playback_callback, s);
s->next = c->first_stream; s->next = c->first_stream;
if (s->next) if (s->next)
@ -385,17 +385,17 @@ void pa_stream_free(struct pa_stream *s) {
assert(s && s->context); assert(s && s->context);
if (s->channel_valid) { if (s->channel_valid) {
struct tagstruct *t = tagstruct_new(NULL, 0); struct pa_tagstruct *t = pa_tagstruct_new(NULL, 0);
assert(t); assert(t);
tagstruct_putu32(t, PA_COMMAND_DELETE_PLAYBACK_STREAM); pa_tagstruct_putu32(t, PA_COMMAND_DELETE_PLAYBACK_STREAM);
tagstruct_putu32(t, s->context->ctag++); pa_tagstruct_putu32(t, s->context->ctag++);
tagstruct_putu32(t, s->channel); pa_tagstruct_putu32(t, s->channel);
pstream_send_tagstruct(s->context->pstream, t); pa_pstream_send_tagstruct(s->context->pstream, t);
} }
if (s->channel_valid) if (s->channel_valid)
dynarray_put(s->context->streams, s->channel, NULL); pa_dynarray_put(s->context->streams, s->channel, NULL);
if (s->next) if (s->next)
s->next->previous = s->previous; s->next->previous = s->previous;
@ -414,17 +414,17 @@ void pa_stream_set_write_callback(struct pa_stream *s, void (*cb)(struct pa_stre
} }
void pa_stream_write(struct pa_stream *s, const void *data, size_t length) { void pa_stream_write(struct pa_stream *s, const void *data, size_t length) {
struct memchunk chunk; struct pa_memchunk chunk;
assert(s && s->context && data && length); assert(s && s->context && data && length);
chunk.memblock = memblock_new(length); chunk.memblock = pa_memblock_new(length);
assert(chunk.memblock && chunk.memblock->data); assert(chunk.memblock && chunk.memblock->data);
memcpy(chunk.memblock->data, data, length); memcpy(chunk.memblock->data, data, length);
chunk.index = 0; chunk.index = 0;
chunk.length = length; chunk.length = length;
pstream_send_memblock(s->context->pstream, s->channel, 0, &chunk); pa_pstream_send_memblock(s->context->pstream, s->channel, 0, &chunk);
memblock_unref(chunk.memblock); pa_memblock_unref(chunk.memblock);
/*fprintf(stderr, "Sent %u bytes\n", length);*/ /*fprintf(stderr, "Sent %u bytes\n", length);*/

View file

@ -4,55 +4,55 @@
#include "protocol-cli.h" #include "protocol-cli.h"
#include "cli.h" #include "cli.h"
struct protocol_cli { struct pa_protocol_cli {
struct core *core; struct pa_core *core;
struct socket_server*server; struct pa_socket_server*server;
struct idxset *connections; struct pa_idxset *connections;
}; };
static void cli_eof_cb(struct cli*c, void*userdata) { static void cli_eof_cb(struct pa_cli*c, void*userdata) {
struct protocol_cli *p = userdata; struct pa_protocol_cli *p = userdata;
assert(p); assert(p);
idxset_remove_by_data(p->connections, c, NULL); pa_idxset_remove_by_data(p->connections, c, NULL);
cli_free(c); pa_cli_free(c);
} }
static void on_connection(struct socket_server*s, struct iochannel *io, void *userdata) { static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, void *userdata) {
struct protocol_cli *p = userdata; struct pa_protocol_cli *p = userdata;
struct cli *c; struct pa_cli *c;
assert(s && io && p); assert(s && io && p);
c = cli_new(p->core, io); c = pa_cli_new(p->core, io);
assert(c); assert(c);
cli_set_eof_callback(c, cli_eof_cb, p); pa_cli_set_eof_callback(c, cli_eof_cb, p);
idxset_put(p->connections, c, NULL); pa_idxset_put(p->connections, c, NULL);
} }
struct protocol_cli* protocol_cli_new(struct core *core, struct socket_server *server) { struct pa_protocol_cli* pa_protocol_cli_new(struct pa_core *core, struct pa_socket_server *server) {
struct protocol_cli* p; struct pa_protocol_cli* p;
assert(core && server); assert(core && server);
p = malloc(sizeof(struct protocol_cli)); p = malloc(sizeof(struct pa_protocol_cli));
assert(p); assert(p);
p->core = core; p->core = core;
p->server = server; p->server = server;
p->connections = idxset_new(NULL, NULL); p->connections = pa_idxset_new(NULL, NULL);
socket_server_set_callback(p->server, on_connection, p); pa_socket_server_set_callback(p->server, on_connection, p);
return p; return p;
} }
static void free_connection(void *p, void *userdata) { static void free_connection(void *p, void *userdata) {
assert(p); assert(p);
cli_free(p); pa_cli_free(p);
} }
void protocol_cli_free(struct protocol_cli *p) { void pa_protocol_cli_free(struct pa_protocol_cli *p) {
assert(p); assert(p);
idxset_free(p->connections, free_connection, NULL); pa_idxset_free(p->connections, free_connection, NULL);
socket_server_free(p->server); pa_socket_server_free(p->server);
free(p); free(p);
} }

View file

@ -4,9 +4,9 @@
#include "core.h" #include "core.h"
#include "socket-server.h" #include "socket-server.h"
struct protocol_cli; struct pa_protocol_cli;
struct protocol_cli* protocol_cli_new(struct core *core, struct socket_server *server); struct pa_protocol_cli* pa_protocol_cli_new(struct pa_core *core, struct pa_socket_server *server);
void protocol_cli_free(struct protocol_cli *n); void pa_protocol_cli_free(struct pa_protocol_cli *n);
#endif #endif

View file

@ -17,9 +17,9 @@
struct connection { struct connection {
uint32_t index; uint32_t index;
struct protocol_esound *protocol; struct pa_protocol_esound *protocol;
struct iochannel *io; struct pa_iochannel *io;
struct client *client; struct pa_client *client;
int authorized, swap_byte_order; int authorized, swap_byte_order;
void *read_data; void *read_data;
size_t read_data_alloc, read_data_length; size_t read_data_alloc, read_data_length;
@ -27,15 +27,15 @@ struct connection {
size_t write_data_alloc, write_data_index, write_data_length; size_t write_data_alloc, write_data_index, write_data_length;
esd_proto_t request; esd_proto_t request;
esd_client_state_t state; esd_client_state_t state;
struct sink_input *sink_input; struct pa_sink_input *sink_input;
struct memblockq *input_memblockq; struct pa_memblockq *input_memblockq;
}; };
struct protocol_esound { struct pa_protocol_esound {
int public; int public;
struct core *core; struct pa_core *core;
struct socket_server *server; struct pa_socket_server *server;
struct idxset *connections; struct pa_idxset *connections;
uint32_t sink_index; uint32_t sink_index;
unsigned n_player; unsigned n_player;
}; };
@ -51,10 +51,10 @@ typedef struct proto_handler {
#define BUFSIZE (1024) #define BUFSIZE (1024)
static void sink_input_drop_cb(struct sink_input *i, size_t length); static void sink_input_drop_cb(struct pa_sink_input *i, size_t length);
static int sink_input_peek_cb(struct sink_input *i, struct memchunk *chunk); static int sink_input_peek_cb(struct pa_sink_input *i, struct pa_memchunk *chunk);
static void sink_input_kill_cb(struct sink_input *i); static void sink_input_kill_cb(struct pa_sink_input *i);
static uint32_t sink_input_get_latency_cb(struct sink_input *i); static uint32_t sink_input_get_latency_cb(struct pa_sink_input *i);
static int esd_proto_connect(struct connection *c, const void *data, size_t length); static int esd_proto_connect(struct connection *c, const void *data, size_t length);
static int esd_proto_stream_play(struct connection *c, const void *data, size_t length); static int esd_proto_stream_play(struct connection *c, const void *data, size_t length);
@ -104,36 +104,36 @@ static struct proto_handler proto_map[ESD_PROTO_MAX] = {
static void connection_free(struct connection *c) { static void connection_free(struct connection *c) {
assert(c); assert(c);
idxset_remove_by_data(c->protocol->connections, c, NULL); pa_idxset_remove_by_data(c->protocol->connections, c, NULL);
if (c->state == ESD_STREAMING_DATA) if (c->state == ESD_STREAMING_DATA)
c->protocol->n_player--; c->protocol->n_player--;
client_free(c->client); pa_client_free(c->client);
if (c->sink_input) if (c->sink_input)
sink_input_free(c->sink_input); pa_sink_input_free(c->sink_input);
if (c->input_memblockq) if (c->input_memblockq)
memblockq_free(c->input_memblockq); pa_memblockq_free(c->input_memblockq);
free(c->read_data); free(c->read_data);
free(c->write_data); free(c->write_data);
iochannel_free(c->io); pa_iochannel_free(c->io);
free(c); free(c);
} }
static struct sink* get_output_sink(struct protocol_esound *p) { static struct pa_sink* get_output_sink(struct pa_protocol_esound *p) {
struct sink *s; struct pa_sink *s;
assert(p); assert(p);
if (!(s = idxset_get_by_index(p->core->sinks, p->sink_index))) if (!(s = pa_idxset_get_by_index(p->core->sinks, p->sink_index)))
s = sink_get_default(p->core); s = pa_sink_get_default(p->core);
if (s->index) if (s->index)
p->sink_index = s->index; p->sink_index = s->index;
else else
p->sink_index = IDXSET_INVALID; p->sink_index = PA_IDXSET_INVALID;
return s; return s;
} }
@ -183,7 +183,7 @@ static int esd_proto_connect(struct connection *c, const void *data, size_t leng
static int esd_proto_stream_play(struct connection *c, const void *data, size_t length) { static int esd_proto_stream_play(struct connection *c, const void *data, size_t length) {
char name[ESD_NAME_MAX]; char name[ESD_NAME_MAX];
int format, rate; int format, rate;
struct sink *sink; struct pa_sink *sink;
struct pa_sample_spec ss; struct pa_sample_spec ss;
assert(length == (sizeof(int)*2+ESD_NAME_MAX)); assert(length == (sizeof(int)*2+ESD_NAME_MAX));
@ -203,14 +203,14 @@ static int esd_proto_stream_play(struct connection *c, const void *data, size_t
strncpy(name, data + sizeof(int)*2, sizeof(name)); strncpy(name, data + sizeof(int)*2, sizeof(name));
name[sizeof(name)-1] = 0; name[sizeof(name)-1] = 0;
client_rename(c->client, name); pa_client_rename(c->client, name);
assert(!c->input_memblockq); assert(!c->input_memblockq);
c->input_memblockq = memblockq_new(MEMBLOCKQ_LENGTH, pa_sample_size(&ss), MEMBLOCKQ_PREBUF); c->input_memblockq = pa_memblockq_new(MEMBLOCKQ_LENGTH, pa_sample_size(&ss), MEMBLOCKQ_PREBUF);
assert(c->input_memblockq); assert(c->input_memblockq);
assert(!c->sink_input); assert(!c->sink_input);
c->sink_input = sink_input_new(sink, name, &ss); c->sink_input = pa_sink_input_new(sink, name, &ss);
assert(c->sink_input); assert(c->sink_input);
c->sink_input->peek = sink_input_peek_cb; c->sink_input->peek = sink_input_peek_cb;
@ -233,14 +233,14 @@ static int esd_proto_stream_record(struct connection *c, const void *data, size_
} }
static int esd_proto_get_latency(struct connection *c, const void *data, size_t length) { static int esd_proto_get_latency(struct connection *c, const void *data, size_t length) {
struct sink *sink; struct pa_sink *sink;
int latency, *lag; int latency, *lag;
assert(c && !data && length == 0); assert(c && !data && length == 0);
if (!(sink = get_output_sink(c->protocol))) if (!(sink = get_output_sink(c->protocol)))
latency = 0; latency = 0;
else { else {
float usec = sink_get_latency(sink); float usec = pa_sink_get_latency(sink);
usec += pa_samples_usec(MEMBLOCKQ_LENGTH-BUFSIZE, &sink->sample_spec); usec += pa_samples_usec(MEMBLOCKQ_LENGTH-BUFSIZE, &sink->sample_spec);
latency = (int) ((usec*44100)/1000000); latency = (int) ((usec*44100)/1000000);
} }
@ -254,7 +254,7 @@ static int esd_proto_get_latency(struct connection *c, const void *data, size_t
static int esd_proto_server_info(struct connection *c, const void *data, size_t length) { static int esd_proto_server_info(struct connection *c, const void *data, size_t length) {
int rate = 44100, format = ESD_STEREO|ESD_BITS16; int rate = 44100, format = ESD_STEREO|ESD_BITS16;
int *response; int *response;
struct sink *sink; struct pa_sink *sink;
assert(c && data && length == sizeof(int)); assert(c && data && length == sizeof(int));
if ((sink = get_output_sink(c->protocol))) { if ((sink = get_output_sink(c->protocol))) {
@ -275,7 +275,7 @@ static int esd_proto_all_info(struct connection *c, const void *data, size_t len
void *response; void *response;
size_t t, k, s; size_t t, k, s;
struct connection *conn; struct connection *conn;
size_t index = IDXSET_INVALID; size_t index = PA_IDXSET_INVALID;
assert(c && data && length == sizeof(int)); assert(c && data && length == sizeof(int));
if (esd_proto_server_info(c, data, length) < 0) if (esd_proto_server_info(c, data, length) < 0)
@ -286,7 +286,7 @@ static int esd_proto_all_info(struct connection *c, const void *data, size_t len
response = connection_write(c, (t = s+k*(c->protocol->n_player+1))); response = connection_write(c, (t = s+k*(c->protocol->n_player+1)));
assert(k); assert(k);
for (conn = idxset_first(c->protocol->connections, &index); conn; conn = idxset_next(c->protocol->connections, &index)) { for (conn = pa_idxset_first(c->protocol->connections, &index); conn; conn = pa_idxset_next(c->protocol->connections, &index)) {
int format = ESD_BITS16 | ESD_STEREO, rate = 44100, volume = 0xFF; int format = ESD_BITS16 | ESD_STEREO, rate = 44100, volume = 0xFF;
if (conn->state != ESD_STREAMING_DATA) if (conn->state != ESD_STREAMING_DATA)
@ -347,7 +347,7 @@ static int esd_proto_stream_pan(struct connection *c, const void *data, size_t l
ok = connection_write(c, sizeof(int)); ok = connection_write(c, sizeof(int));
assert(ok); assert(ok);
if ((conn = idxset_get_by_index(c->protocol->connections, index))) { if ((conn = pa_idxset_get_by_index(c->protocol->connections, index))) {
assert(conn->sink_input); assert(conn->sink_input);
conn->sink_input->volume = volume; conn->sink_input->volume = volume;
*ok = 1; *ok = 1;
@ -359,24 +359,24 @@ static int esd_proto_stream_pan(struct connection *c, const void *data, size_t l
/*** client callbacks ***/ /*** client callbacks ***/
static void client_kill_cb(struct client *c) { static void client_kill_cb(struct pa_client *c) {
assert(c && c->userdata); assert(c && c->userdata);
connection_free(c->userdata); connection_free(c->userdata);
} }
/*** iochannel callbacks ***/ /*** pa_iochannel callbacks ***/
static int do_read(struct connection *c) { static int do_read(struct connection *c) {
assert(c && c->io); assert(c && c->io);
if (!iochannel_is_readable(c->io)) if (!pa_iochannel_is_readable(c->io))
return 0; return 0;
if (c->state == ESD_NEXT_REQUEST) { if (c->state == ESD_NEXT_REQUEST) {
ssize_t r; ssize_t r;
assert(c->read_data_length < sizeof(c->request)); assert(c->read_data_length < sizeof(c->request));
if ((r = iochannel_read(c->io, ((void*) &c->request) + c->read_data_length, sizeof(c->request) - c->read_data_length)) <= 0) { if ((r = pa_iochannel_read(c->io, ((void*) &c->request) + c->read_data_length, sizeof(c->request) - c->read_data_length)) <= 0) {
fprintf(stderr, "protocol-esound.c: read() failed: %s\n", r == 0 ? "EOF" : strerror(errno)); fprintf(stderr, "protocol-esound.c: read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
return -1; return -1;
} }
@ -423,7 +423,7 @@ static int do_read(struct connection *c) {
assert(c->read_data && c->read_data_length < handler->data_length); assert(c->read_data && c->read_data_length < handler->data_length);
if ((r = iochannel_read(c->io, c->read_data + c->read_data_length, handler->data_length - c->read_data_length)) <= 0) { if ((r = pa_iochannel_read(c->io, c->read_data + c->read_data_length, handler->data_length - c->read_data_length)) <= 0) {
fprintf(stderr, "protocol-esound.c: read() failed: %s\n", r == 0 ? "EOF" : strerror(errno)); fprintf(stderr, "protocol-esound.c: read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
return -1; return -1;
} }
@ -439,20 +439,20 @@ static int do_read(struct connection *c) {
return -1; return -1;
} }
} else if (c->state == ESD_STREAMING_DATA) { } else if (c->state == ESD_STREAMING_DATA) {
struct memchunk chunk; struct pa_memchunk chunk;
ssize_t r; ssize_t r;
assert(c->input_memblockq); assert(c->input_memblockq);
if (!memblockq_is_writable(c->input_memblockq, BUFSIZE)) if (!pa_memblockq_is_writable(c->input_memblockq, BUFSIZE))
return 0; return 0;
chunk.memblock = memblock_new(BUFSIZE); chunk.memblock = pa_memblock_new(BUFSIZE);
assert(chunk.memblock && chunk.memblock->data); assert(chunk.memblock && chunk.memblock->data);
if ((r = iochannel_read(c->io, chunk.memblock->data, BUFSIZE)) <= 0) { if ((r = pa_iochannel_read(c->io, chunk.memblock->data, BUFSIZE)) <= 0) {
fprintf(stderr, "protocol-esound.c: read() failed: %s\n", r == 0 ? "EOF" : strerror(errno)); fprintf(stderr, "protocol-esound.c: read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
memblock_unref(chunk.memblock); pa_memblock_unref(chunk.memblock);
return -1; return -1;
} }
@ -460,10 +460,10 @@ static int do_read(struct connection *c) {
chunk.index = 0; chunk.index = 0;
assert(c->input_memblockq); assert(c->input_memblockq);
memblockq_push_align(c->input_memblockq, &chunk, 0); pa_memblockq_push_align(c->input_memblockq, &chunk, 0);
memblock_unref(chunk.memblock); pa_memblock_unref(chunk.memblock);
assert(c->sink_input); assert(c->sink_input);
sink_notify(c->sink_input->sink); pa_sink_notify(c->sink_input->sink);
} else } else
assert(0); assert(0);
@ -475,14 +475,14 @@ static int do_write(struct connection *c) {
ssize_t r; ssize_t r;
assert(c && c->io); assert(c && c->io);
if (!iochannel_is_writable(c->io)) if (!pa_iochannel_is_writable(c->io))
return 0; return 0;
if (!c->write_data_length) if (!c->write_data_length)
return 0; return 0;
assert(c->write_data_index < c->write_data_length); assert(c->write_data_index < c->write_data_length);
if ((r = iochannel_write(c->io, c->write_data+c->write_data_index, c->write_data_length-c->write_data_index)) < 0) { if ((r = pa_iochannel_write(c->io, c->write_data+c->write_data_index, c->write_data_length-c->write_data_index)) < 0) {
fprintf(stderr, "protocol-esound.c: write() failed: %s\n", strerror(errno)); fprintf(stderr, "protocol-esound.c: write() failed: %s\n", strerror(errno));
return -1; return -1;
} }
@ -493,7 +493,7 @@ static int do_write(struct connection *c) {
return 0; return 0;
} }
static void io_callback(struct iochannel*io, void *userdata) { static void io_callback(struct pa_iochannel*io, void *userdata) {
struct connection *c = userdata; struct connection *c = userdata;
assert(io && c && c->io == io); assert(io && c && c->io == io);
@ -503,42 +503,42 @@ static void io_callback(struct iochannel*io, void *userdata) {
/*** sink_input callbacks ***/ /*** sink_input callbacks ***/
static int sink_input_peek_cb(struct sink_input *i, struct memchunk *chunk) { static int sink_input_peek_cb(struct pa_sink_input *i, struct pa_memchunk *chunk) {
struct connection*c; struct connection*c;
assert(i && i->userdata && chunk); assert(i && i->userdata && chunk);
c = i->userdata; c = i->userdata;
if (memblockq_peek(c->input_memblockq, chunk) < 0) if (pa_memblockq_peek(c->input_memblockq, chunk) < 0)
return -1; return -1;
return 0; return 0;
} }
static void sink_input_drop_cb(struct sink_input *i, size_t length) { static void sink_input_drop_cb(struct pa_sink_input *i, size_t length) {
struct connection*c = i->userdata; struct connection*c = i->userdata;
assert(i && c && length); assert(i && c && length);
memblockq_drop(c->input_memblockq, length); pa_memblockq_drop(c->input_memblockq, length);
if (do_read(c) < 0) if (do_read(c) < 0)
connection_free(c); connection_free(c);
} }
static void sink_input_kill_cb(struct sink_input *i) { static void sink_input_kill_cb(struct pa_sink_input *i) {
assert(i && i->userdata); assert(i && i->userdata);
connection_free((struct connection *) i->userdata); connection_free((struct connection *) i->userdata);
} }
static uint32_t sink_input_get_latency_cb(struct sink_input *i) { static uint32_t sink_input_get_latency_cb(struct pa_sink_input *i) {
struct connection*c = i->userdata; struct connection*c = i->userdata;
assert(i && c); assert(i && c);
return pa_samples_usec(memblockq_get_length(c->input_memblockq), &c->sink_input->sample_spec); return pa_samples_usec(pa_memblockq_get_length(c->input_memblockq), &c->sink_input->sample_spec);
} }
/*** socket server callback ***/ /*** socket server callback ***/
static void on_connection(struct socket_server*s, struct iochannel *io, void *userdata) { static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, void *userdata) {
struct connection *c; struct connection *c;
char cname[256]; char cname[256];
assert(s && io && userdata); assert(s && io && userdata);
@ -547,11 +547,11 @@ static void on_connection(struct socket_server*s, struct iochannel *io, void *us
assert(c); assert(c);
c->protocol = userdata; c->protocol = userdata;
c->io = io; c->io = io;
iochannel_set_callback(c->io, io_callback, c); pa_iochannel_set_callback(c->io, io_callback, c);
iochannel_peer_to_string(io, cname, sizeof(cname)); pa_iochannel_peer_to_string(io, cname, sizeof(cname));
assert(c->protocol->core); assert(c->protocol->core);
c->client = client_new(c->protocol->core, "ESOUND", cname); c->client = pa_client_new(c->protocol->core, "ESOUND", cname);
assert(c->client); assert(c->client);
c->client->kill = client_kill_cb; c->client->kill = client_kill_cb;
c->client->userdata = c; c->client->userdata = c;
@ -572,39 +572,39 @@ static void on_connection(struct socket_server*s, struct iochannel *io, void *us
c->sink_input = NULL; c->sink_input = NULL;
c->input_memblockq = NULL; c->input_memblockq = NULL;
idxset_put(c->protocol->connections, c, &c->index); pa_idxset_put(c->protocol->connections, c, &c->index);
} }
/*** entry points ***/ /*** entry points ***/
struct protocol_esound* protocol_esound_new(struct core*core, struct socket_server *server) { struct pa_protocol_esound* pa_protocol_esound_new(struct pa_core*core, struct pa_socket_server *server) {
struct protocol_esound *p; struct pa_protocol_esound *p;
assert(core && server); assert(core && server);
p = malloc(sizeof(struct protocol_esound)); p = malloc(sizeof(struct pa_protocol_esound));
assert(p); assert(p);
p->public = 1; p->public = 1;
p->server = server; p->server = server;
p->core = core; p->core = core;
p->connections = idxset_new(NULL, NULL); p->connections = pa_idxset_new(NULL, NULL);
assert(p->connections); assert(p->connections);
p->sink_index = IDXSET_INVALID; p->sink_index = PA_IDXSET_INVALID;
p->n_player = 0; p->n_player = 0;
socket_server_set_callback(p->server, on_connection, p); pa_socket_server_set_callback(p->server, on_connection, p);
return p; return p;
} }
void protocol_esound_free(struct protocol_esound *p) { void pa_protocol_esound_free(struct pa_protocol_esound *p) {
struct connection *c; struct connection *c;
assert(p); assert(p);
while ((c = idxset_first(p->connections, NULL))) while ((c = pa_idxset_first(p->connections, NULL)))
connection_free(c); connection_free(c);
idxset_free(p->connections, NULL, NULL); pa_idxset_free(p->connections, NULL, NULL);
socket_server_free(p->server); pa_socket_server_free(p->server);
free(p); free(p);
} }

View file

@ -4,9 +4,9 @@
#include "core.h" #include "core.h"
#include "socket-server.h" #include "socket-server.h"
struct protocol_esound; struct pa_protocol_esound;
struct protocol_esound* protocol_esound_new(struct core*core, struct socket_server *server); struct pa_protocol_esound* pa_protocol_esound_new(struct pa_core*core, struct pa_socket_server *server);
void protocol_esound_free(struct protocol_esound *p); void pa_protocol_esound_free(struct pa_protocol_esound *p);
#endif #endif

View file

@ -14,52 +14,52 @@
#include "pstream-util.h" #include "pstream-util.h"
struct connection; struct connection;
struct protocol_native; struct pa_protocol_native;
struct record_stream { struct record_stream {
struct connection *connection; struct connection *connection;
uint32_t index; uint32_t index;
struct source_output *source_output; struct pa_source_output *source_output;
struct memblockq *memblockq; struct pa_memblockq *memblockq;
}; };
struct playback_stream { struct playback_stream {
struct connection *connection; struct connection *connection;
uint32_t index; uint32_t index;
size_t qlength; size_t qlength;
struct sink_input *sink_input; struct pa_sink_input *sink_input;
struct memblockq *memblockq; struct pa_memblockq *memblockq;
size_t requested_bytes; size_t requested_bytes;
}; };
struct connection { struct connection {
int authorized; int authorized;
struct protocol_native *protocol; struct pa_protocol_native *protocol;
struct client *client; struct pa_client *client;
struct pstream *pstream; struct pa_pstream *pstream;
struct pdispatch *pdispatch; struct pa_pdispatch *pdispatch;
struct idxset *record_streams, *playback_streams; struct pa_idxset *record_streams, *playback_streams;
}; };
struct protocol_native { struct pa_protocol_native {
int public; int public;
struct core *core; struct pa_core *core;
struct socket_server *server; struct pa_socket_server *server;
struct idxset *connections; struct pa_idxset *connections;
}; };
static int sink_input_peek_cb(struct sink_input *i, struct memchunk *chunk); static int sink_input_peek_cb(struct pa_sink_input *i, struct pa_memchunk *chunk);
static void sink_input_drop_cb(struct sink_input *i, size_t length); static void sink_input_drop_cb(struct pa_sink_input *i, size_t length);
static void sink_input_kill_cb(struct sink_input *i); static void sink_input_kill_cb(struct pa_sink_input *i);
static uint32_t sink_input_get_latency_cb(struct sink_input *i); static uint32_t sink_input_get_latency_cb(struct pa_sink_input *i);
static void request_bytes(struct playback_stream*s); static void request_bytes(struct playback_stream*s);
static int command_exit(struct pdispatch *pd, uint32_t command, uint32_t tag, struct tagstruct *t, void *userdata); static int command_exit(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static int command_create_playback_stream(struct pdispatch *pd, uint32_t command, uint32_t tag, struct tagstruct *t, void *userdata); static int command_create_playback_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static int command_delete_playback_stream(struct pdispatch *pd, uint32_t command, uint32_t tag, struct tagstruct *t, void *userdata); static int command_delete_playback_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
static const struct pdispatch_command command_table[PA_COMMAND_MAX] = { static const struct pa_pdispatch_command command_table[PA_COMMAND_MAX] = {
[PA_COMMAND_ERROR] = { NULL }, [PA_COMMAND_ERROR] = { NULL },
[PA_COMMAND_REPLY] = { NULL }, [PA_COMMAND_REPLY] = { NULL },
[PA_COMMAND_CREATE_PLAYBACK_STREAM] = { command_create_playback_stream }, [PA_COMMAND_CREATE_PLAYBACK_STREAM] = { command_create_playback_stream },
@ -74,13 +74,13 @@ static const struct pdispatch_command command_table[PA_COMMAND_MAX] = {
static void record_stream_free(struct record_stream* r) { static void record_stream_free(struct record_stream* r) {
assert(r && r->connection); assert(r && r->connection);
idxset_remove_by_data(r->connection->record_streams, r, NULL); pa_idxset_remove_by_data(r->connection->record_streams, r, NULL);
source_output_free(r->source_output); pa_source_output_free(r->source_output);
memblockq_free(r->memblockq); pa_memblockq_free(r->memblockq);
free(r); free(r);
} }
static struct playback_stream* playback_stream_new(struct connection *c, struct sink *sink, struct pa_sample_spec *ss, const char *name, size_t qlen, size_t maxlength, size_t prebuf) { static struct playback_stream* playback_stream_new(struct connection *c, struct pa_sink *sink, struct pa_sample_spec *ss, const char *name, size_t qlen, size_t maxlength, size_t prebuf) {
struct playback_stream *s; struct playback_stream *s;
assert(c && sink && ss && name && qlen && maxlength && prebuf); assert(c && sink && ss && name && qlen && maxlength && prebuf);
@ -89,7 +89,7 @@ static struct playback_stream* playback_stream_new(struct connection *c, struct
s->connection = c; s->connection = c;
s->qlength = qlen; s->qlength = qlen;
s->sink_input = sink_input_new(sink, name, ss); s->sink_input = pa_sink_input_new(sink, name, ss);
assert(s->sink_input); assert(s->sink_input);
s->sink_input->peek = sink_input_peek_cb; s->sink_input->peek = sink_input_peek_cb;
s->sink_input->drop = sink_input_drop_cb; s->sink_input->drop = sink_input_drop_cb;
@ -97,21 +97,21 @@ static struct playback_stream* playback_stream_new(struct connection *c, struct
s->sink_input->get_latency = sink_input_get_latency_cb; s->sink_input->get_latency = sink_input_get_latency_cb;
s->sink_input->userdata = s; s->sink_input->userdata = s;
s->memblockq = memblockq_new(maxlength, pa_sample_size(ss), prebuf); s->memblockq = pa_memblockq_new(maxlength, pa_sample_size(ss), prebuf);
assert(s->memblockq); assert(s->memblockq);
s->requested_bytes = 0; s->requested_bytes = 0;
idxset_put(c->playback_streams, s, &s->index); pa_idxset_put(c->playback_streams, s, &s->index);
return s; return s;
} }
static void playback_stream_free(struct playback_stream* p) { static void playback_stream_free(struct playback_stream* p) {
assert(p && p->connection); assert(p && p->connection);
idxset_remove_by_data(p->connection->playback_streams, p, NULL); pa_idxset_remove_by_data(p->connection->playback_streams, p, NULL);
sink_input_free(p->sink_input); pa_sink_input_free(p->sink_input);
memblockq_free(p->memblockq); pa_memblockq_free(p->memblockq);
free(p); free(p);
} }
@ -120,27 +120,27 @@ static void connection_free(struct connection *c) {
struct playback_stream *p; struct playback_stream *p;
assert(c && c->protocol); assert(c && c->protocol);
idxset_remove_by_data(c->protocol->connections, c, NULL); pa_idxset_remove_by_data(c->protocol->connections, c, NULL);
while ((r = idxset_first(c->record_streams, NULL))) while ((r = pa_idxset_first(c->record_streams, NULL)))
record_stream_free(r); record_stream_free(r);
idxset_free(c->record_streams, NULL, NULL); pa_idxset_free(c->record_streams, NULL, NULL);
while ((p = idxset_first(c->playback_streams, NULL))) while ((p = pa_idxset_first(c->playback_streams, NULL)))
playback_stream_free(p); playback_stream_free(p);
idxset_free(c->playback_streams, NULL, NULL); pa_idxset_free(c->playback_streams, NULL, NULL);
pdispatch_free(c->pdispatch); pa_pdispatch_free(c->pdispatch);
pstream_free(c->pstream); pa_pstream_free(c->pstream);
client_free(c->client); pa_client_free(c->client);
free(c); free(c);
} }
static void request_bytes(struct playback_stream *s) { static void request_bytes(struct playback_stream *s) {
struct tagstruct *t; struct pa_tagstruct *t;
size_t l; size_t l;
assert(s); assert(s);
if (!(l = memblockq_missing_to(s->memblockq, s->qlength))) if (!(l = pa_memblockq_missing_to(s->memblockq, s->qlength)))
return; return;
if (l <= s->requested_bytes) if (l <= s->requested_bytes)
@ -149,40 +149,40 @@ static void request_bytes(struct playback_stream *s) {
l -= s->requested_bytes; l -= s->requested_bytes;
s->requested_bytes += l; s->requested_bytes += l;
t = tagstruct_new(NULL, 0); t = pa_tagstruct_new(NULL, 0);
assert(t); assert(t);
tagstruct_putu32(t, PA_COMMAND_REQUEST); pa_tagstruct_putu32(t, PA_COMMAND_REQUEST);
tagstruct_putu32(t, (uint32_t) -1); /* tag */ pa_tagstruct_putu32(t, (uint32_t) -1); /* tag */
tagstruct_putu32(t, s->index); pa_tagstruct_putu32(t, s->index);
tagstruct_putu32(t, l); pa_tagstruct_putu32(t, l);
pstream_send_tagstruct(s->connection->pstream, t); pa_pstream_send_tagstruct(s->connection->pstream, t);
/* fprintf(stderr, "Requesting %u bytes\n", l);*/ /* fprintf(stderr, "Requesting %u bytes\n", l);*/
} }
/*** sinkinput callbacks ***/ /*** sinkinput callbacks ***/
static int sink_input_peek_cb(struct sink_input *i, struct memchunk *chunk) { static int sink_input_peek_cb(struct pa_sink_input *i, struct pa_memchunk *chunk) {
struct playback_stream *s; struct playback_stream *s;
assert(i && i->userdata && chunk); assert(i && i->userdata && chunk);
s = i->userdata; s = i->userdata;
if (memblockq_peek(s->memblockq, chunk) < 0) if (pa_memblockq_peek(s->memblockq, chunk) < 0)
return -1; return -1;
return 0; return 0;
} }
static void sink_input_drop_cb(struct sink_input *i, size_t length) { static void sink_input_drop_cb(struct pa_sink_input *i, size_t length) {
struct playback_stream *s; struct playback_stream *s;
assert(i && i->userdata && length); assert(i && i->userdata && length);
s = i->userdata; s = i->userdata;
memblockq_drop(s->memblockq, length); pa_memblockq_drop(s->memblockq, length);
request_bytes(s); request_bytes(s);
} }
static void sink_input_kill_cb(struct sink_input *i) { static void sink_input_kill_cb(struct pa_sink_input *i) {
struct playback_stream *s; struct playback_stream *s;
assert(i && i->userdata); assert(i && i->userdata);
s = i->userdata; s = i->userdata;
@ -190,117 +190,117 @@ static void sink_input_kill_cb(struct sink_input *i) {
playback_stream_free(s); playback_stream_free(s);
} }
static uint32_t sink_input_get_latency_cb(struct sink_input *i) { static uint32_t sink_input_get_latency_cb(struct pa_sink_input *i) {
struct playback_stream *s; struct playback_stream *s;
assert(i && i->userdata); assert(i && i->userdata);
s = i->userdata; s = i->userdata;
return pa_samples_usec(memblockq_get_length(s->memblockq), &s->sink_input->sample_spec); return pa_samples_usec(pa_memblockq_get_length(s->memblockq), &s->sink_input->sample_spec);
} }
/*** pdispatch callbacks ***/ /*** pdispatch callbacks ***/
static int command_create_playback_stream(struct pdispatch *pd, uint32_t command, uint32_t tag, struct tagstruct *t, void *userdata) { static int command_create_playback_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
struct connection *c = userdata; struct connection *c = userdata;
struct playback_stream *s; struct playback_stream *s;
size_t maxlength, prebuf, qlength; size_t maxlength, prebuf, qlength;
uint32_t sink_index; uint32_t sink_index;
const char *name; const char *name;
struct pa_sample_spec ss; struct pa_sample_spec ss;
struct tagstruct *reply; struct pa_tagstruct *reply;
struct sink *sink; struct pa_sink *sink;
assert(c && t && c->protocol && c->protocol->core); assert(c && t && c->protocol && c->protocol->core);
if (tagstruct_gets(t, &name) < 0 || if (pa_tagstruct_gets(t, &name) < 0 ||
tagstruct_get_sample_spec(t, &ss) < 0 || pa_tagstruct_get_sample_spec(t, &ss) < 0 ||
tagstruct_getu32(t, &sink_index) < 0 || pa_tagstruct_getu32(t, &sink_index) < 0 ||
tagstruct_getu32(t, &qlength) < 0 || pa_tagstruct_getu32(t, &qlength) < 0 ||
tagstruct_getu32(t, &maxlength) < 0 || pa_tagstruct_getu32(t, &maxlength) < 0 ||
tagstruct_getu32(t, &prebuf) < 0 || pa_tagstruct_getu32(t, &prebuf) < 0 ||
!tagstruct_eof(t)) !pa_tagstruct_eof(t))
return -1; return -1;
if (!c->authorized) { if (!c->authorized) {
pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS); pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
return 0; return 0;
} }
if (sink_index == (uint32_t) -1) if (sink_index == (uint32_t) -1)
sink = sink_get_default(c->protocol->core); sink = pa_sink_get_default(c->protocol->core);
else else
sink = idxset_get_by_index(c->protocol->core->sinks, sink_index); sink = pa_idxset_get_by_index(c->protocol->core->sinks, sink_index);
if (!sink) { if (!sink) {
pstream_send_error(c->pstream, tag, PA_ERROR_EXIST); pa_pstream_send_error(c->pstream, tag, PA_ERROR_EXIST);
return 0; return 0;
} }
if (!(s = playback_stream_new(c, sink, &ss, name, qlength, maxlength, prebuf))) { if (!(s = playback_stream_new(c, sink, &ss, name, qlength, maxlength, prebuf))) {
pstream_send_error(c->pstream, tag, PA_ERROR_INVALID); pa_pstream_send_error(c->pstream, tag, PA_ERROR_INVALID);
return 0; return 0;
} }
reply = tagstruct_new(NULL, 0); reply = pa_tagstruct_new(NULL, 0);
assert(reply); assert(reply);
tagstruct_putu32(reply, PA_COMMAND_REPLY); pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
tagstruct_putu32(reply, tag); pa_tagstruct_putu32(reply, tag);
tagstruct_putu32(reply, s->index); pa_tagstruct_putu32(reply, s->index);
assert(s->sink_input); assert(s->sink_input);
tagstruct_putu32(reply, s->sink_input->index); pa_tagstruct_putu32(reply, s->sink_input->index);
pstream_send_tagstruct(c->pstream, reply); pa_pstream_send_tagstruct(c->pstream, reply);
request_bytes(s); request_bytes(s);
return 0; return 0;
} }
static int command_delete_playback_stream(struct pdispatch *pd, uint32_t command, uint32_t tag, struct tagstruct *t, void *userdata) { static int command_delete_playback_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
struct connection *c = userdata; struct connection *c = userdata;
uint32_t channel; uint32_t channel;
struct playback_stream *s; struct playback_stream *s;
assert(c && t); assert(c && t);
if (tagstruct_getu32(t, &channel) < 0 || if (pa_tagstruct_getu32(t, &channel) < 0 ||
!tagstruct_eof(t)) !pa_tagstruct_eof(t))
return -1; return -1;
if (!c->authorized) { if (!c->authorized) {
pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS); pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
return 0; return 0;
} }
if (!(s = idxset_get_by_index(c->playback_streams, channel))) { if (!(s = pa_idxset_get_by_index(c->playback_streams, channel))) {
pstream_send_error(c->pstream, tag, PA_ERROR_EXIST); pa_pstream_send_error(c->pstream, tag, PA_ERROR_EXIST);
return 0; return 0;
} }
pstream_send_simple_ack(c->pstream, tag); pa_pstream_send_simple_ack(c->pstream, tag);
return 0; return 0;
} }
static int command_exit(struct pdispatch *pd, uint32_t command, uint32_t tag, struct tagstruct *t, void *userdata) { static int command_exit(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
struct connection *c = userdata; struct connection *c = userdata;
assert(c && t); assert(c && t);
if (!tagstruct_eof(t)) if (!pa_tagstruct_eof(t))
return -1; return -1;
if (!c->authorized) { if (!c->authorized) {
pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS); pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
return 0; return 0;
} }
assert(c->protocol && c->protocol->core && c->protocol->core->mainloop); assert(c->protocol && c->protocol->core && c->protocol->core->mainloop);
c->protocol->core->mainloop->quit(c->protocol->core->mainloop, 0); c->protocol->core->mainloop->quit(c->protocol->core->mainloop, 0);
pstream_send_simple_ack(c->pstream, tag); /* nonsense */ pa_pstream_send_simple_ack(c->pstream, tag); /* nonsense */
return 0; return 0;
} }
/*** pstream callbacks ***/ /*** pstream callbacks ***/
static int packet_callback(struct pstream *p, struct packet *packet, void *userdata) { static int packet_callback(struct pa_pstream *p, struct pa_packet *packet, void *userdata) {
struct connection *c = userdata; struct connection *c = userdata;
assert(p && packet && packet->data && c); assert(p && packet && packet->data && c);
if (pdispatch_run(c->pdispatch, packet, c) < 0) { if (pa_pdispatch_run(c->pdispatch, packet, c) < 0) {
fprintf(stderr, "protocol-native: invalid packet.\n"); fprintf(stderr, "protocol-native: invalid packet.\n");
return -1; return -1;
} }
@ -308,12 +308,12 @@ static int packet_callback(struct pstream *p, struct packet *packet, void *userd
return 0; return 0;
} }
static int memblock_callback(struct pstream *p, uint32_t channel, int32_t delta, struct memchunk *chunk, void *userdata) { static int memblock_callback(struct pa_pstream *p, uint32_t channel, int32_t delta, struct pa_memchunk *chunk, void *userdata) {
struct connection *c = userdata; struct connection *c = userdata;
struct playback_stream *stream; struct playback_stream *stream;
assert(p && chunk && userdata); assert(p && chunk && userdata);
if (!(stream = idxset_get_by_index(c->playback_streams, channel))) { if (!(stream = pa_idxset_get_by_index(c->playback_streams, channel))) {
fprintf(stderr, "protocol-native: client sent block for invalid stream.\n"); fprintf(stderr, "protocol-native: client sent block for invalid stream.\n");
return -1; return -1;
} }
@ -323,16 +323,16 @@ static int memblock_callback(struct pstream *p, uint32_t channel, int32_t delta,
else else
stream->requested_bytes -= chunk->length; stream->requested_bytes -= chunk->length;
memblockq_push_align(stream->memblockq, chunk, delta); pa_memblockq_push_align(stream->memblockq, chunk, delta);
assert(stream->sink_input); assert(stream->sink_input);
sink_notify(stream->sink_input->sink); pa_sink_notify(stream->sink_input->sink);
/*fprintf(stderr, "Recieved %u bytes.\n", chunk->length);*/ /*fprintf(stderr, "Recieved %u bytes.\n", chunk->length);*/
return 0; return 0;
} }
static void die_callback(struct pstream *p, void *userdata) { static void die_callback(struct pa_pstream *p, void *userdata) {
struct connection *c = userdata; struct connection *c = userdata;
assert(p && c); assert(p && c);
connection_free(c); connection_free(c);
@ -342,8 +342,8 @@ static void die_callback(struct pstream *p, void *userdata) {
/*** socket server callbacks ***/ /*** socket server callbacks ***/
static void on_connection(struct socket_server*s, struct iochannel *io, void *userdata) { static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, void *userdata) {
struct protocol_native *p = userdata; struct pa_protocol_native *p = userdata;
struct connection *c; struct connection *c;
assert(s && io && p); assert(s && io && p);
@ -352,52 +352,52 @@ static void on_connection(struct socket_server*s, struct iochannel *io, void *us
c->authorized = p->public; c->authorized = p->public;
c->protocol = p; c->protocol = p;
assert(p->core); assert(p->core);
c->client = client_new(p->core, "NATIVE", "Client"); c->client = pa_client_new(p->core, "NATIVE", "Client");
assert(c->client); assert(c->client);
c->pstream = pstream_new(p->core->mainloop, io); c->pstream = pa_pstream_new(p->core->mainloop, io);
assert(c->pstream); assert(c->pstream);
pstream_set_recieve_packet_callback(c->pstream, packet_callback, c); pa_pstream_set_recieve_packet_callback(c->pstream, packet_callback, c);
pstream_set_recieve_memblock_callback(c->pstream, memblock_callback, c); pa_pstream_set_recieve_memblock_callback(c->pstream, memblock_callback, c);
pstream_set_die_callback(c->pstream, die_callback, c); pa_pstream_set_die_callback(c->pstream, die_callback, c);
c->pdispatch = pdispatch_new(p->core->mainloop, command_table, PA_COMMAND_MAX); c->pdispatch = pa_pdispatch_new(p->core->mainloop, command_table, PA_COMMAND_MAX);
assert(c->pdispatch); assert(c->pdispatch);
c->record_streams = idxset_new(NULL, NULL); c->record_streams = pa_idxset_new(NULL, NULL);
c->playback_streams = idxset_new(NULL, NULL); c->playback_streams = pa_idxset_new(NULL, NULL);
assert(c->record_streams && c->playback_streams); assert(c->record_streams && c->playback_streams);
idxset_put(p->connections, c, NULL); pa_idxset_put(p->connections, c, NULL);
} }
/*** module entry points ***/ /*** module entry points ***/
struct protocol_native* protocol_native_new(struct core *core, struct socket_server *server) { struct pa_protocol_native* pa_protocol_native_new(struct pa_core *core, struct pa_socket_server *server) {
struct protocol_native *p; struct pa_protocol_native *p;
assert(core && server); assert(core && server);
p = malloc(sizeof(struct protocol_native)); p = malloc(sizeof(struct pa_protocol_native));
assert(p); assert(p);
p->public = 1; p->public = 1;
p->server = server; p->server = server;
p->core = core; p->core = core;
p->connections = idxset_new(NULL, NULL); p->connections = pa_idxset_new(NULL, NULL);
assert(p->connections); assert(p->connections);
socket_server_set_callback(p->server, on_connection, p); pa_socket_server_set_callback(p->server, on_connection, p);
return p; return p;
} }
void protocol_native_free(struct protocol_native *p) { void pa_protocol_native_free(struct pa_protocol_native *p) {
struct connection *c; struct connection *c;
assert(p); assert(p);
while ((c = idxset_first(p->connections, NULL))) while ((c = pa_idxset_first(p->connections, NULL)))
connection_free(c); connection_free(c);
idxset_free(p->connections, NULL, NULL); pa_idxset_free(p->connections, NULL, NULL);
socket_server_free(p->server); pa_socket_server_free(p->server);
free(p); free(p);
} }

View file

@ -4,9 +4,9 @@
#include "core.h" #include "core.h"
#include "socket-server.h" #include "socket-server.h"
struct protocol_native; struct pa_protocol_native;
struct protocol_native* protocol_native_new(struct core*core, struct socket_server *server); struct pa_protocol_native* pa_protocol_native_new(struct pa_core*core, struct pa_socket_server *server);
void protocol_native_free(struct protocol_native *n); void pa_protocol_native_free(struct pa_protocol_native *n);
#endif #endif

View file

@ -12,19 +12,19 @@
#include "sample-util.h" #include "sample-util.h"
struct connection { struct connection {
struct protocol_simple *protocol; struct pa_protocol_simple *protocol;
struct iochannel *io; struct pa_iochannel *io;
struct sink_input *sink_input; struct pa_sink_input *sink_input;
struct source_output *source_output; struct pa_source_output *source_output;
struct client *client; struct pa_client *client;
struct memblockq *input_memblockq, *output_memblockq; struct pa_memblockq *input_memblockq, *output_memblockq;
}; };
struct protocol_simple { struct pa_protocol_simple {
struct core *core; struct pa_core *core;
struct socket_server*server; struct pa_socket_server*server;
struct idxset *connections; struct pa_idxset *connections;
enum protocol_simple_mode mode; enum pa_protocol_simple_mode mode;
struct pa_sample_spec sample_spec; struct pa_sample_spec sample_spec;
}; };
@ -33,38 +33,38 @@ struct protocol_simple {
static void connection_free(struct connection *c) { static void connection_free(struct connection *c) {
assert(c); assert(c);
idxset_remove_by_data(c->protocol->connections, c, NULL); pa_idxset_remove_by_data(c->protocol->connections, c, NULL);
if (c->sink_input) if (c->sink_input)
sink_input_free(c->sink_input); pa_sink_input_free(c->sink_input);
if (c->source_output) if (c->source_output)
source_output_free(c->source_output); pa_source_output_free(c->source_output);
if (c->client) if (c->client)
client_free(c->client); pa_client_free(c->client);
if (c->io) if (c->io)
iochannel_free(c->io); pa_iochannel_free(c->io);
if (c->input_memblockq) if (c->input_memblockq)
memblockq_free(c->input_memblockq); pa_memblockq_free(c->input_memblockq);
if (c->output_memblockq) if (c->output_memblockq)
memblockq_free(c->output_memblockq); pa_memblockq_free(c->output_memblockq);
free(c); free(c);
} }
static int do_read(struct connection *c) { static int do_read(struct connection *c) {
struct memchunk chunk; struct pa_memchunk chunk;
ssize_t r; ssize_t r;
if (!iochannel_is_readable(c->io)) if (!pa_iochannel_is_readable(c->io))
return 0; return 0;
if (!c->sink_input || !memblockq_is_writable(c->input_memblockq, BUFSIZE)) if (!c->sink_input || !pa_memblockq_is_writable(c->input_memblockq, BUFSIZE))
return 0; return 0;
chunk.memblock = memblock_new(BUFSIZE); chunk.memblock = pa_memblock_new(BUFSIZE);
assert(chunk.memblock); assert(chunk.memblock);
if ((r = iochannel_read(c->io, chunk.memblock->data, BUFSIZE)) <= 0) { if ((r = pa_iochannel_read(c->io, chunk.memblock->data, BUFSIZE)) <= 0) {
fprintf(stderr, "read(): %s\n", r == 0 ? "EOF" : strerror(errno)); fprintf(stderr, "read(): %s\n", r == 0 ? "EOF" : strerror(errno));
memblock_unref(chunk.memblock); pa_memblock_unref(chunk.memblock);
return -1; return -1;
} }
@ -72,103 +72,103 @@ static int do_read(struct connection *c) {
chunk.index = 0; chunk.index = 0;
assert(c->input_memblockq); assert(c->input_memblockq);
memblockq_push_align(c->input_memblockq, &chunk, 0); pa_memblockq_push_align(c->input_memblockq, &chunk, 0);
memblock_unref(chunk.memblock); pa_memblock_unref(chunk.memblock);
assert(c->sink_input); assert(c->sink_input);
sink_notify(c->sink_input->sink); pa_sink_notify(c->sink_input->sink);
return 0; return 0;
} }
static int do_write(struct connection *c) { static int do_write(struct connection *c) {
struct memchunk chunk; struct pa_memchunk chunk;
ssize_t r; ssize_t r;
if (!iochannel_is_writable(c->io)) if (!pa_iochannel_is_writable(c->io))
return 0; return 0;
if (!c->source_output) if (!c->source_output)
return 0; return 0;
assert(c->output_memblockq); assert(c->output_memblockq);
if (memblockq_peek(c->output_memblockq, &chunk) < 0) if (pa_memblockq_peek(c->output_memblockq, &chunk) < 0)
return 0; return 0;
assert(chunk.memblock && chunk.length); assert(chunk.memblock && chunk.length);
if ((r = iochannel_write(c->io, chunk.memblock->data+chunk.index, chunk.length)) < 0) { if ((r = pa_iochannel_write(c->io, chunk.memblock->data+chunk.index, chunk.length)) < 0) {
fprintf(stderr, "write(): %s\n", strerror(errno)); fprintf(stderr, "write(): %s\n", strerror(errno));
memblock_unref(chunk.memblock); pa_memblock_unref(chunk.memblock);
return -1; return -1;
} }
memblockq_drop(c->output_memblockq, r); pa_memblockq_drop(c->output_memblockq, r);
memblock_unref(chunk.memblock); pa_memblock_unref(chunk.memblock);
return 0; return 0;
} }
/*** sink_input callbacks ***/ /*** sink_input callbacks ***/
static int sink_input_peek_cb(struct sink_input *i, struct memchunk *chunk) { static int sink_input_peek_cb(struct pa_sink_input *i, struct pa_memchunk *chunk) {
struct connection*c; struct connection*c;
assert(i && i->userdata && chunk); assert(i && i->userdata && chunk);
c = i->userdata; c = i->userdata;
if (memblockq_peek(c->input_memblockq, chunk) < 0) if (pa_memblockq_peek(c->input_memblockq, chunk) < 0)
return -1; return -1;
return 0; return 0;
} }
static void sink_input_drop_cb(struct sink_input *i, size_t length) { static void sink_input_drop_cb(struct pa_sink_input *i, size_t length) {
struct connection*c = i->userdata; struct connection*c = i->userdata;
assert(i && c && length); assert(i && c && length);
memblockq_drop(c->input_memblockq, length); pa_memblockq_drop(c->input_memblockq, length);
if (do_read(c) < 0) if (do_read(c) < 0)
connection_free(c); connection_free(c);
} }
static void sink_input_kill_cb(struct sink_input *i) { static void sink_input_kill_cb(struct pa_sink_input *i) {
assert(i && i->userdata); assert(i && i->userdata);
connection_free((struct connection *) i->userdata); connection_free((struct connection *) i->userdata);
} }
static uint32_t sink_input_get_latency_cb(struct sink_input *i) { static uint32_t sink_input_get_latency_cb(struct pa_sink_input *i) {
struct connection*c = i->userdata; struct connection*c = i->userdata;
assert(i && c); assert(i && c);
return pa_samples_usec(memblockq_get_length(c->input_memblockq), &c->sink_input->sample_spec); return pa_samples_usec(pa_memblockq_get_length(c->input_memblockq), &c->sink_input->sample_spec);
} }
/*** source_output callbacks ***/ /*** source_output callbacks ***/
static void source_output_push_cb(struct source_output *o, const struct memchunk *chunk) { static void source_output_push_cb(struct pa_source_output *o, const struct pa_memchunk *chunk) {
struct connection *c = o->userdata; struct connection *c = o->userdata;
assert(o && c && chunk); assert(o && c && chunk);
memblockq_push(c->output_memblockq, chunk, 0); pa_memblockq_push(c->output_memblockq, chunk, 0);
if (do_write(c) < 0) if (do_write(c) < 0)
connection_free(c); connection_free(c);
} }
static void source_output_kill_cb(struct source_output *o) { static void source_output_kill_cb(struct pa_source_output *o) {
assert(o && o->userdata); assert(o && o->userdata);
connection_free((struct connection *) o->userdata); connection_free((struct connection *) o->userdata);
} }
/*** client callbacks ***/ /*** client callbacks ***/
static void client_kill_cb(struct client *c) { static void client_kill_cb(struct pa_client *c) {
assert(c && c->userdata); assert(c && c->userdata);
connection_free((struct connection *) c->userdata); connection_free((struct connection *) c->userdata);
} }
/*** iochannel callbacks ***/ /*** pa_iochannel callbacks ***/
static void io_callback(struct iochannel*io, void *userdata) { static void io_callback(struct pa_iochannel*io, void *userdata) {
struct connection *c = userdata; struct connection *c = userdata;
assert(io && c && c->io == io); assert(io && c && c->io == io);
@ -178,8 +178,8 @@ static void io_callback(struct iochannel*io, void *userdata) {
/*** socket_server callbacks */ /*** socket_server callbacks */
static void on_connection(struct socket_server*s, struct iochannel *io, void *userdata) { static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, void *userdata) {
struct protocol_simple *p = userdata; struct pa_protocol_simple *p = userdata;
struct connection *c = NULL; struct connection *c = NULL;
char cname[256]; char cname[256];
assert(s && io && p); assert(s && io && p);
@ -192,41 +192,41 @@ static void on_connection(struct socket_server*s, struct iochannel *io, void *us
c->input_memblockq = c->output_memblockq = NULL; c->input_memblockq = c->output_memblockq = NULL;
c->protocol = p; c->protocol = p;
iochannel_peer_to_string(io, cname, sizeof(cname)); pa_iochannel_peer_to_string(io, cname, sizeof(cname));
c->client = client_new(p->core, "SIMPLE", cname); c->client = pa_client_new(p->core, "SIMPLE", cname);
assert(c->client); assert(c->client);
c->client->kill = client_kill_cb; c->client->kill = client_kill_cb;
c->client->userdata = c; c->client->userdata = c;
if (p->mode & PROTOCOL_SIMPLE_RECORD) { if (p->mode & PA_PROTOCOL_SIMPLE_RECORD) {
struct source *source; struct pa_source *source;
size_t l; size_t l;
if (!(source = source_get_default(p->core))) { if (!(source = pa_source_get_default(p->core))) {
fprintf(stderr, "Failed to get default source.\n"); fprintf(stderr, "Failed to get default source.\n");
goto fail; goto fail;
} }
c->source_output = source_output_new(source, c->client->name, &p->sample_spec); c->source_output = pa_source_output_new(source, c->client->name, &p->sample_spec);
assert(c->source_output); assert(c->source_output);
c->source_output->push = source_output_push_cb; c->source_output->push = source_output_push_cb;
c->source_output->kill = source_output_kill_cb; c->source_output->kill = source_output_kill_cb;
c->source_output->userdata = c; c->source_output->userdata = c;
l = 5*pa_bytes_per_second(&DEFAULT_SAMPLE_SPEC); /* 5s */ l = 5*pa_bytes_per_second(&p->sample_spec); /* 5s */
c->output_memblockq = memblockq_new(l, pa_sample_size(&p->sample_spec), l/2); c->output_memblockq = pa_memblockq_new(l, pa_sample_size(&p->sample_spec), l/2);
} }
if (p->mode & PROTOCOL_SIMPLE_PLAYBACK) { if (p->mode & PA_PROTOCOL_SIMPLE_PLAYBACK) {
struct sink *sink; struct pa_sink *sink;
size_t l; size_t l;
if (!(sink = sink_get_default(p->core))) { if (!(sink = pa_sink_get_default(p->core))) {
fprintf(stderr, "Failed to get default sink.\n"); fprintf(stderr, "Failed to get default sink.\n");
goto fail; goto fail;
} }
c->sink_input = sink_input_new(sink, c->client->name, &p->sample_spec); c->sink_input = pa_sink_input_new(sink, c->client->name, &p->sample_spec);
assert(c->sink_input); assert(c->sink_input);
c->sink_input->peek = sink_input_peek_cb; c->sink_input->peek = sink_input_peek_cb;
c->sink_input->drop = sink_input_drop_cb; c->sink_input->drop = sink_input_drop_cb;
@ -234,13 +234,13 @@ static void on_connection(struct socket_server*s, struct iochannel *io, void *us
c->sink_input->get_latency = sink_input_get_latency_cb; c->sink_input->get_latency = sink_input_get_latency_cb;
c->sink_input->userdata = c; c->sink_input->userdata = c;
l = pa_bytes_per_second(&DEFAULT_SAMPLE_SPEC)/2; /* half a second */ l = pa_bytes_per_second(&p->sample_spec)/2; /* half a second */
c->input_memblockq = memblockq_new(l, pa_sample_size(&p->sample_spec), l/2); c->input_memblockq = pa_memblockq_new(l, pa_sample_size(&p->sample_spec), l/2);
} }
iochannel_set_callback(c->io, io_callback, c); pa_iochannel_set_callback(c->io, io_callback, c);
idxset_put(p->connections, c, NULL); pa_idxset_put(p->connections, c, NULL);
return; return;
fail: fail:
@ -248,34 +248,34 @@ fail:
connection_free(c); connection_free(c);
} }
struct protocol_simple* protocol_simple_new(struct core *core, struct socket_server *server, enum protocol_simple_mode mode) { struct pa_protocol_simple* pa_protocol_simple_new(struct pa_core *core, struct pa_socket_server *server, enum pa_protocol_simple_mode mode) {
struct protocol_simple* p; struct pa_protocol_simple* p;
assert(core && server && mode <= PROTOCOL_SIMPLE_DUPLEX && mode > 0); assert(core && server && mode <= PA_PROTOCOL_SIMPLE_DUPLEX && mode > 0);
p = malloc(sizeof(struct protocol_simple)); p = malloc(sizeof(struct pa_protocol_simple));
assert(p); assert(p);
p->core = core; p->core = core;
p->server = server; p->server = server;
p->connections = idxset_new(NULL, NULL); p->connections = pa_idxset_new(NULL, NULL);
p->mode = mode; p->mode = mode;
p->sample_spec = DEFAULT_SAMPLE_SPEC; p->sample_spec = PA_DEFAULT_SAMPLE_SPEC;
socket_server_set_callback(p->server, on_connection, p); pa_socket_server_set_callback(p->server, on_connection, p);
return p; return p;
} }
void protocol_simple_free(struct protocol_simple *p) { void pa_protocol_simple_free(struct pa_protocol_simple *p) {
struct connection *c; struct connection *c;
assert(p); assert(p);
while((c = idxset_first(p->connections, NULL))) while((c = pa_idxset_first(p->connections, NULL)))
connection_free(c); connection_free(c);
idxset_free(p->connections, NULL, NULL); pa_idxset_free(p->connections, NULL, NULL);
socket_server_free(p->server); pa_socket_server_free(p->server);
free(p); free(p);
} }

View file

@ -3,15 +3,15 @@
#include "socket-server.h" #include "socket-server.h"
struct protocol_simple; struct pa_protocol_simple;
enum protocol_simple_mode { enum pa_protocol_simple_mode {
PROTOCOL_SIMPLE_RECORD = 1, PA_PROTOCOL_SIMPLE_RECORD = 1,
PROTOCOL_SIMPLE_PLAYBACK = 2, PA_PROTOCOL_SIMPLE_PLAYBACK = 2,
PROTOCOL_SIMPLE_DUPLEX = 3 PA_PROTOCOL_SIMPLE_DUPLEX = 3
}; };
struct protocol_simple* protocol_simple_new(struct core *core, struct socket_server *server, enum protocol_simple_mode mode); struct pa_protocol_simple* pa_protocol_simple_new(struct pa_core *core, struct pa_socket_server *server, enum pa_protocol_simple_mode mode);
void protocol_simple_free(struct protocol_simple *n); void pa_protocol_simple_free(struct pa_protocol_simple *n);
#endif #endif

View file

@ -3,33 +3,33 @@
#include "protocol-native-spec.h" #include "protocol-native-spec.h"
#include "pstream-util.h" #include "pstream-util.h"
void pstream_send_tagstruct(struct pstream *p, struct tagstruct *t) { void pa_pstream_send_tagstruct(struct pa_pstream *p, struct pa_tagstruct *t) {
size_t length; size_t length;
uint8_t *data; uint8_t *data;
struct packet *packet; struct pa_packet *packet;
assert(p && t); assert(p && t);
data = tagstruct_free_data(t, &length); data = pa_tagstruct_free_data(t, &length);
assert(data && length); assert(data && length);
packet = packet_new_dynamic(data, length); packet = pa_packet_new_dynamic(data, length);
assert(packet); assert(packet);
pstream_send_packet(p, packet); pa_pstream_send_packet(p, packet);
packet_unref(packet); pa_packet_unref(packet);
} }
void pstream_send_error(struct pstream *p, uint32_t tag, uint32_t error) { void pa_pstream_send_error(struct pa_pstream *p, uint32_t tag, uint32_t error) {
struct tagstruct *t = tagstruct_new(NULL, 0); struct pa_tagstruct *t = pa_tagstruct_new(NULL, 0);
assert(t); assert(t);
tagstruct_putu32(t, PA_COMMAND_ERROR); pa_tagstruct_putu32(t, PA_COMMAND_ERROR);
tagstruct_putu32(t, tag); pa_tagstruct_putu32(t, tag);
tagstruct_putu32(t, error); pa_tagstruct_putu32(t, error);
pstream_send_tagstruct(p, t); pa_pstream_send_tagstruct(p, t);
} }
void pstream_send_simple_ack(struct pstream *p, uint32_t tag) { void pa_pstream_send_simple_ack(struct pa_pstream *p, uint32_t tag) {
struct tagstruct *t = tagstruct_new(NULL, 0); struct pa_tagstruct *t = pa_tagstruct_new(NULL, 0);
assert(t); assert(t);
tagstruct_putu32(t, PA_COMMAND_REPLY); pa_tagstruct_putu32(t, PA_COMMAND_REPLY);
tagstruct_putu32(t, tag); pa_tagstruct_putu32(t, tag);
pstream_send_tagstruct(p, t); pa_pstream_send_tagstruct(p, t);
} }

View file

@ -6,9 +6,9 @@
#include "tagstruct.h" #include "tagstruct.h"
/* The tagstruct is freed!*/ /* The tagstruct is freed!*/
void pstream_send_tagstruct(struct pstream *p, struct tagstruct *t); void pa_pstream_send_tagstruct(struct pa_pstream *p, struct pa_tagstruct *t);
void pstream_send_error(struct pstream *p, uint32_t tag, uint32_t error); void pa_pstream_send_error(struct pa_pstream *p, uint32_t tag, uint32_t error);
void pstream_send_simple_ack(struct pstream *p, uint32_t tag); void pa_pstream_send_simple_ack(struct pa_pstream *p, uint32_t tag);
#endif #endif

View file

@ -5,70 +5,70 @@
#include "pstream.h" #include "pstream.h"
#include "queue.h" #include "queue.h"
enum pstream_descriptor_index { enum pa_pstream_descriptor_index {
PSTREAM_DESCRIPTOR_LENGTH, PA_PSTREAM_DESCRIPTOR_LENGTH,
PSTREAM_DESCRIPTOR_CHANNEL, PA_PSTREAM_DESCRIPTOR_CHANNEL,
PSTREAM_DESCRIPTOR_DELTA, PA_PSTREAM_DESCRIPTOR_DELTA,
PSTREAM_DESCRIPTOR_MAX PA_PSTREAM_DESCRIPTOR_MAX
}; };
typedef uint32_t pstream_descriptor[PSTREAM_DESCRIPTOR_MAX]; typedef uint32_t pa_pstream_descriptor[PA_PSTREAM_DESCRIPTOR_MAX];
#define PSTREAM_DESCRIPTOR_SIZE (PSTREAM_DESCRIPTOR_MAX*sizeof(uint32_t)) #define PA_PSTREAM_DESCRIPTOR_SIZE (PA_PSTREAM_DESCRIPTOR_MAX*sizeof(uint32_t))
#define FRAME_SIZE_MAX (1024*64) #define FRAME_SIZE_MAX (1024*64)
struct item_info { struct item_info {
enum { PSTREAM_ITEM_PACKET, PSTREAM_ITEM_MEMBLOCK } type; enum { PA_PSTREAM_ITEM_PACKET, PA_PSTREAM_ITEM_MEMBLOCK } type;
/* memblock info */ /* memblock info */
struct memchunk chunk; struct pa_memchunk chunk;
uint32_t channel; uint32_t channel;
int32_t delta; int32_t delta;
/* packet info */ /* packet info */
struct packet *packet; struct pa_packet *packet;
}; };
struct pstream { struct pa_pstream {
struct pa_mainloop_api *mainloop; struct pa_mainloop_api *mainloop;
struct mainloop_source *mainloop_source; struct mainloop_source *mainloop_source;
struct iochannel *io; struct pa_iochannel *io;
struct queue *send_queue; struct pa_queue *send_queue;
int dead; int dead;
void (*die_callback) (struct pstream *p, void *userdad); void (*die_callback) (struct pa_pstream *p, void *userdad);
void *die_callback_userdata; void *die_callback_userdata;
struct { struct {
struct item_info* current; struct item_info* current;
pstream_descriptor descriptor; pa_pstream_descriptor descriptor;
void *data; void *data;
size_t index; size_t index;
} write; } write;
void (*send_callback) (struct pstream *p, void *userdata); void (*send_callback) (struct pa_pstream *p, void *userdata);
void *send_callback_userdata; void *send_callback_userdata;
struct { struct {
struct memblock *memblock; struct pa_memblock *memblock;
struct packet *packet; struct pa_packet *packet;
pstream_descriptor descriptor; pa_pstream_descriptor descriptor;
void *data; void *data;
size_t index; size_t index;
} read; } read;
int (*recieve_packet_callback) (struct pstream *p, struct packet *packet, void *userdata); int (*recieve_packet_callback) (struct pa_pstream *p, struct pa_packet *packet, void *userdata);
void *recieve_packet_callback_userdata; void *recieve_packet_callback_userdata;
int (*recieve_memblock_callback) (struct pstream *p, uint32_t channel, int32_t delta, struct memchunk *chunk, void *userdata); int (*recieve_memblock_callback) (struct pa_pstream *p, uint32_t channel, int32_t delta, struct pa_memchunk *chunk, void *userdata);
void *recieve_memblock_callback_userdata; void *recieve_memblock_callback_userdata;
}; };
static void do_write(struct pstream *p); static void do_write(struct pa_pstream *p);
static void do_read(struct pstream *p); static void do_read(struct pa_pstream *p);
static void io_callback(struct iochannel*io, void *userdata) { static void io_callback(struct pa_iochannel*io, void *userdata) {
struct pstream *p = userdata; struct pa_pstream *p = userdata;
assert(p && p->io == io); assert(p && p->io == io);
p->mainloop->enable_fixed(p->mainloop, p->mainloop_source, 0); p->mainloop->enable_fixed(p->mainloop, p->mainloop_source, 0);
@ -78,7 +78,7 @@ static void io_callback(struct iochannel*io, void *userdata) {
} }
static void fixed_callback(struct pa_mainloop_api *m, void *id, void*userdata) { static void fixed_callback(struct pa_mainloop_api *m, void *id, void*userdata) {
struct pstream *p = userdata; struct pa_pstream *p = userdata;
assert(p && p->mainloop_source == id && p->mainloop == m); assert(p && p->mainloop_source == id && p->mainloop == m);
p->mainloop->enable_fixed(p->mainloop, p->mainloop_source, 0); p->mainloop->enable_fixed(p->mainloop, p->mainloop_source, 0);
@ -87,15 +87,15 @@ static void fixed_callback(struct pa_mainloop_api *m, void *id, void*userdata) {
do_read(p); do_read(p);
} }
struct pstream *pstream_new(struct pa_mainloop_api *m, struct iochannel *io) { struct pa_pstream *pa_pstream_new(struct pa_mainloop_api *m, struct pa_iochannel *io) {
struct pstream *p; struct pa_pstream *p;
assert(io); assert(io);
p = malloc(sizeof(struct pstream)); p = malloc(sizeof(struct pa_pstream));
assert(p); assert(p);
p->io = io; p->io = io;
iochannel_set_callback(io, io_callback, p); pa_iochannel_set_callback(io, io_callback, p);
p->dead = 0; p->dead = 0;
p->die_callback = NULL; p->die_callback = NULL;
@ -105,7 +105,7 @@ struct pstream *pstream_new(struct pa_mainloop_api *m, struct iochannel *io) {
p->mainloop_source = m->source_fixed(m, fixed_callback, p); p->mainloop_source = m->source_fixed(m, fixed_callback, p);
m->enable_fixed(m, p->mainloop_source, 0); m->enable_fixed(m, p->mainloop_source, 0);
p->send_queue = queue_new(); p->send_queue = pa_queue_new();
assert(p->send_queue); assert(p->send_queue);
p->write.current = NULL; p->write.current = NULL;
@ -131,118 +131,118 @@ static void item_free(void *item, void *p) {
struct item_info *i = item; struct item_info *i = item;
assert(i); assert(i);
if (i->type == PSTREAM_ITEM_MEMBLOCK) { if (i->type == PA_PSTREAM_ITEM_MEMBLOCK) {
assert(i->chunk.memblock); assert(i->chunk.memblock);
memblock_unref(i->chunk.memblock); pa_memblock_unref(i->chunk.memblock);
} else { } else {
assert(i->type == PSTREAM_ITEM_PACKET); assert(i->type == PA_PSTREAM_ITEM_PACKET);
assert(i->packet); assert(i->packet);
packet_unref(i->packet); pa_packet_unref(i->packet);
} }
free(i); free(i);
} }
void pstream_free(struct pstream *p) { void pa_pstream_free(struct pa_pstream *p) {
assert(p); assert(p);
iochannel_free(p->io); pa_iochannel_free(p->io);
queue_free(p->send_queue, item_free, NULL); pa_queue_free(p->send_queue, item_free, NULL);
if (p->write.current) if (p->write.current)
item_free(p->write.current, NULL); item_free(p->write.current, NULL);
if (p->read.memblock) if (p->read.memblock)
memblock_unref(p->read.memblock); pa_memblock_unref(p->read.memblock);
if (p->read.packet) if (p->read.packet)
packet_unref(p->read.packet); pa_packet_unref(p->read.packet);
p->mainloop->cancel_fixed(p->mainloop, p->mainloop_source); p->mainloop->cancel_fixed(p->mainloop, p->mainloop_source);
free(p); free(p);
} }
void pstream_set_send_callback(struct pstream*p, void (*callback) (struct pstream *p, void *userdata), void *userdata) { void pa_pstream_set_send_callback(struct pa_pstream*p, void (*callback) (struct pa_pstream *p, void *userdata), void *userdata) {
assert(p && callback); assert(p && callback);
p->send_callback = callback; p->send_callback = callback;
p->send_callback_userdata = userdata; p->send_callback_userdata = userdata;
} }
void pstream_send_packet(struct pstream*p, struct packet *packet) { void pa_pstream_send_packet(struct pa_pstream*p, struct pa_packet *packet) {
struct item_info *i; struct item_info *i;
assert(p && packet); assert(p && packet);
i = malloc(sizeof(struct item_info)); i = malloc(sizeof(struct item_info));
assert(i); assert(i);
i->type = PSTREAM_ITEM_PACKET; i->type = PA_PSTREAM_ITEM_PACKET;
i->packet = packet_ref(packet); i->packet = pa_packet_ref(packet);
queue_push(p->send_queue, i); pa_queue_push(p->send_queue, i);
p->mainloop->enable_fixed(p->mainloop, p->mainloop_source, 1); p->mainloop->enable_fixed(p->mainloop, p->mainloop_source, 1);
} }
void pstream_send_memblock(struct pstream*p, uint32_t channel, int32_t delta, struct memchunk *chunk) { void pa_pstream_send_memblock(struct pa_pstream*p, uint32_t channel, int32_t delta, struct pa_memchunk *chunk) {
struct item_info *i; struct item_info *i;
assert(p && channel != (uint32_t) -1 && chunk); assert(p && channel != (uint32_t) -1 && chunk);
i = malloc(sizeof(struct item_info)); i = malloc(sizeof(struct item_info));
assert(i); assert(i);
i->type = PSTREAM_ITEM_MEMBLOCK; i->type = PA_PSTREAM_ITEM_MEMBLOCK;
i->chunk = *chunk; i->chunk = *chunk;
i->channel = channel; i->channel = channel;
i->delta = delta; i->delta = delta;
memblock_ref(i->chunk.memblock); pa_memblock_ref(i->chunk.memblock);
queue_push(p->send_queue, i); pa_queue_push(p->send_queue, i);
p->mainloop->enable_fixed(p->mainloop, p->mainloop_source, 1); p->mainloop->enable_fixed(p->mainloop, p->mainloop_source, 1);
} }
void pstream_set_recieve_packet_callback(struct pstream *p, int (*callback) (struct pstream *p, struct packet *packet, void *userdata), void *userdata) { void pa_pstream_set_recieve_packet_callback(struct pa_pstream *p, int (*callback) (struct pa_pstream *p, struct pa_packet *packet, void *userdata), void *userdata) {
assert(p && callback); assert(p && callback);
p->recieve_packet_callback = callback; p->recieve_packet_callback = callback;
p->recieve_packet_callback_userdata = userdata; p->recieve_packet_callback_userdata = userdata;
} }
void pstream_set_recieve_memblock_callback(struct pstream *p, int (*callback) (struct pstream *p, uint32_t channel, int32_t delta, struct memchunk *chunk, void *userdata), void *userdata) { void pa_pstream_set_recieve_memblock_callback(struct pa_pstream *p, int (*callback) (struct pa_pstream *p, uint32_t channel, int32_t delta, struct pa_memchunk *chunk, void *userdata), void *userdata) {
assert(p && callback); assert(p && callback);
p->recieve_memblock_callback = callback; p->recieve_memblock_callback = callback;
p->recieve_memblock_callback_userdata = userdata; p->recieve_memblock_callback_userdata = userdata;
} }
static void prepare_next_write_item(struct pstream *p) { static void prepare_next_write_item(struct pa_pstream *p) {
assert(p); assert(p);
if (!(p->write.current = queue_pop(p->send_queue))) if (!(p->write.current = pa_queue_pop(p->send_queue)))
return; return;
p->write.index = 0; p->write.index = 0;
if (p->write.current->type == PSTREAM_ITEM_PACKET) { if (p->write.current->type == PA_PSTREAM_ITEM_PACKET) {
assert(p->write.current->packet); assert(p->write.current->packet);
p->write.data = p->write.current->packet->data; p->write.data = p->write.current->packet->data;
p->write.descriptor[PSTREAM_DESCRIPTOR_LENGTH] = htonl(p->write.current->packet->length); p->write.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH] = htonl(p->write.current->packet->length);
p->write.descriptor[PSTREAM_DESCRIPTOR_CHANNEL] = htonl((uint32_t) -1); p->write.descriptor[PA_PSTREAM_DESCRIPTOR_CHANNEL] = htonl((uint32_t) -1);
p->write.descriptor[PSTREAM_DESCRIPTOR_DELTA] = 0; p->write.descriptor[PA_PSTREAM_DESCRIPTOR_DELTA] = 0;
} else { } else {
assert(p->write.current->type == PSTREAM_ITEM_MEMBLOCK && p->write.current->chunk.memblock); assert(p->write.current->type == PA_PSTREAM_ITEM_MEMBLOCK && p->write.current->chunk.memblock);
p->write.data = p->write.current->chunk.memblock->data + p->write.current->chunk.index; p->write.data = p->write.current->chunk.memblock->data + p->write.current->chunk.index;
p->write.descriptor[PSTREAM_DESCRIPTOR_LENGTH] = htonl(p->write.current->chunk.length); p->write.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH] = htonl(p->write.current->chunk.length);
p->write.descriptor[PSTREAM_DESCRIPTOR_CHANNEL] = htonl(p->write.current->channel); p->write.descriptor[PA_PSTREAM_DESCRIPTOR_CHANNEL] = htonl(p->write.current->channel);
p->write.descriptor[PSTREAM_DESCRIPTOR_DELTA] = htonl(p->write.current->delta); p->write.descriptor[PA_PSTREAM_DESCRIPTOR_DELTA] = htonl(p->write.current->delta);
} }
} }
static void do_write(struct pstream *p) { static void do_write(struct pa_pstream *p) {
void *d; void *d;
size_t l; size_t l;
ssize_t r; ssize_t r;
assert(p); assert(p);
if (p->dead || !iochannel_is_writable(p->io)) if (p->dead || !pa_iochannel_is_writable(p->io))
return; return;
if (!p->write.current) if (!p->write.current)
@ -253,25 +253,25 @@ static void do_write(struct pstream *p) {
assert(p->write.data); assert(p->write.data);
if (p->write.index < PSTREAM_DESCRIPTOR_SIZE) { if (p->write.index < PA_PSTREAM_DESCRIPTOR_SIZE) {
d = (void*) p->write.descriptor + p->write.index; d = (void*) p->write.descriptor + p->write.index;
l = PSTREAM_DESCRIPTOR_SIZE - p->write.index; l = PA_PSTREAM_DESCRIPTOR_SIZE - p->write.index;
} else { } else {
d = (void*) p->write.data + p->write.index - PSTREAM_DESCRIPTOR_SIZE; d = (void*) p->write.data + p->write.index - PA_PSTREAM_DESCRIPTOR_SIZE;
l = ntohl(p->write.descriptor[PSTREAM_DESCRIPTOR_LENGTH]) - (p->write.index - PSTREAM_DESCRIPTOR_SIZE); l = ntohl(p->write.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH]) - (p->write.index - PA_PSTREAM_DESCRIPTOR_SIZE);
} }
if ((r = iochannel_write(p->io, d, l)) < 0) if ((r = pa_iochannel_write(p->io, d, l)) < 0)
goto die; goto die;
p->write.index += r; p->write.index += r;
if (p->write.index >= PSTREAM_DESCRIPTOR_SIZE+ntohl(p->write.descriptor[PSTREAM_DESCRIPTOR_LENGTH])) { if (p->write.index >= PA_PSTREAM_DESCRIPTOR_SIZE+ntohl(p->write.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH])) {
assert(p->write.current); assert(p->write.current);
item_free(p->write.current, (void *) 1); item_free(p->write.current, (void *) 1);
p->write.current = NULL; p->write.current = NULL;
if (p->send_callback && queue_is_empty(p->send_queue)) if (p->send_callback && pa_queue_is_empty(p->send_queue))
p->send_callback(p, p->send_callback_userdata); p->send_callback(p, p->send_callback_userdata);
} }
@ -283,68 +283,68 @@ die:
p->die_callback(p, p->die_callback_userdata); p->die_callback(p, p->die_callback_userdata);
} }
static void do_read(struct pstream *p) { static void do_read(struct pa_pstream *p) {
void *d; void *d;
size_t l; size_t l;
ssize_t r; ssize_t r;
assert(p); assert(p);
if (p->dead || !iochannel_is_readable(p->io)) if (p->dead || !pa_iochannel_is_readable(p->io))
return; return;
if (p->read.index < PSTREAM_DESCRIPTOR_SIZE) { if (p->read.index < PA_PSTREAM_DESCRIPTOR_SIZE) {
d = (void*) p->read.descriptor + p->read.index; d = (void*) p->read.descriptor + p->read.index;
l = PSTREAM_DESCRIPTOR_SIZE - p->read.index; l = PA_PSTREAM_DESCRIPTOR_SIZE - p->read.index;
} else { } else {
assert(p->read.data); assert(p->read.data);
d = (void*) p->read.data + p->read.index - PSTREAM_DESCRIPTOR_SIZE; d = (void*) p->read.data + p->read.index - PA_PSTREAM_DESCRIPTOR_SIZE;
l = ntohl(p->read.descriptor[PSTREAM_DESCRIPTOR_LENGTH]) - (p->read.index - PSTREAM_DESCRIPTOR_SIZE); l = ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH]) - (p->read.index - PA_PSTREAM_DESCRIPTOR_SIZE);
} }
if ((r = iochannel_read(p->io, d, l)) <= 0) if ((r = pa_iochannel_read(p->io, d, l)) <= 0)
goto die; goto die;
p->read.index += r; p->read.index += r;
if (p->read.index == PSTREAM_DESCRIPTOR_SIZE) { if (p->read.index == PA_PSTREAM_DESCRIPTOR_SIZE) {
/* Reading of frame descriptor complete */ /* Reading of frame descriptor complete */
/* Frame size too large */ /* Frame size too large */
if (ntohl(p->read.descriptor[PSTREAM_DESCRIPTOR_LENGTH]) > FRAME_SIZE_MAX) if (ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH]) > FRAME_SIZE_MAX)
goto die; goto die;
assert(!p->read.packet && !p->read.memblock); assert(!p->read.packet && !p->read.memblock);
if (ntohl(p->read.descriptor[PSTREAM_DESCRIPTOR_CHANNEL]) == (uint32_t) -1) { if (ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_CHANNEL]) == (uint32_t) -1) {
/* Frame is a packet frame */ /* Frame is a packet frame */
p->read.packet = packet_new(ntohl(p->read.descriptor[PSTREAM_DESCRIPTOR_LENGTH])); p->read.packet = pa_packet_new(ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH]));
assert(p->read.packet); assert(p->read.packet);
p->read.data = p->read.packet->data; p->read.data = p->read.packet->data;
} else { } else {
/* Frame is a memblock frame */ /* Frame is a memblock frame */
p->read.memblock = memblock_new(ntohl(p->read.descriptor[PSTREAM_DESCRIPTOR_LENGTH])); p->read.memblock = pa_memblock_new(ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH]));
assert(p->read.memblock); assert(p->read.memblock);
p->read.data = p->read.memblock->data; p->read.data = p->read.memblock->data;
} }
} else if (p->read.index > PSTREAM_DESCRIPTOR_SIZE) { } else if (p->read.index > PA_PSTREAM_DESCRIPTOR_SIZE) {
/* Frame payload available */ /* Frame payload available */
if (p->read.memblock && p->recieve_memblock_callback) { /* Is this memblock data? Than pass it to the user */ if (p->read.memblock && p->recieve_memblock_callback) { /* Is this memblock data? Than pass it to the user */
size_t l; size_t l;
l = (p->read.index - r) < PSTREAM_DESCRIPTOR_SIZE ? p->read.index - PSTREAM_DESCRIPTOR_SIZE : (size_t) r; l = (p->read.index - r) < PA_PSTREAM_DESCRIPTOR_SIZE ? p->read.index - PA_PSTREAM_DESCRIPTOR_SIZE : (size_t) r;
if (l > 0) { if (l > 0) {
struct memchunk chunk; struct pa_memchunk chunk;
chunk.memblock = p->read.memblock; chunk.memblock = p->read.memblock;
chunk.index = p->read.index - PSTREAM_DESCRIPTOR_SIZE - l; chunk.index = p->read.index - PA_PSTREAM_DESCRIPTOR_SIZE - l;
chunk.length = l; chunk.length = l;
if (p->recieve_memblock_callback(p, if (p->recieve_memblock_callback(p,
ntohl(p->read.descriptor[PSTREAM_DESCRIPTOR_CHANNEL]), ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_CHANNEL]),
(int32_t) ntohl(p->read.descriptor[PSTREAM_DESCRIPTOR_DELTA]), (int32_t) ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_DELTA]),
&chunk, &chunk,
p->recieve_memblock_callback_userdata) < 0) p->recieve_memblock_callback_userdata) < 0)
goto die; goto die;
@ -352,11 +352,11 @@ static void do_read(struct pstream *p) {
} }
/* Frame complete */ /* Frame complete */
if (p->read.index >= ntohl(p->read.descriptor[PSTREAM_DESCRIPTOR_LENGTH]) + PSTREAM_DESCRIPTOR_SIZE) { if (p->read.index >= ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH]) + PA_PSTREAM_DESCRIPTOR_SIZE) {
if (p->read.memblock) { if (p->read.memblock) {
assert(!p->read.packet); assert(!p->read.packet);
memblock_unref(p->read.memblock); pa_memblock_unref(p->read.memblock);
p->read.memblock = NULL; p->read.memblock = NULL;
} else { } else {
int r = 0; int r = 0;
@ -365,7 +365,7 @@ static void do_read(struct pstream *p) {
if (p->recieve_packet_callback) if (p->recieve_packet_callback)
r = p->recieve_packet_callback(p, p->read.packet, p->recieve_packet_callback_userdata); r = p->recieve_packet_callback(p, p->read.packet, p->recieve_packet_callback_userdata);
packet_unref(p->read.packet); pa_packet_unref(p->read.packet);
p->read.packet = NULL; p->read.packet = NULL;
if (r < 0) if (r < 0)
@ -385,7 +385,7 @@ die:
} }
void pstream_set_die_callback(struct pstream *p, void (*callback)(struct pstream *p, void *userdata), void *userdata) { void pa_pstream_set_die_callback(struct pa_pstream *p, void (*callback)(struct pa_pstream *p, void *userdata), void *userdata) {
assert(p && callback); assert(p && callback);
p->die_callback = callback; p->die_callback = callback;
p->die_callback_userdata = userdata; p->die_callback_userdata = userdata;

View file

@ -9,18 +9,18 @@
#include "mainloop-api.h" #include "mainloop-api.h"
#include "memchunk.h" #include "memchunk.h"
struct pstream; struct pa_pstream;
struct pstream* pstream_new(struct pa_mainloop_api *m, struct iochannel *io); struct pa_pstream* pa_pstream_new(struct pa_mainloop_api *m, struct pa_iochannel *io);
void pstream_free(struct pstream*p); void pa_pstream_free(struct pa_pstream*p);
void pstream_set_send_callback(struct pstream*p, void (*callback) (struct pstream *p, void *userdata), void *userdata); void pa_pstream_set_send_callback(struct pa_pstream*p, void (*callback) (struct pa_pstream *p, void *userdata), void *userdata);
void pstream_send_packet(struct pstream*p, struct packet *packet); void pa_pstream_send_packet(struct pa_pstream*p, struct pa_packet *packet);
void pstream_send_memblock(struct pstream*p, uint32_t channel, int32_t delta, struct memchunk *chunk); void pa_pstream_send_memblock(struct pa_pstream*p, uint32_t channel, int32_t delta, struct pa_memchunk *chunk);
void pstream_set_recieve_packet_callback(struct pstream *p, int (*callback) (struct pstream *p, struct packet *packet, void *userdata), void *userdata); void pa_pstream_set_recieve_packet_callback(struct pa_pstream *p, int (*callback) (struct pa_pstream *p, struct pa_packet *packet, void *userdata), void *userdata);
void pstream_set_recieve_memblock_callback(struct pstream *p, int (*callback) (struct pstream *p, uint32_t channel, int32_t delta, struct memchunk *chunk, void *userdata), void *userdata); void pa_pstream_set_recieve_memblock_callback(struct pa_pstream *p, int (*callback) (struct pa_pstream *p, uint32_t channel, int32_t delta, struct pa_memchunk *chunk, void *userdata), void *userdata);
void pstream_set_die_callback(struct pstream *p, void (*callback)(struct pstream *p, void *userdata), void *userdata); void pa_pstream_set_die_callback(struct pa_pstream *p, void (*callback)(struct pa_pstream *p, void *userdata), void *userdata);
#endif #endif

View file

@ -8,20 +8,20 @@ struct queue_entry {
void *data; void *data;
}; };
struct queue { struct pa_queue {
struct queue_entry *front, *back; struct queue_entry *front, *back;
unsigned length; unsigned length;
}; };
struct queue* queue_new(void) { struct pa_queue* pa_queue_new(void) {
struct queue *q = malloc(sizeof(struct queue)); struct pa_queue *q = malloc(sizeof(struct pa_queue));
assert(q); assert(q);
q->front = q->back = NULL; q->front = q->back = NULL;
q->length = 0; q->length = 0;
return q; return q;
} }
void queue_free(struct queue* q, void (*destroy)(void *p, void *userdata), void *userdata) { void pa_queue_free(struct pa_queue* q, void (*destroy)(void *p, void *userdata), void *userdata) {
struct queue_entry *e; struct queue_entry *e;
assert(q); assert(q);
@ -39,7 +39,7 @@ void queue_free(struct queue* q, void (*destroy)(void *p, void *userdata), void
free(q); free(q);
} }
void queue_push(struct queue *q, void *p) { void pa_queue_push(struct pa_queue *q, void *p) {
struct queue_entry *e; struct queue_entry *e;
e = malloc(sizeof(struct queue_entry)); e = malloc(sizeof(struct queue_entry));
@ -58,7 +58,7 @@ void queue_push(struct queue *q, void *p) {
q->length++; q->length++;
} }
void* queue_pop(struct queue *q) { void* pa_queue_pop(struct pa_queue *q) {
void *p; void *p;
struct queue_entry *e; struct queue_entry *e;
assert(q); assert(q);
@ -78,7 +78,7 @@ void* queue_pop(struct queue *q) {
return p; return p;
} }
int queue_is_empty(struct queue *q) { int pa_queue_is_empty(struct pa_queue *q) {
assert(q); assert(q);
return q->length == 0; return q->length == 0;
} }

View file

@ -1,13 +1,13 @@
#ifndef fooqueuehfoo #ifndef fooqueuehfoo
#define fooqueuehfoo #define fooqueuehfoo
struct queue; struct pa_queue;
struct queue* queue_new(void); struct pa_queue* pa_queue_new(void);
void queue_free(struct queue* q, void (*destroy)(void *p, void *userdata), void *userdata); void pa_queue_free(struct pa_queue* q, void (*destroy)(void *p, void *userdata), void *userdata);
void queue_push(struct queue *q, void *p); void pa_queue_push(struct pa_queue *q, void *p);
void* queue_pop(struct queue *q); void* pa_queue_pop(struct pa_queue *q);
int queue_is_empty(struct queue *q); int pa_queue_is_empty(struct pa_queue *q);
#endif #endif

View file

@ -6,7 +6,7 @@
#include "resampler.h" #include "resampler.h"
#include "sconv.h" #include "sconv.h"
struct resampler { struct pa_resampler {
struct pa_sample_spec i_ss, o_ss; struct pa_sample_spec i_ss, o_ss;
float* i_buf, *o_buf; float* i_buf, *o_buf;
unsigned i_alloc, o_alloc; unsigned i_alloc, o_alloc;
@ -14,13 +14,13 @@ struct resampler {
int channels; int channels;
convert_to_float32_func_t to_float32_func; pa_convert_to_float32_func_t to_float32_func;
convert_from_float32_func_t from_float32_func; pa_convert_from_float32_func_t from_float32_func;
SRC_STATE *src_state; SRC_STATE *src_state;
}; };
struct resampler* resampler_new(const struct pa_sample_spec *a, const struct pa_sample_spec *b) { struct pa_resampler* pa_resampler_new(const struct pa_sample_spec *a, const struct pa_sample_spec *b) {
struct resampler *r; struct pa_resampler *r;
int err; int err;
assert(a && b && pa_sample_spec_valid(a) && pa_sample_spec_valid(b)); assert(a && b && pa_sample_spec_valid(a) && pa_sample_spec_valid(b));
@ -30,7 +30,7 @@ struct resampler* resampler_new(const struct pa_sample_spec *a, const struct pa_
if (a->format == PA_SAMPLE_ALAW || a->format == PA_SAMPLE_ULAW || b->format == PA_SAMPLE_ALAW || b->format == PA_SAMPLE_ULAW) if (a->format == PA_SAMPLE_ALAW || a->format == PA_SAMPLE_ULAW || b->format == PA_SAMPLE_ALAW || b->format == PA_SAMPLE_ULAW)
goto fail; goto fail;
r = malloc(sizeof(struct resampler)); r = malloc(sizeof(struct pa_resampler));
assert(r); assert(r);
r->channels = a->channels; r->channels = a->channels;
@ -53,8 +53,8 @@ struct resampler* resampler_new(const struct pa_sample_spec *a, const struct pa_
r->i_sz = pa_sample_size(a); r->i_sz = pa_sample_size(a);
r->o_sz = pa_sample_size(b); r->o_sz = pa_sample_size(b);
r->to_float32_func = get_convert_to_float32_function(a->format); r->to_float32_func = pa_get_convert_to_float32_function(a->format);
r->from_float32_func = get_convert_from_float32_function(b->format); r->from_float32_func = pa_get_convert_from_float32_function(b->format);
assert(r->to_float32_func && r->from_float32_func); assert(r->to_float32_func && r->from_float32_func);
@ -67,7 +67,7 @@ fail:
return NULL; return NULL;
} }
void resampler_free(struct resampler *r) { void pa_resampler_free(struct pa_resampler *r) {
assert(r); assert(r);
if (r->src_state) if (r->src_state)
src_delete(r->src_state); src_delete(r->src_state);
@ -76,14 +76,14 @@ void resampler_free(struct resampler *r) {
free(r); free(r);
} }
size_t resampler_request(struct resampler *r, size_t out_length) { size_t pa_resampler_request(struct pa_resampler *r, size_t out_length) {
assert(r && (out_length % r->o_sz) == 0); assert(r && (out_length % r->o_sz) == 0);
return (((out_length / r->o_sz)*r->i_ss.rate)/r->o_ss.rate) * r->i_sz; return (((out_length / r->o_sz)*r->i_ss.rate)/r->o_ss.rate) * r->i_sz;
} }
void resampler_run(struct resampler *r, const struct memchunk *in, struct memchunk *out) { void pa_resampler_run(struct pa_resampler *r, const struct pa_memchunk *in, struct pa_memchunk *out) {
unsigned i_nchannels, o_nchannels, ins, ons, eff_ins, eff_ons; unsigned i_nchannels, o_nchannels, ins, ons, eff_ins, eff_ons;
float *cbuf; float *cbuf;
assert(r && in && out && in->length && in->memblock && (in->length % r->i_sz) == 0); assert(r && in && out && in->length && in->memblock && (in->length % r->i_sz) == 0);
@ -109,7 +109,7 @@ void resampler_run(struct resampler *r, const struct memchunk *in, struct memchu
eff_ons = ons; eff_ons = ons;
} }
out->memblock = memblock_new(out->length = (ons*r->o_sz)); out->memblock = pa_memblock_new(out->length = (ons*r->o_sz));
out->index = 0; out->index = 0;
assert(out->memblock); assert(out->memblock);

View file

@ -5,12 +5,12 @@
#include "memblock.h" #include "memblock.h"
#include "memchunk.h" #include "memchunk.h"
struct resampler; struct pa_resampler;
struct resampler* resampler_new(const struct pa_sample_spec *a, const struct pa_sample_spec *b); struct pa_resampler* pa_resampler_new(const struct pa_sample_spec *a, const struct pa_sample_spec *b);
void resampler_free(struct resampler *r); void pa_resampler_free(struct pa_resampler *r);
size_t resampler_request(struct resampler *r, size_t out_length); size_t pa_resampler_request(struct pa_resampler *r, size_t out_length);
void resampler_run(struct resampler *r, const struct memchunk *in, struct memchunk *out); void pa_resampler_run(struct pa_resampler *r, const struct pa_memchunk *in, struct pa_memchunk *out);
#endif #endif

View file

@ -4,26 +4,26 @@
#include "sample-util.h" #include "sample-util.h"
struct pa_sample_spec default_sample_spec = { struct pa_sample_spec pa_default_sample_spec = {
.format = PA_SAMPLE_S16NE, .format = PA_SAMPLE_S16NE,
.rate = 44100, .rate = 44100,
.channels = 2 .channels = 2
}; };
struct memblock *silence_memblock(struct memblock* b, struct pa_sample_spec *spec) { struct pa_memblock *pa_silence_memblock(struct pa_memblock* b, const struct pa_sample_spec *spec) {
assert(b && b->data && spec); assert(b && b->data && spec);
memblock_assert_exclusive(b); pa_memblock_assert_exclusive(b);
silence_memory(b->data, b->length, spec); pa_silence_memory(b->data, b->length, spec);
return b; return b;
} }
void silence_memchunk(struct memchunk *c, struct pa_sample_spec *spec) { void pa_silence_memchunk(struct pa_memchunk *c, const struct pa_sample_spec *spec) {
assert(c && c->memblock && c->memblock->data && spec && c->length); assert(c && c->memblock && c->memblock->data && spec && c->length);
memblock_assert_exclusive(c->memblock); pa_memblock_assert_exclusive(c->memblock);
silence_memory(c->memblock->data+c->index, c->length, spec); pa_silence_memory(c->memblock->data+c->index, c->length, spec);
} }
void silence_memory(void *p, size_t length, struct pa_sample_spec *spec) { void pa_silence_memory(void *p, size_t length, const struct pa_sample_spec *spec) {
char c = 0; char c = 0;
assert(p && length && spec); assert(p && length && spec);
@ -47,7 +47,7 @@ void silence_memory(void *p, size_t length, struct pa_sample_spec *spec) {
memset(p, c, length); memset(p, c, length);
} }
size_t mix_chunks(struct mix_info channels[], unsigned nchannels, void *data, size_t length, struct pa_sample_spec *spec, uint32_t volume) { size_t pa_mix(struct pa_mix_info channels[], unsigned nchannels, void *data, size_t length, const struct pa_sample_spec *spec, uint32_t volume) {
unsigned c, d; unsigned c, d;
assert(channels && data && length && spec); assert(channels && data && length && spec);
assert(spec->format == PA_SAMPLE_S16NE); assert(spec->format == PA_SAMPLE_S16NE);
@ -65,22 +65,22 @@ size_t mix_chunks(struct mix_info channels[], unsigned nchannels, void *data, si
if (d >= channels[c].chunk.length) if (d >= channels[c].chunk.length)
return d; return d;
if (volume == VOLUME_MUTE) if (volume == PA_VOLUME_MUTE)
v = 0; v = 0;
else { else {
v = *((int16_t*) (channels[c].chunk.memblock->data + channels[c].chunk.index + d)); v = *((int16_t*) (channels[c].chunk.memblock->data + channels[c].chunk.index + d));
if (volume != VOLUME_NORM) if (volume != PA_VOLUME_NORM)
v = (int32_t) ((float)v*volume/VOLUME_NORM); v = (int32_t) ((float)v*volume/PA_VOLUME_NORM);
} }
sum += v; sum += v;
} }
if (volume == VOLUME_MUTE) if (volume == PA_VOLUME_MUTE)
sum = 0; sum = 0;
else if (volume != VOLUME_NORM) else if (volume != PA_VOLUME_NORM)
sum = (int32_t) ((float) sum*volume/VOLUME_NORM); sum = (int32_t) ((float) sum*volume/PA_VOLUME_NORM);
if (sum < -0x8000) sum = -0x8000; if (sum < -0x8000) sum = -0x8000;
if (sum > 0x7FFF) sum = 0x7FFF; if (sum > 0x7FFF) sum = 0x7FFF;
@ -91,18 +91,18 @@ size_t mix_chunks(struct mix_info channels[], unsigned nchannels, void *data, si
} }
void volume_memchunk(struct memchunk*c, struct pa_sample_spec *spec, uint32_t volume) { void pa_volume_memchunk(struct pa_memchunk*c, const struct pa_sample_spec *spec, uint32_t volume) {
int16_t *d; int16_t *d;
size_t n; size_t n;
assert(c && spec && (c->length % pa_sample_size(spec) == 0)); assert(c && spec && (c->length % pa_sample_size(spec) == 0));
assert(spec->format == PA_SAMPLE_S16NE); assert(spec->format == PA_SAMPLE_S16NE);
memblock_assert_exclusive(c->memblock); pa_memblock_assert_exclusive(c->memblock);
if (volume == VOLUME_NORM) if (volume == PA_VOLUME_NORM)
return; return;
if (volume == VOLUME_MUTE) { if (volume == PA_VOLUME_MUTE) {
silence_memchunk(c, spec); pa_silence_memchunk(c, spec);
return; return;
} }
@ -110,7 +110,7 @@ void volume_memchunk(struct memchunk*c, struct pa_sample_spec *spec, uint32_t vo
int32_t t = (int32_t)(*d); int32_t t = (int32_t)(*d);
t *= volume; t *= volume;
t /= VOLUME_NORM; t /= PA_VOLUME_NORM;
if (t < -0x8000) t = -0x8000; if (t < -0x8000) t = -0x8000;
if (t > 0x7FFF) t = 0x7FFF; if (t > 0x7FFF) t = 0x7FFF;
@ -119,10 +119,10 @@ void volume_memchunk(struct memchunk*c, struct pa_sample_spec *spec, uint32_t vo
} }
} }
uint32_t volume_multiply(uint32_t a, uint32_t b) { uint32_t pa_volume_multiply(uint32_t a, uint32_t b) {
uint64_t p = a; uint64_t p = a;
p *= b; p *= b;
p /= VOLUME_NORM; p /= PA_VOLUME_NORM;
return (uint32_t) p; return (uint32_t) p;
} }

View file

@ -5,27 +5,27 @@
#include "memblock.h" #include "memblock.h"
#include "memchunk.h" #include "memchunk.h"
#define DEFAULT_SAMPLE_SPEC default_sample_spec #define PA_DEFAULT_SAMPLE_SPEC pa_default_sample_spec
extern struct pa_sample_spec default_sample_spec; extern struct pa_sample_spec pa_default_sample_spec;
#define VOLUME_NORM (0x100) #define PA_VOLUME_NORM (0x100)
#define VOLUME_MUTE (0) #define PA_VOLUME_MUTE (0)
struct memblock *silence_memblock(struct memblock* b, struct pa_sample_spec *spec); struct pa_memblock *pa_silence_memblock(struct pa_memblock* b, const struct pa_sample_spec *spec);
void silence_memchunk(struct memchunk *c, struct pa_sample_spec *spec); void pa_silence_memchunk(struct pa_memchunk *c, const struct pa_sample_spec *spec);
void silence_memory(void *p, size_t length, struct pa_sample_spec *spec); void pa_silence_memory(void *p, size_t length, const struct pa_sample_spec *spec);
struct mix_info { struct pa_mix_info {
struct memchunk chunk; struct pa_memchunk chunk;
uint32_t volume; uint32_t volume;
void *userdata; void *userdata;
}; };
size_t mix_chunks(struct mix_info channels[], unsigned nchannels, void *data, size_t length, struct pa_sample_spec *spec, uint32_t volume); size_t pa_mix(struct pa_mix_info channels[], unsigned nchannels, void *data, size_t length, const struct pa_sample_spec *spec, uint32_t volume);
void volume_memchunk(struct memchunk*c, struct pa_sample_spec *spec, uint32_t volume); void pa_volume_memchunk(struct pa_memchunk*c, const struct pa_sample_spec *spec, uint32_t volume);
uint32_t volume_multiply(uint32_t a, uint32_t b); uint32_t pa_volume_multiply(uint32_t a, uint32_t b);
#endif #endif

View file

@ -1,3 +1,4 @@
#include <stdio.h>
#include <assert.h> #include <assert.h>
#include "sample.h" #include "sample.h"
@ -44,7 +45,7 @@ int pa_sample_spec_valid(const struct pa_sample_spec *spec) {
if (!spec->rate || !spec->channels) if (!spec->rate || !spec->channels)
return 0; return 0;
if (spec->format <= 0 || spec->format >= PA_SAMPLE_MAX) if (spec->format >= PA_SAMPLE_MAX)
return 0; return 0;
return 1; return 1;
@ -55,3 +56,17 @@ int pa_sample_spec_equal(const struct pa_sample_spec*a, const struct pa_sample_s
return (a->format == b->format) && (a->rate == b->rate) && (a->channels == b->channels); return (a->format == b->format) && (a->rate == b->rate) && (a->channels == b->channels);
} }
void pa_sample_snprint(char *s, size_t l, const struct pa_sample_spec *spec) {
static const char* const table[]= {
[PA_SAMPLE_U8] = "U8",
[PA_SAMPLE_ALAW] = "ALAW",
[PA_SAMPLE_ULAW] = "ULAW",
[PA_SAMPLE_S16LE] = "S16LE",
[PA_SAMPLE_S16BE] = "S16BE",
[PA_SAMPLE_FLOAT32] = "FLOAT32",
};
assert(pa_sample_spec_valid(spec));
snprintf(s, l, "%s %uch %uHz", table[spec->format], spec->channels, spec->rate);
}

View file

@ -32,4 +32,6 @@ uint32_t pa_samples_usec(size_t length, const struct pa_sample_spec *spec);
int pa_sample_spec_valid(const struct pa_sample_spec *spec); int pa_sample_spec_valid(const struct pa_sample_spec *spec);
int pa_sample_spec_equal(const struct pa_sample_spec*a, const struct pa_sample_spec*b); int pa_sample_spec_equal(const struct pa_sample_spec*a, const struct pa_sample_spec*b);
void pa_sample_snprint(char *s, size_t l, const struct pa_sample_spec *spec);
#endif #endif

9
src/sconv-s16be.c Normal file
View file

@ -0,0 +1,9 @@
#include "sconv-s16be.h"
#define INT16_FROM INT16_FROM_BE
#define INT16_TO INT16_TO_BE
#define pa_sconv_s16le_to_float32 pa_sconv_s16be_to_float32
#define pa_sconv_s16le_from_float32 pa_sconv_s16be_from_float32
#include "sconv-s16le.c"

7
src/sconv-s16be.h Normal file
View file

@ -0,0 +1,7 @@
#ifndef foosconv_s16befoo
#define foosconv_s16befoo
void pa_sconv_s16be_to_float32(unsigned n, const void *a, unsigned an, float *b);
void pa_sconv_s16be_from_float32(unsigned n, const float *a, void *b, unsigned bn);
#endif

57
src/sconv-s16le.c Normal file
View file

@ -0,0 +1,57 @@
#include <assert.h>
#include <inttypes.h>
#include "endianmacros.h"
#include "sconv.h"
#ifndef INT16_FROM
#define INT16_FROM INT16_FROM_LE
#endif
#ifndef INT16_TO
#define INT16_TO INT16_TO_LE
#endif
void pa_sconv_s16le_to_float32(unsigned n, const void *a, unsigned an, float *b) {
const int16_t *ca = a;
assert(n && a && an && b);
for (; n > 0; n--) {
unsigned i;
float sum = 0;
for (i = 0; i < an; i++) {
int16_t s = *(ca++);
sum += ((float) INT16_FROM(s))/0x7FFF;
}
if (sum > 1)
sum = 1;
if (sum < -1)
sum = -1;
*(b++) = sum;
}
}
void pa_sconv_s16le_from_float32(unsigned n, const float *a, void *b, unsigned bn) {
int16_t *cb = b;
assert(n && a && b && bn);
for (; n > 0; n--) {
unsigned i;
int16_t s;
float v = *(a++);
if (v > 1)
v = 1;
if (v < -1)
v = -1;
s = (int16_t) (v * 0x7FFF);
s = INT16_TO(s);
for (i = 0; i < bn; i++)
*(cb++) = s;
}
}

7
src/sconv-s16le.h Normal file
View file

@ -0,0 +1,7 @@
#ifndef foosconv_s16lefoo
#define foosconv_s16lefoo
void pa_sconv_s16le_to_float32(unsigned n, const void *a, unsigned an, float *b);
void pa_sconv_s16le_from_float32(unsigned n, const float *a, void *b, unsigned bn);
#endif

View file

@ -1,19 +1,23 @@
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include "endianmacros.h" #include "endianmacros.h"
#include "sconv.h" #include "sconv.h"
static void s16le_to_float32(unsigned n, const void *a, unsigned an, float *b) { #include "sconv-s16le.h"
const int16_t *ca = a; #include "sconv-s16be.h"
static void u8_to_float32(unsigned n, const void *a, unsigned an, float *b) {
unsigned i;
const uint8_t *ca = a;
assert(n && a && an && b); assert(n && a && an && b);
for (; n > 0; n--) { for (; n > 0; n--) {
unsigned i;
float sum = 0; float sum = 0;
for (i = 0; i < an; i++) { for (i = 0; i < an; i++) {
int16_t s = *(ca++); uint8_t v = *(ca++);
sum += ((float) INT16_FROM_LE(s))/0x7FFF; sum += (((float) v)-127)/127;
} }
if (sum > 1) if (sum > 1)
@ -25,24 +29,25 @@ static void s16le_to_float32(unsigned n, const void *a, unsigned an, float *b) {
} }
} }
static void s16le_from_float32(unsigned n, const float *a, void *b, unsigned bn) { static void u8_from_float32(unsigned n, const float *a, void *b, unsigned bn) {
int16_t *cb = b;
assert(n && a && b && bn);
for (; n > 0; n--) {
unsigned i; unsigned i;
int16_t s; uint8_t *cb = b;
assert(n && a && b && bn);
for (; n > 0; n--) {
float v = *(a++); float v = *(a++);
uint8_t u;
if (v > 1) if (v > 1)
v = 1; v = 1;
if (v < -1) if (v < -1)
v = -1; v = -1;
s = (int16_t) (v * 0x7FFF); u = (uint8_t) (v*127+127);
for (i = 0; i < bn; i++) for (i = 0; i < bn; i++)
*(cb++) = INT16_TO_LE(v); *(cb++) = u;
} }
} }
@ -76,10 +81,14 @@ static void float32_from_float32(unsigned n, const float *a, void *b, unsigned b
} }
} }
convert_to_float32_func_t get_convert_to_float32_function(enum pa_sample_format f) { pa_convert_to_float32_func_t pa_get_convert_to_float32_function(enum pa_sample_format f) {
switch(f) { switch(f) {
case PA_SAMPLE_U8:
return u8_to_float32;
case PA_SAMPLE_S16LE: case PA_SAMPLE_S16LE:
return s16le_to_float32; return pa_sconv_s16le_to_float32;
case PA_SAMPLE_S16BE:
return pa_sconv_s16be_to_float32;
case PA_SAMPLE_FLOAT32: case PA_SAMPLE_FLOAT32:
return float32_to_float32; return float32_to_float32;
default: default:
@ -87,10 +96,14 @@ convert_to_float32_func_t get_convert_to_float32_function(enum pa_sample_format
} }
} }
convert_from_float32_func_t get_convert_from_float32_function(enum pa_sample_format f) { pa_convert_from_float32_func_t pa_get_convert_from_float32_function(enum pa_sample_format f) {
switch(f) { switch(f) {
case PA_SAMPLE_U8:
return u8_from_float32;
case PA_SAMPLE_S16LE: case PA_SAMPLE_S16LE:
return s16le_from_float32; return pa_sconv_s16le_from_float32;
case PA_SAMPLE_S16BE:
return pa_sconv_s16be_from_float32;
case PA_SAMPLE_FLOAT32: case PA_SAMPLE_FLOAT32:
return float32_from_float32; return float32_from_float32;
default: default:

View file

@ -3,12 +3,10 @@
#include "sample.h" #include "sample.h"
typedef void (*convert_to_float32_func_t)(unsigned n, const void *a, unsigned an, float *b); typedef void (*pa_convert_to_float32_func_t)(unsigned n, const void *a, unsigned an, float *b);
typedef void (*convert_from_float32_func_t)(unsigned n, const float *a, void *b, unsigned bn); typedef void (*pa_convert_from_float32_func_t)(unsigned n, const float *a, void *b, unsigned bn);
convert_to_float32_func_t get_convert_to_float32_function(enum pa_sample_format f);
convert_from_float32_func_t get_convert_from_float32_function(enum pa_sample_format f);
pa_convert_to_float32_func_t pa_get_convert_to_float32_function(enum pa_sample_format f);
pa_convert_from_float32_func_t pa_get_convert_from_float32_function(enum pa_sample_format f);
#endif #endif

View file

@ -11,16 +11,17 @@
#define MAX_MIX_CHANNELS 32 #define MAX_MIX_CHANNELS 32
struct sink* sink_new(struct core *core, const char *name, int fail, const struct pa_sample_spec *spec) { struct pa_sink* pa_sink_new(struct pa_core *core, const char *name, int fail, const struct pa_sample_spec *spec) {
struct sink *s; struct pa_sink *s;
char *n = NULL; char *n = NULL;
char st[256];
int r; int r;
assert(core && spec); assert(core && spec);
s = malloc(sizeof(struct sink)); s = malloc(sizeof(struct pa_sink));
assert(s); assert(s);
if (!(name = namereg_register(core, name, NAMEREG_SINK, s, fail))) { if (!(name = pa_namereg_register(core, name, PA_NAMEREG_SINK, s, fail))) {
free(s); free(s);
return NULL; return NULL;
} }
@ -28,46 +29,47 @@ struct sink* sink_new(struct core *core, const char *name, int fail, const struc
s->name = strdup(name); s->name = strdup(name);
s->core = core; s->core = core;
s->sample_spec = *spec; s->sample_spec = *spec;
s->inputs = idxset_new(NULL, NULL); s->inputs = pa_idxset_new(NULL, NULL);
if (name) { if (name) {
n = malloc(strlen(name)+9); n = malloc(strlen(name)+9);
sprintf(n, "%s_monitor", name); sprintf(n, "%s_monitor", name);
} }
s->monitor_source = source_new(core, n, 0, spec); s->monitor_source = pa_source_new(core, n, 0, spec);
assert(s->monitor_source); assert(s->monitor_source);
free(n); free(n);
s->volume = VOLUME_NORM; s->volume = PA_VOLUME_NORM;
s->notify = NULL; s->notify = NULL;
s->get_latency = NULL; s->get_latency = NULL;
s->userdata = NULL; s->userdata = NULL;
r = idxset_put(core->sinks, s, &s->index); r = pa_idxset_put(core->sinks, s, &s->index);
assert(s->index != IDXSET_INVALID && r >= 0); assert(s->index != PA_IDXSET_INVALID && r >= 0);
fprintf(stderr, "sink: created %u \"%s\".\n", s->index, s->name); pa_sample_snprint(st, sizeof(st), spec);
fprintf(stderr, "sink: created %u \"%s\" with sample spec \"%s\"\n", s->index, s->name, st);
return s; return s;
} }
void sink_free(struct sink *s) { void pa_sink_free(struct pa_sink *s) {
struct sink_input *i, *j = NULL; struct pa_sink_input *i, *j = NULL;
assert(s); assert(s);
namereg_unregister(s->core, s->name); pa_namereg_unregister(s->core, s->name);
while ((i = idxset_first(s->inputs, NULL))) { while ((i = pa_idxset_first(s->inputs, NULL))) {
assert(i != j); assert(i != j);
sink_input_kill(i); pa_sink_input_kill(i);
j = i; j = i;
} }
idxset_free(s->inputs, NULL, NULL); pa_idxset_free(s->inputs, NULL, NULL);
source_free(s->monitor_source); pa_source_free(s->monitor_source);
idxset_remove_by_data(s->core->sinks, s, NULL); pa_idxset_remove_by_data(s->core->sinks, s, NULL);
fprintf(stderr, "sink: freed %u \"%s\"\n", s->index, s->name); fprintf(stderr, "sink: freed %u \"%s\"\n", s->index, s->name);
@ -75,22 +77,22 @@ void sink_free(struct sink *s) {
free(s); free(s);
} }
void sink_notify(struct sink*s) { void pa_sink_notify(struct pa_sink*s) {
assert(s); assert(s);
if (s->notify) if (s->notify)
s->notify(s); s->notify(s);
} }
static unsigned fill_mix_info(struct sink *s, struct mix_info *info, unsigned maxinfo) { static unsigned fill_mix_info(struct pa_sink *s, struct pa_mix_info *info, unsigned maxinfo) {
uint32_t index = IDXSET_INVALID; uint32_t index = PA_IDXSET_INVALID;
struct sink_input *i; struct pa_sink_input *i;
unsigned n = 0; unsigned n = 0;
assert(s && info); assert(s && info);
for (i = idxset_first(s->inputs, &index); maxinfo > 0 && i; i = idxset_next(s->inputs, &index)) { for (i = pa_idxset_first(s->inputs, &index); maxinfo > 0 && i; i = pa_idxset_next(s->inputs, &index)) {
if (sink_input_peek(i, &info->chunk) < 0) if (pa_sink_input_peek(i, &info->chunk) < 0)
continue; continue;
info->volume = i->volume; info->volume = i->volume;
@ -106,20 +108,20 @@ static unsigned fill_mix_info(struct sink *s, struct mix_info *info, unsigned ma
return n; return n;
} }
static void inputs_drop(struct sink *s, struct mix_info *info, unsigned maxinfo, size_t length) { static void inputs_drop(struct pa_sink *s, struct pa_mix_info *info, unsigned maxinfo, size_t length) {
assert(s && info); assert(s && info);
for (; maxinfo > 0; maxinfo--, info++) { for (; maxinfo > 0; maxinfo--, info++) {
struct sink_input *i = info->userdata; struct pa_sink_input *i = info->userdata;
assert(i && info->chunk.memblock); assert(i && info->chunk.memblock);
memblock_unref(info->chunk.memblock); pa_memblock_unref(info->chunk.memblock);
sink_input_drop(i, length); pa_sink_input_drop(i, length);
} }
} }
int sink_render(struct sink*s, size_t length, struct memchunk *result) { int pa_sink_render(struct pa_sink*s, size_t length, struct pa_memchunk *result) {
struct mix_info info[MAX_MIX_CHANNELS]; struct pa_mix_info info[MAX_MIX_CHANNELS];
unsigned n; unsigned n;
size_t l; size_t l;
assert(s && length && result); assert(s && length && result);
@ -130,29 +132,29 @@ int sink_render(struct sink*s, size_t length, struct memchunk *result) {
return -1; return -1;
if (n == 1) { if (n == 1) {
uint32_t volume = VOLUME_NORM; uint32_t volume = PA_VOLUME_NORM;
struct sink_info *i = info[0].userdata; struct pa_sink_input *i = info[0].userdata;
assert(i); assert(i);
*result = info[0].chunk; *result = info[0].chunk;
memblock_ref(result->memblock); pa_memblock_ref(result->memblock);
if (result->length > length) if (result->length > length)
result->length = length; result->length = length;
l = result->length; l = result->length;
if (s->volume != VOLUME_NORM || info[0].volume != VOLUME_NORM) if (s->volume != PA_VOLUME_NORM || info[0].volume != PA_VOLUME_NORM)
volume = volume_multiply(s->volume, info[0].volume); volume = pa_volume_multiply(s->volume, info[0].volume);
if (volume != VOLUME_NORM) { if (volume != PA_VOLUME_NORM) {
memchunk_make_writable(result); pa_memchunk_make_writable(result);
volume_memchunk(result, &s->sample_spec, volume); pa_volume_memchunk(result, &s->sample_spec, volume);
} }
} else { } else {
result->memblock = memblock_new(length); result->memblock = pa_memblock_new(length);
assert(result->memblock); assert(result->memblock);
result->length = l = mix_chunks(info, n, result->memblock->data, length, &s->sample_spec, s->volume); result->length = l = pa_mix(info, n, result->memblock->data, length, &s->sample_spec, s->volume);
result->index = 0; result->index = 0;
assert(l); assert(l);
@ -161,17 +163,17 @@ int sink_render(struct sink*s, size_t length, struct memchunk *result) {
inputs_drop(s, info, n, l); inputs_drop(s, info, n, l);
assert(s->monitor_source); assert(s->monitor_source);
source_post(s->monitor_source, result); pa_source_post(s->monitor_source, result);
return 0; return 0;
} }
int sink_render_into(struct sink*s, struct memchunk *target) { int pa_sink_render_into(struct pa_sink*s, struct pa_memchunk *target) {
struct mix_info info[MAX_MIX_CHANNELS]; struct pa_mix_info info[MAX_MIX_CHANNELS];
unsigned n; unsigned n;
size_t l; size_t l;
assert(s && target && target->length && target->memblock && target->memblock->data); assert(s && target && target->length && target->memblock && target->memblock->data);
memblock_assert_exclusive(target->memblock); pa_memblock_assert_exclusive(target->memblock);
n = fill_mix_info(s, info, MAX_MIX_CHANNELS); n = fill_mix_info(s, info, MAX_MIX_CHANNELS);
@ -179,8 +181,8 @@ int sink_render_into(struct sink*s, struct memchunk *target) {
return -1; return -1;
if (n == 1) { if (n == 1) {
uint32_t volume = VOLUME_NORM; uint32_t volume = PA_VOLUME_NORM;
struct sink_info *i = info[0].userdata; struct pa_sink_info *i = info[0].userdata;
assert(i); assert(i);
l = target->length; l = target->length;
@ -190,25 +192,25 @@ int sink_render_into(struct sink*s, struct memchunk *target) {
memcpy(target->memblock->data+target->index, info[0].chunk.memblock->data + info[0].chunk.index, l); memcpy(target->memblock->data+target->index, info[0].chunk.memblock->data + info[0].chunk.index, l);
target->length = l; target->length = l;
if (s->volume != VOLUME_NORM || info[0].volume != VOLUME_NORM) if (s->volume != PA_VOLUME_NORM || info[0].volume != PA_VOLUME_NORM)
volume = volume_multiply(s->volume, info[0].volume); volume = pa_volume_multiply(s->volume, info[0].volume);
if (volume != VOLUME_NORM) if (volume != PA_VOLUME_NORM)
volume_memchunk(target, &s->sample_spec, volume); pa_volume_memchunk(target, &s->sample_spec, volume);
} else } else
target->length = l = mix_chunks(info, n, target->memblock->data+target->index, target->length, &s->sample_spec, s->volume); target->length = l = pa_mix(info, n, target->memblock->data+target->index, target->length, &s->sample_spec, s->volume);
assert(l); assert(l);
inputs_drop(s, info, n, l); inputs_drop(s, info, n, l);
assert(s->monitor_source); assert(s->monitor_source);
source_post(s->monitor_source, target); pa_source_post(s->monitor_source, target);
return 0; return 0;
} }
void sink_render_into_full(struct sink *s, struct memchunk *target) { void pa_sink_render_into_full(struct pa_sink *s, struct pa_memchunk *target) {
struct memchunk chunk; struct pa_memchunk chunk;
size_t l, d; size_t l, d;
assert(s && target && target->memblock && target->length && target->memblock->data); assert(s && target && target->memblock && target->length && target->memblock->data);
@ -219,7 +221,7 @@ void sink_render_into_full(struct sink *s, struct memchunk *target) {
chunk.index += d; chunk.index += d;
chunk.length -= d; chunk.length -= d;
if (sink_render_into(s, &chunk) < 0) if (pa_sink_render_into(s, &chunk) < 0)
break; break;
d += chunk.length; d += chunk.length;
@ -230,11 +232,11 @@ void sink_render_into_full(struct sink *s, struct memchunk *target) {
chunk = *target; chunk = *target;
chunk.index += d; chunk.index += d;
chunk.length -= d; chunk.length -= d;
silence_memchunk(&chunk, &s->sample_spec); pa_silence_memchunk(&chunk, &s->sample_spec);
} }
} }
uint32_t sink_get_latency(struct sink *s) { uint32_t pa_sink_get_latency(struct pa_sink *s) {
assert(s); assert(s);
if (!s->get_latency) if (!s->get_latency)
@ -243,38 +245,38 @@ uint32_t sink_get_latency(struct sink *s) {
return s->get_latency(s); return s->get_latency(s);
} }
struct sink* sink_get_default(struct core *c) { struct pa_sink* pa_sink_get_default(struct pa_core *c) {
struct sink *sink; struct pa_sink *sink;
assert(c); assert(c);
if ((sink = idxset_get_by_index(c->sinks, c->default_sink_index))) if ((sink = pa_idxset_get_by_index(c->sinks, c->default_sink_index)))
return sink; return sink;
if (!(sink = idxset_first(c->sinks, &c->default_sink_index))) if (!(sink = pa_idxset_first(c->sinks, &c->default_sink_index)))
return NULL; return NULL;
fprintf(stderr, "core: default sink vanished, setting to %u.\n", sink->index); fprintf(stderr, "core: default sink vanished, setting to %u.\n", sink->index);
return sink; return sink;
} }
char *sink_list_to_string(struct core *c) { char *pa_sink_list_to_string(struct pa_core *c) {
struct strbuf *s; struct pa_strbuf *s;
struct sink *sink, *default_sink; struct pa_sink *sink, *default_sink;
uint32_t index = IDXSET_INVALID; uint32_t index = PA_IDXSET_INVALID;
assert(c); assert(c);
s = strbuf_new(); s = pa_strbuf_new();
assert(s); assert(s);
strbuf_printf(s, "%u sink(s) available.\n", idxset_ncontents(c->sinks)); pa_strbuf_printf(s, "%u sink(s) available.\n", pa_idxset_ncontents(c->sinks));
default_sink = sink_get_default(c); default_sink = pa_sink_get_default(c);
for (sink = idxset_first(c->sinks, &index); sink; sink = idxset_next(c->sinks, &index)) { for (sink = pa_idxset_first(c->sinks, &index); sink; sink = pa_idxset_next(c->sinks, &index)) {
assert(sink->monitor_source); assert(sink->monitor_source);
strbuf_printf(s, " %c index: %u, name: <%s>, volume: <0x%04x>, latency: <%u usec>, monitor_source: <%u>\n", sink == default_sink ? '*' : ' ', sink->index, sink->name, (unsigned) sink->volume, sink_get_latency(sink), sink->monitor_source->index); pa_strbuf_printf(s, " %c index: %u, name: <%s>, volume: <0x%04x>, latency: <%u usec>, monitor_source: <%u>\n", sink == default_sink ? '*' : ' ', sink->index, sink->name, (unsigned) sink->volume, pa_sink_get_latency(sink), sink->monitor_source->index);
} }
return strbuf_tostring_free(s); return pa_strbuf_tostring_free(s);
} }

View file

@ -1,7 +1,7 @@
#ifndef foosinkhfoo #ifndef foosinkhfoo
#define foosinkhfoo #define foosinkhfoo
struct sink; struct pa_sink;
#include <inttypes.h> #include <inttypes.h>
@ -10,37 +10,37 @@ struct sink;
#include "idxset.h" #include "idxset.h"
#include "source.h" #include "source.h"
struct sink { struct pa_sink {
uint32_t index; uint32_t index;
char *name; char *name;
struct core *core; struct pa_core *core;
struct pa_sample_spec sample_spec; struct pa_sample_spec sample_spec;
struct idxset *inputs; struct pa_idxset *inputs;
struct source *monitor_source; struct pa_source *monitor_source;
uint32_t volume; uint32_t volume;
void (*notify)(struct sink*sink); void (*notify)(struct pa_sink*sink);
uint32_t (*get_latency)(struct sink *s); uint32_t (*get_latency)(struct pa_sink *s);
void *userdata; void *userdata;
}; };
struct sink* sink_new(struct core *core, const char *name, int fail, const struct pa_sample_spec *spec); struct pa_sink* pa_sink_new(struct pa_core *core, const char *name, int fail, const struct pa_sample_spec *spec);
void sink_free(struct sink* s); void pa_sink_free(struct pa_sink* s);
int sink_render(struct sink*s, size_t length, struct memchunk *result); int pa_sink_render(struct pa_sink*s, size_t length, struct pa_memchunk *result);
int sink_render_into(struct sink*s, struct memchunk *target); int pa_sink_render_into(struct pa_sink*s, struct pa_memchunk *target);
void sink_render_into_full(struct sink *s, struct memchunk *target); void pa_sink_render_into_full(struct pa_sink *s, struct pa_memchunk *target);
uint32_t sink_get_latency(struct sink *s); uint32_t pa_sink_get_latency(struct pa_sink *s);
void sink_notify(struct sink*s); void pa_sink_notify(struct pa_sink*s);
char *sink_list_to_string(struct core *core); char *pa_sink_list_to_string(struct pa_core *core);
struct sink* sink_get_default(struct core *c); struct pa_sink* pa_sink_get_default(struct pa_core *c);

View file

@ -1,3 +1,4 @@
#include <stdio.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -8,17 +9,18 @@
#define CONVERT_BUFFER_LENGTH 4096 #define CONVERT_BUFFER_LENGTH 4096
struct sink_input* sink_input_new(struct sink *s, const char *name, const struct pa_sample_spec *spec) { struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, const struct pa_sample_spec *spec) {
struct sink_input *i; struct pa_sink_input *i;
struct resampler *resampler = NULL; struct pa_resampler *resampler = NULL;
int r; int r;
char st[256];
assert(s && spec); assert(s && spec);
if (!pa_sample_spec_equal(spec, &s->sample_spec)) if (!pa_sample_spec_equal(spec, &s->sample_spec))
if (!(resampler = resampler_new(spec, &s->sample_spec))) if (!(resampler = pa_resampler_new(spec, &s->sample_spec)))
return NULL; return NULL;
i = malloc(sizeof(struct sink_input)); i = malloc(sizeof(struct pa_sink_input));
assert(i); assert(i);
i->name = name ? strdup(name) : NULL; i->name = name ? strdup(name) : NULL;
i->sink = s; i->sink = s;
@ -30,69 +32,72 @@ struct sink_input* sink_input_new(struct sink *s, const char *name, const struct
i->get_latency = NULL; i->get_latency = NULL;
i->userdata = NULL; i->userdata = NULL;
i->volume = VOLUME_NORM; i->volume = PA_VOLUME_NORM;
i->resampled_chunk.memblock = NULL; i->resampled_chunk.memblock = NULL;
i->resampled_chunk.index = i->resampled_chunk.length = 0; i->resampled_chunk.index = i->resampled_chunk.length = 0;
i->resampler = resampler; i->resampler = resampler;
assert(s->core); assert(s->core);
r = idxset_put(s->core->sink_inputs, i, &i->index); r = pa_idxset_put(s->core->sink_inputs, i, &i->index);
assert(r == 0 && i->index != IDXSET_INVALID); assert(r == 0 && i->index != PA_IDXSET_INVALID);
r = idxset_put(s->inputs, i, NULL); r = pa_idxset_put(s->inputs, i, NULL);
assert(r == 0); assert(r == 0);
pa_sample_snprint(st, sizeof(st), spec);
fprintf(stderr, "sink-input: created %u \"%s\" on %u with sample spec \"%s\"\n", i->index, i->name, s->index, st);
return i; return i;
} }
void sink_input_free(struct sink_input* i) { void pa_sink_input_free(struct pa_sink_input* i) {
assert(i); assert(i);
assert(i->sink && i->sink->core); assert(i->sink && i->sink->core);
idxset_remove_by_data(i->sink->core->sink_inputs, i, NULL); pa_idxset_remove_by_data(i->sink->core->sink_inputs, i, NULL);
idxset_remove_by_data(i->sink->inputs, i, NULL); pa_idxset_remove_by_data(i->sink->inputs, i, NULL);
if (i->resampled_chunk.memblock) if (i->resampled_chunk.memblock)
memblock_unref(i->resampled_chunk.memblock); pa_memblock_unref(i->resampled_chunk.memblock);
if (i->resampler) if (i->resampler)
resampler_free(i->resampler); pa_resampler_free(i->resampler);
free(i->name); free(i->name);
free(i); free(i);
} }
void sink_input_kill(struct sink_input*i) { void pa_sink_input_kill(struct pa_sink_input*i) {
assert(i); assert(i);
if (i->kill) if (i->kill)
i->kill(i); i->kill(i);
} }
char *sink_input_list_to_string(struct core *c) { char *pa_sink_input_list_to_string(struct pa_core *c) {
struct strbuf *s; struct pa_strbuf *s;
struct sink_input *i; struct pa_sink_input *i;
uint32_t index = IDXSET_INVALID; uint32_t index = PA_IDXSET_INVALID;
assert(c); assert(c);
s = strbuf_new(); s = pa_strbuf_new();
assert(s); assert(s);
strbuf_printf(s, "%u sink input(s) available.\n", idxset_ncontents(c->sink_inputs)); pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_ncontents(c->sink_inputs));
for (i = idxset_first(c->sink_inputs, &index); i; i = idxset_next(c->sink_inputs, &index)) { for (i = pa_idxset_first(c->sink_inputs, &index); i; i = pa_idxset_next(c->sink_inputs, &index)) {
assert(i->sink); assert(i->sink);
strbuf_printf(s, " index: %u, name: <%s>, sink: <%u>; volume: <0x%04x>, latency: <%u usec>\n", pa_strbuf_printf(s, " index: %u, name: <%s>, sink: <%u>; volume: <0x%04x>, latency: <%u usec>\n",
i->index, i->index,
i->name, i->name,
i->sink->index, i->sink->index,
(unsigned) i->volume, (unsigned) i->volume,
sink_input_get_latency(i)); pa_sink_input_get_latency(i));
} }
return strbuf_tostring_free(s); return pa_strbuf_tostring_free(s);
} }
uint32_t sink_input_get_latency(struct sink_input *i) { uint32_t pa_sink_input_get_latency(struct pa_sink_input *i) {
uint32_t l = 0; uint32_t l = 0;
assert(i); assert(i);
@ -100,43 +105,43 @@ uint32_t sink_input_get_latency(struct sink_input *i) {
l += i->get_latency(i); l += i->get_latency(i);
assert(i->sink); assert(i->sink);
l += sink_get_latency(i->sink); l += pa_sink_get_latency(i->sink);
return l; return l;
} }
int sink_input_peek(struct sink_input *i, struct memchunk *chunk) { int pa_sink_input_peek(struct pa_sink_input *i, struct pa_memchunk *chunk) {
assert(i && chunk && i->peek && i->drop); assert(i && chunk && i->peek && i->drop);
if (!i->resampler) if (!i->resampler)
return i->peek(i, chunk); return i->peek(i, chunk);
if (!i->resampled_chunk.memblock) { if (!i->resampled_chunk.memblock) {
struct memchunk tchunk; struct pa_memchunk tchunk;
size_t l; size_t l;
int ret; int ret;
if ((ret = i->peek(i, &tchunk)) < 0) if ((ret = i->peek(i, &tchunk)) < 0)
return ret; return ret;
l = resampler_request(i->resampler, CONVERT_BUFFER_LENGTH); l = pa_resampler_request(i->resampler, CONVERT_BUFFER_LENGTH);
if (tchunk.length > l) if (tchunk.length > l)
tchunk.length = l; tchunk.length = l;
i->drop(i, tchunk.length); i->drop(i, tchunk.length);
resampler_run(i->resampler, &tchunk, &i->resampled_chunk); pa_resampler_run(i->resampler, &tchunk, &i->resampled_chunk);
memblock_unref(tchunk.memblock); pa_memblock_unref(tchunk.memblock);
} }
assert(i->resampled_chunk.memblock && i->resampled_chunk.length); assert(i->resampled_chunk.memblock && i->resampled_chunk.length);
*chunk = i->resampled_chunk; *chunk = i->resampled_chunk;
memblock_ref(i->resampled_chunk.memblock); pa_memblock_ref(i->resampled_chunk.memblock);
return 0; return 0;
} }
void sink_input_drop(struct sink_input *i, size_t length) { void pa_sink_input_drop(struct pa_sink_input *i, size_t length) {
assert(i && length); assert(i && length);
if (!i->resampler) { if (!i->resampler) {
@ -150,7 +155,7 @@ void sink_input_drop(struct sink_input *i, size_t length) {
i->resampled_chunk.length -= length; i->resampled_chunk.length -= length;
if (!i->resampled_chunk.length) { if (!i->resampled_chunk.length) {
memblock_unref(i->resampled_chunk.memblock); pa_memblock_unref(i->resampled_chunk.memblock);
i->resampled_chunk.memblock = NULL; i->resampled_chunk.memblock = NULL;
i->resampled_chunk.index = i->resampled_chunk.length = 0; i->resampled_chunk.index = i->resampled_chunk.length = 0;
} }

View file

@ -8,36 +8,36 @@
#include "memblockq.h" #include "memblockq.h"
#include "resampler.h" #include "resampler.h"
struct sink_input { struct pa_sink_input {
uint32_t index; uint32_t index;
char *name; char *name;
struct sink *sink; struct pa_sink *sink;
struct pa_sample_spec sample_spec; struct pa_sample_spec sample_spec;
uint32_t volume; uint32_t volume;
int (*peek) (struct sink_input *i, struct memchunk *chunk); int (*peek) (struct pa_sink_input *i, struct pa_memchunk *chunk);
void (*drop) (struct sink_input *i, size_t length); void (*drop) (struct pa_sink_input *i, size_t length);
void (*kill) (struct sink_input *i); void (*kill) (struct pa_sink_input *i);
uint32_t (*get_latency) (struct sink_input *i); uint32_t (*get_latency) (struct pa_sink_input *i);
void *userdata; void *userdata;
struct memchunk resampled_chunk; struct pa_memchunk resampled_chunk;
struct resampler *resampler; struct pa_resampler *resampler;
}; };
struct sink_input* sink_input_new(struct sink *s, const char *name, const struct pa_sample_spec *spec); struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, const struct pa_sample_spec *spec);
void sink_input_free(struct sink_input* i); void pa_sink_input_free(struct pa_sink_input* i);
/* Code that didn't create the input stream should call this function to /* Code that didn't create the input stream should call this function to
* request destruction of it */ * request destruction of it */
void sink_input_kill(struct sink_input *i); void pa_sink_input_kill(struct pa_sink_input *i);
uint32_t sink_input_get_latency(struct sink_input *i); uint32_t pa_sink_input_get_latency(struct pa_sink_input *i);
char *sink_input_list_to_string(struct core *c); char *pa_sink_input_list_to_string(struct pa_core *c);
int sink_input_peek(struct sink_input *i, struct memchunk *chunk); int pa_sink_input_peek(struct pa_sink_input *i, struct pa_memchunk *chunk);
void sink_input_drop(struct sink_input *i, size_t length); void pa_sink_input_drop(struct pa_sink_input *i, size_t length);
#endif #endif

View file

@ -11,20 +11,20 @@
#include "socket-client.h" #include "socket-client.h"
#include "util.h" #include "util.h"
struct socket_client { struct pa_socket_client {
struct pa_mainloop_api *mainloop; struct pa_mainloop_api *mainloop;
int fd; int fd;
void *io_source, *fixed_source; void *io_source, *fixed_source;
void (*callback)(struct socket_client*c, struct iochannel *io, void *userdata); void (*callback)(struct pa_socket_client*c, struct pa_iochannel *io, void *userdata);
void *userdata; void *userdata;
}; };
static struct socket_client*socket_client_new(struct pa_mainloop_api *m) { static struct pa_socket_client*pa_socket_client_new(struct pa_mainloop_api *m) {
struct socket_client *c; struct pa_socket_client *c;
assert(m); assert(m);
c = malloc(sizeof(struct socket_client)); c = malloc(sizeof(struct pa_socket_client));
assert(c); assert(c);
c->mainloop = m; c->mainloop = m;
c->fd = -1; c->fd = -1;
@ -34,8 +34,8 @@ static struct socket_client*socket_client_new(struct pa_mainloop_api *m) {
return c; return c;
} }
static void do_call(struct socket_client *c) { static void do_call(struct pa_socket_client *c) {
struct iochannel *io; struct pa_iochannel *io;
int error, lerror; int error, lerror;
assert(c && c->callback); assert(c && c->callback);
@ -55,7 +55,7 @@ static void do_call(struct socket_client *c) {
goto failed; goto failed;
} }
io = iochannel_new(c->mainloop, c->fd, c->fd); io = pa_iochannel_new(c->mainloop, c->fd, c->fd);
assert(io); assert(io);
c->fd = -1; c->fd = -1;
c->callback(c, io, c->userdata); c->callback(c, io, c->userdata);
@ -70,7 +70,7 @@ failed:
} }
static void connect_fixed_cb(struct pa_mainloop_api *m, void *id, void *userdata) { static void connect_fixed_cb(struct pa_mainloop_api *m, void *id, void *userdata) {
struct socket_client *c = userdata; struct pa_socket_client *c = userdata;
assert(m && c && c->fixed_source == id); assert(m && c && c->fixed_source == id);
m->cancel_fixed(m, c->fixed_source); m->cancel_fixed(m, c->fixed_source);
c->fixed_source = NULL; c->fixed_source = NULL;
@ -78,18 +78,18 @@ static void connect_fixed_cb(struct pa_mainloop_api *m, void *id, void *userdata
} }
static void connect_io_cb(struct pa_mainloop_api*m, void *id, int fd, enum pa_mainloop_api_io_events events, void *userdata) { static void connect_io_cb(struct pa_mainloop_api*m, void *id, int fd, enum pa_mainloop_api_io_events events, void *userdata) {
struct socket_client *c = userdata; struct pa_socket_client *c = userdata;
assert(m && c && c->io_source == id && fd >= 0 && events == PA_MAINLOOP_API_IO_EVENT_OUTPUT); assert(m && c && c->io_source == id && fd >= 0 && events == PA_MAINLOOP_API_IO_EVENT_OUTPUT);
m->cancel_io(m, c->io_source); m->cancel_io(m, c->io_source);
c->io_source = NULL; c->io_source = NULL;
do_call(c); do_call(c);
} }
static int do_connect(struct socket_client *c, const struct sockaddr *sa, socklen_t len) { static int do_connect(struct pa_socket_client *c, const struct sockaddr *sa, socklen_t len) {
int r; int r;
assert(c && sa && len); assert(c && sa && len);
make_nonblock_fd(c->fd); pa_make_nonblock_fd(c->fd);
if ((r = connect(c->fd, sa, len)) < 0) { if ((r = connect(c->fd, sa, len)) < 0) {
if (r != EINPROGRESS) { if (r != EINPROGRESS) {
@ -107,12 +107,12 @@ static int do_connect(struct socket_client *c, const struct sockaddr *sa, sockle
return 0; return 0;
} }
struct socket_client* socket_client_new_ipv4(struct pa_mainloop_api *m, uint32_t address, uint16_t port) { struct pa_socket_client* pa_socket_client_new_ipv4(struct pa_mainloop_api *m, uint32_t address, uint16_t port) {
struct socket_client *c; struct pa_socket_client *c;
struct sockaddr_in sa; struct sockaddr_in sa;
assert(m && address && port); assert(m && address && port);
c = socket_client_new(m); c = pa_socket_client_new(m);
assert(c); assert(c);
if ((c->fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { if ((c->fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
@ -120,7 +120,7 @@ struct socket_client* socket_client_new_ipv4(struct pa_mainloop_api *m, uint32_t
goto fail; goto fail;
} }
make_tcp_socket_low_delay(c->fd); pa_make_tcp_socket_low_delay(c->fd);
sa.sin_family = AF_INET; sa.sin_family = AF_INET;
sa.sin_port = htons(port); sa.sin_port = htons(port);
@ -132,16 +132,16 @@ struct socket_client* socket_client_new_ipv4(struct pa_mainloop_api *m, uint32_t
return c; return c;
fail: fail:
socket_client_free(c); pa_socket_client_free(c);
return NULL; return NULL;
} }
struct socket_client* socket_client_new_unix(struct pa_mainloop_api *m, const char *filename) { struct pa_socket_client* pa_socket_client_new_unix(struct pa_mainloop_api *m, const char *filename) {
struct socket_client *c; struct pa_socket_client *c;
struct sockaddr_un sa; struct sockaddr_un sa;
assert(m && filename); assert(m && filename);
c = socket_client_new(m); c = pa_socket_client_new(m);
assert(c); assert(c);
if ((c->fd = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) { if ((c->fd = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) {
@ -149,7 +149,7 @@ struct socket_client* socket_client_new_unix(struct pa_mainloop_api *m, const ch
goto fail; goto fail;
} }
make_socket_low_delay(c->fd); pa_make_socket_low_delay(c->fd);
sa.sun_family = AF_LOCAL; sa.sun_family = AF_LOCAL;
strncpy(sa.sun_path, filename, sizeof(sa.sun_path)-1); strncpy(sa.sun_path, filename, sizeof(sa.sun_path)-1);
@ -161,11 +161,11 @@ struct socket_client* socket_client_new_unix(struct pa_mainloop_api *m, const ch
return c; return c;
fail: fail:
socket_client_free(c); pa_socket_client_free(c);
return NULL; return NULL;
} }
void socket_client_free(struct socket_client *c) { void pa_socket_client_free(struct pa_socket_client *c) {
assert(c && c->mainloop); assert(c && c->mainloop);
if (c->io_source) if (c->io_source)
c->mainloop->cancel_io(c->mainloop, c->io_source); c->mainloop->cancel_io(c->mainloop, c->io_source);
@ -176,7 +176,7 @@ void socket_client_free(struct socket_client *c) {
free(c); free(c);
} }
void socket_client_set_callback(struct socket_client *c, void (*on_connection)(struct socket_client *c, struct iochannel*io, void *userdata), void *userdata) { void pa_socket_client_set_callback(struct pa_socket_client *c, void (*on_connection)(struct pa_socket_client *c, struct pa_iochannel*io, void *userdata), void *userdata) {
assert(c); assert(c);
c->callback = on_connection; c->callback = on_connection;
c->userdata = userdata; c->userdata = userdata;

View file

@ -5,13 +5,13 @@
#include "mainloop-api.h" #include "mainloop-api.h"
#include "iochannel.h" #include "iochannel.h"
struct socket_client; struct pa_socket_client;
struct socket_client* socket_client_new_ipv4(struct pa_mainloop_api *m, uint32_t address, uint16_t port); struct pa_socket_client* pa_socket_client_new_ipv4(struct pa_mainloop_api *m, uint32_t address, uint16_t port);
struct socket_client* socket_client_new_unix(struct pa_mainloop_api *m, const char *filename); struct pa_socket_client* pa_socket_client_new_unix(struct pa_mainloop_api *m, const char *filename);
void socket_client_free(struct socket_client *c); void pa_socket_client_free(struct pa_socket_client *c);
void socket_client_set_callback(struct socket_client *c, void (*on_connection)(struct socket_client *c, struct iochannel*io, void *userdata), void *userdata); void pa_socket_client_set_callback(struct pa_socket_client *c, void (*on_connection)(struct pa_socket_client *c, struct pa_iochannel*io, void *userdata), void *userdata);
#endif #endif

View file

@ -13,20 +13,21 @@
#include "socket-server.h" #include "socket-server.h"
#include "util.h" #include "util.h"
struct socket_server { struct pa_socket_server {
int fd; int fd;
char *filename; char *filename;
void (*on_connection)(struct socket_server*s, struct iochannel *io, void *userdata); void (*on_connection)(struct pa_socket_server*s, struct pa_iochannel *io, void *userdata);
void *userdata; void *userdata;
void *mainloop_source; void *mainloop_source;
struct pa_mainloop_api *mainloop; struct pa_mainloop_api *mainloop;
enum { SOCKET_SERVER_GENERIC, SOCKET_SERVER_IPV4, SOCKET_SERVER_UNIX } type;
}; };
static void callback(struct pa_mainloop_api *mainloop, void *id, int fd, enum pa_mainloop_api_io_events events, void *userdata) { static void callback(struct pa_mainloop_api *mainloop, void *id, int fd, enum pa_mainloop_api_io_events events, void *userdata) {
struct socket_server *s = userdata; struct pa_socket_server *s = userdata;
struct iochannel *io; struct pa_iochannel *io;
int nfd; int nfd;
assert(s && s->mainloop == mainloop && s->mainloop_source == id && id && fd >= 0 && fd == s->fd && events == PA_MAINLOOP_API_IO_EVENT_INPUT); assert(s && s->mainloop == mainloop && s->mainloop_source == id && id && fd >= 0 && fd == s->fd && events == PA_MAINLOOP_API_IO_EVENT_INPUT);
@ -41,18 +42,21 @@ static void callback(struct pa_mainloop_api *mainloop, void *id, int fd, enum pa
} }
/* There should be a check for socket type here */ /* There should be a check for socket type here */
make_tcp_socket_low_delay(fd); if (s->type == SOCKET_SERVER_IPV4)
pa_make_tcp_socket_low_delay(fd);
else
pa_make_socket_low_delay(fd);
io = iochannel_new(s->mainloop, nfd, nfd); io = pa_iochannel_new(s->mainloop, nfd, nfd);
assert(io); assert(io);
s->on_connection(s, io, s->userdata); s->on_connection(s, io, s->userdata);
} }
struct socket_server* socket_server_new(struct pa_mainloop_api *m, int fd) { struct pa_socket_server* pa_socket_server_new(struct pa_mainloop_api *m, int fd) {
struct socket_server *s; struct pa_socket_server *s;
assert(m && fd >= 0); assert(m && fd >= 0);
s = malloc(sizeof(struct socket_server)); s = malloc(sizeof(struct pa_socket_server));
assert(s); assert(s);
s->fd = fd; s->fd = fd;
s->filename = NULL; s->filename = NULL;
@ -63,13 +67,15 @@ struct socket_server* socket_server_new(struct pa_mainloop_api *m, int fd) {
s->mainloop_source = m->source_io(m, fd, PA_MAINLOOP_API_IO_EVENT_INPUT, callback, s); s->mainloop_source = m->source_io(m, fd, PA_MAINLOOP_API_IO_EVENT_INPUT, callback, s);
assert(s->mainloop_source); assert(s->mainloop_source);
s->type = SOCKET_SERVER_GENERIC;
return s; return s;
} }
struct socket_server* socket_server_new_unix(struct pa_mainloop_api *m, const char *filename) { struct pa_socket_server* pa_socket_server_new_unix(struct pa_mainloop_api *m, const char *filename) {
int fd = -1; int fd = -1;
struct sockaddr_un sa; struct sockaddr_un sa;
struct socket_server *s; struct pa_socket_server *s;
assert(m && filename); assert(m && filename);
@ -82,7 +88,7 @@ struct socket_server* socket_server_new_unix(struct pa_mainloop_api *m, const ch
strncpy(sa.sun_path, filename, sizeof(sa.sun_path)-1); strncpy(sa.sun_path, filename, sizeof(sa.sun_path)-1);
sa.sun_path[sizeof(sa.sun_path) - 1] = 0; sa.sun_path[sizeof(sa.sun_path) - 1] = 0;
make_socket_low_delay(fd); pa_make_socket_low_delay(fd);
if (bind(fd, (struct sockaddr*) &sa, SUN_LEN(&sa)) < 0) { if (bind(fd, (struct sockaddr*) &sa, SUN_LEN(&sa)) < 0) {
fprintf(stderr, "bind(): %s\n", strerror(errno)); fprintf(stderr, "bind(): %s\n", strerror(errno));
@ -94,12 +100,14 @@ struct socket_server* socket_server_new_unix(struct pa_mainloop_api *m, const ch
goto fail; goto fail;
} }
s = socket_server_new(m, fd); s = pa_socket_server_new(m, fd);
assert(s); assert(s);
s->filename = strdup(filename); s->filename = strdup(filename);
assert(s->filename); assert(s->filename);
s->type = SOCKET_SERVER_UNIX;
return s; return s;
fail: fail:
@ -109,7 +117,8 @@ fail:
return NULL; return NULL;
} }
struct socket_server* socket_server_new_ipv4(struct pa_mainloop_api *m, uint32_t address, uint16_t port) { struct pa_socket_server* pa_socket_server_new_ipv4(struct pa_mainloop_api *m, uint32_t address, uint16_t port) {
struct pa_socket_server *ss;
int fd = -1; int fd = -1;
struct sockaddr_in sa; struct sockaddr_in sa;
int on = 1; int on = 1;
@ -124,7 +133,7 @@ struct socket_server* socket_server_new_ipv4(struct pa_mainloop_api *m, uint32_t
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
fprintf(stderr, "setsockopt(): %s\n", strerror(errno)); fprintf(stderr, "setsockopt(): %s\n", strerror(errno));
make_tcp_socket_low_delay(fd); pa_make_tcp_socket_low_delay(fd);
sa.sin_family = AF_INET; sa.sin_family = AF_INET;
sa.sin_port = htons(port); sa.sin_port = htons(port);
@ -140,7 +149,10 @@ struct socket_server* socket_server_new_ipv4(struct pa_mainloop_api *m, uint32_t
goto fail; goto fail;
} }
return socket_server_new(m, fd); if ((ss = pa_socket_server_new(m, fd)))
ss->type = SOCKET_SERVER_IPV4;
return ss;
fail: fail:
if (fd >= 0) if (fd >= 0)
@ -149,7 +161,7 @@ fail:
return NULL; return NULL;
} }
void socket_server_free(struct socket_server*s) { void pa_socket_server_free(struct pa_socket_server*s) {
assert(s); assert(s);
close(s->fd); close(s->fd);
@ -164,7 +176,7 @@ void socket_server_free(struct socket_server*s) {
free(s); free(s);
} }
void socket_server_set_callback(struct socket_server*s, void (*on_connection)(struct socket_server*s, struct iochannel *io, void *userdata), void *userdata) { void pa_socket_server_set_callback(struct pa_socket_server*s, void (*on_connection)(struct pa_socket_server*s, struct pa_iochannel *io, void *userdata), void *userdata) {
assert(s); assert(s);
s->on_connection = on_connection; s->on_connection = on_connection;

View file

@ -5,14 +5,14 @@
#include "mainloop-api.h" #include "mainloop-api.h"
#include "iochannel.h" #include "iochannel.h"
struct socket_server; struct pa_socket_server;
struct socket_server* socket_server_new(struct pa_mainloop_api *m, int fd); struct pa_socket_server* pa_socket_server_new(struct pa_mainloop_api *m, int fd);
struct socket_server* socket_server_new_unix(struct pa_mainloop_api *m, const char *filename); struct pa_socket_server* pa_socket_server_new_unix(struct pa_mainloop_api *m, const char *filename);
struct socket_server* socket_server_new_ipv4(struct pa_mainloop_api *m, uint32_t address, uint16_t port); struct pa_socket_server* pa_socket_server_new_ipv4(struct pa_mainloop_api *m, uint32_t address, uint16_t port);
void socket_server_free(struct socket_server*s); void pa_socket_server_free(struct pa_socket_server*s);
void socket_server_set_callback(struct socket_server*s, void (*on_connection)(struct socket_server*s, struct iochannel *io, void *userdata), void *userdata); void pa_socket_server_set_callback(struct pa_socket_server*s, void (*on_connection)(struct pa_socket_server*s, struct pa_iochannel *io, void *userdata), void *userdata);
#endif #endif

View file

@ -8,15 +8,16 @@
#include "strbuf.h" #include "strbuf.h"
#include "namereg.h" #include "namereg.h"
struct source* source_new(struct core *core, const char *name, int fail, const struct pa_sample_spec *spec) { struct pa_source* pa_source_new(struct pa_core *core, const char *name, int fail, const struct pa_sample_spec *spec) {
struct source *s; struct pa_source *s;
char st[256];
int r; int r;
assert(core && spec); assert(core && spec);
s = malloc(sizeof(struct source)); s = malloc(sizeof(struct pa_source));
assert(s); assert(s);
if (!(name = namereg_register(core, name, NAMEREG_SOURCE, s, fail))) { if (!(name = pa_namereg_register(core, name, PA_NAMEREG_SOURCE, s, fail))) {
free(s); free(s);
return NULL; return NULL;
} }
@ -24,33 +25,34 @@ struct source* source_new(struct core *core, const char *name, int fail, const s
s->name = strdup(name); s->name = strdup(name);
s->core = core; s->core = core;
s->sample_spec = *spec; s->sample_spec = *spec;
s->outputs = idxset_new(NULL, NULL); s->outputs = pa_idxset_new(NULL, NULL);
s->notify = NULL; s->notify = NULL;
s->userdata = NULL; s->userdata = NULL;
r = idxset_put(core->sources, s, &s->index); r = pa_idxset_put(core->sources, s, &s->index);
assert(s->index != IDXSET_INVALID && r >= 0); assert(s->index != PA_IDXSET_INVALID && r >= 0);
fprintf(stderr, "source: created %u \"%s\"\n", s->index, s->name); pa_sample_snprint(st, sizeof(st), spec);
fprintf(stderr, "source: created %u \"%s\" with sample spec \"%s\"\n", s->index, s->name, st);
return s; return s;
} }
void source_free(struct source *s) { void pa_source_free(struct pa_source *s) {
struct source_output *o, *j = NULL; struct pa_source_output *o, *j = NULL;
assert(s); assert(s);
namereg_unregister(s->core, s->name); pa_namereg_unregister(s->core, s->name);
while ((o = idxset_first(s->outputs, NULL))) { while ((o = pa_idxset_first(s->outputs, NULL))) {
assert(o != j); assert(o != j);
source_output_kill(o); pa_source_output_kill(o);
j = o; j = o;
} }
idxset_free(s->outputs, NULL, NULL); pa_idxset_free(s->outputs, NULL, NULL);
idxset_remove_by_data(s->core->sources, s, NULL); pa_idxset_remove_by_data(s->core->sources, s, NULL);
fprintf(stderr, "source: freed %u \"%s\"\n", s->index, s->name); fprintf(stderr, "source: freed %u \"%s\"\n", s->index, s->name);
@ -58,7 +60,7 @@ void source_free(struct source *s) {
free(s); free(s);
} }
void source_notify(struct source*s) { void pa_source_notify(struct pa_source*s) {
assert(s); assert(s);
if (s->notify) if (s->notify)
@ -66,50 +68,50 @@ void source_notify(struct source*s) {
} }
static int do_post(void *p, uint32_t index, int *del, void*userdata) { static int do_post(void *p, uint32_t index, int *del, void*userdata) {
struct memchunk *chunk = userdata; struct pa_memchunk *chunk = userdata;
struct source_output *o = p; struct pa_source_output *o = p;
assert(o && o->push && del && chunk); assert(o && o->push && del && chunk);
source_output_push(o, chunk); pa_source_output_push(o, chunk);
return 0; return 0;
} }
void source_post(struct source*s, struct memchunk *chunk) { void pa_source_post(struct pa_source*s, struct pa_memchunk *chunk) {
assert(s && chunk); assert(s && chunk);
idxset_foreach(s->outputs, do_post, chunk); pa_idxset_foreach(s->outputs, do_post, chunk);
} }
struct source* source_get_default(struct core *c) { struct pa_source* pa_source_get_default(struct pa_core *c) {
struct source *source; struct pa_source *source;
assert(c); assert(c);
if ((source = idxset_get_by_index(c->sources, c->default_source_index))) if ((source = pa_idxset_get_by_index(c->sources, c->default_source_index)))
return source; return source;
if (!(source = idxset_first(c->sources, &c->default_source_index))) if (!(source = pa_idxset_first(c->sources, &c->default_source_index)))
return NULL; return NULL;
fprintf(stderr, "core: default source vanished, setting to %u.\n", source->index); fprintf(stderr, "core: default source vanished, setting to %u.\n", source->index);
return source; return source;
} }
char *source_list_to_string(struct core *c) { char *pa_source_list_to_string(struct pa_core *c) {
struct strbuf *s; struct pa_strbuf *s;
struct source *source, *default_source; struct pa_source *source, *default_source;
uint32_t index = IDXSET_INVALID; uint32_t index = PA_IDXSET_INVALID;
assert(c); assert(c);
s = strbuf_new(); s = pa_strbuf_new();
assert(s); assert(s);
strbuf_printf(s, "%u source(s) available.\n", idxset_ncontents(c->sources)); pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_ncontents(c->sources));
default_source = source_get_default(c); default_source = pa_source_get_default(c);
for (source = idxset_first(c->sources, &index); source; source = idxset_next(c->sources, &index)) for (source = pa_idxset_first(c->sources, &index); source; source = pa_idxset_next(c->sources, &index))
strbuf_printf(s, " %c index: %u, name: <%s>\n", source == default_source ? '*' : ' ', source->index, source->name); pa_strbuf_printf(s, " %c index: %u, name: <%s>\n", source == default_source ? '*' : ' ', source->index, source->name);
return strbuf_tostring_free(s); return pa_strbuf_tostring_free(s);
} }

View file

@ -1,7 +1,7 @@
#ifndef foosourcehfoo #ifndef foosourcehfoo
#define foosourcehfoo #define foosourcehfoo
struct source; struct pa_source;
#include <inttypes.h> #include <inttypes.h>
#include "core.h" #include "core.h"
@ -10,28 +10,28 @@ struct source;
#include "memblock.h" #include "memblock.h"
#include "memchunk.h" #include "memchunk.h"
struct source { struct pa_source {
uint32_t index; uint32_t index;
char *name; char *name;
struct core *core; struct pa_core *core;
struct pa_sample_spec sample_spec; struct pa_sample_spec sample_spec;
struct idxset *outputs; struct pa_idxset *outputs;
void (*notify)(struct source*source); void (*notify)(struct pa_source*source);
void *userdata; void *userdata;
}; };
struct source* source_new(struct core *core, const char *name, int fail, const struct pa_sample_spec *spec); struct pa_source* pa_source_new(struct pa_core *core, const char *name, int fail, const struct pa_sample_spec *spec);
void source_free(struct source *s); void pa_source_free(struct pa_source *s);
/* Pass a new memory block to all output streams */ /* Pass a new memory block to all output streams */
void source_post(struct source*s, struct memchunk *b); void pa_source_post(struct pa_source*s, struct pa_memchunk *b);
void source_notify(struct source *s); void pa_source_notify(struct pa_source *s);
char *source_list_to_string(struct core *c); char *pa_source_list_to_string(struct pa_core *c);
struct source* source_get_default(struct core *c); struct pa_source* pa_source_get_default(struct pa_core *c);
#endif #endif

View file

@ -5,17 +5,17 @@
#include "sourceoutput.h" #include "sourceoutput.h"
#include "strbuf.h" #include "strbuf.h"
struct source_output* source_output_new(struct source *s, const char *name, const struct pa_sample_spec *spec) { struct pa_source_output* pa_source_output_new(struct pa_source *s, const char *name, const struct pa_sample_spec *spec) {
struct source_output *o; struct pa_source_output *o;
struct resampler *resampler = NULL; struct pa_resampler *resampler = NULL;
int r; int r;
assert(s && spec); assert(s && spec);
if (!pa_sample_spec_equal(&s->sample_spec, spec)) if (!pa_sample_spec_equal(&s->sample_spec, spec))
if (!(resampler = resampler_new(&s->sample_spec, spec))) if (!(resampler = pa_resampler_new(&s->sample_spec, spec)))
return NULL; return NULL;
o = malloc(sizeof(struct source_output)); o = malloc(sizeof(struct pa_source_output));
assert(o); assert(o);
o->name = name ? strdup(name) : NULL; o->name = name ? strdup(name) : NULL;
o->source = s; o->source = s;
@ -27,59 +27,59 @@ struct source_output* source_output_new(struct source *s, const char *name, cons
o->resampler = resampler; o->resampler = resampler;
assert(s->core); assert(s->core);
r = idxset_put(s->core->source_outputs, o, &o->index); r = pa_idxset_put(s->core->source_outputs, o, &o->index);
assert(r == 0 && o->index != IDXSET_INVALID); assert(r == 0 && o->index != PA_IDXSET_INVALID);
r = idxset_put(s->outputs, o, NULL); r = pa_idxset_put(s->outputs, o, NULL);
assert(r == 0); assert(r == 0);
return o; return o;
} }
void source_output_free(struct source_output* o) { void pa_source_output_free(struct pa_source_output* o) {
assert(o); assert(o);
assert(o->source && o->source->core); assert(o->source && o->source->core);
idxset_remove_by_data(o->source->core->source_outputs, o, NULL); pa_idxset_remove_by_data(o->source->core->source_outputs, o, NULL);
idxset_remove_by_data(o->source->outputs, o, NULL); pa_idxset_remove_by_data(o->source->outputs, o, NULL);
if (o->resampler) if (o->resampler)
resampler_free(o->resampler); pa_resampler_free(o->resampler);
free(o->name); free(o->name);
free(o); free(o);
} }
void source_output_kill(struct source_output*i) { void pa_source_output_kill(struct pa_source_output*i) {
assert(i); assert(i);
if (i->kill) if (i->kill)
i->kill(i); i->kill(i);
} }
char *source_output_list_to_string(struct core *c) { char *pa_source_output_list_to_string(struct pa_core *c) {
struct strbuf *s; struct pa_strbuf *s;
struct source_output *o; struct pa_source_output *o;
uint32_t index = IDXSET_INVALID; uint32_t index = PA_IDXSET_INVALID;
assert(c); assert(c);
s = strbuf_new(); s = pa_strbuf_new();
assert(s); assert(s);
strbuf_printf(s, "%u source outputs(s) available.\n", idxset_ncontents(c->source_outputs)); pa_strbuf_printf(s, "%u source outputs(s) available.\n", pa_idxset_ncontents(c->source_outputs));
for (o = idxset_first(c->source_outputs, &index); o; o = idxset_next(c->source_outputs, &index)) { for (o = pa_idxset_first(c->source_outputs, &index); o; o = pa_idxset_next(c->source_outputs, &index)) {
assert(o->source); assert(o->source);
strbuf_printf(s, " %c index: %u, name: <%s>, source: <%u>\n", pa_strbuf_printf(s, " %c index: %u, name: <%s>, source: <%u>\n",
o->index, o->index,
o->name, o->name,
o->source->index); o->source->index);
} }
return strbuf_tostring_free(s); return pa_strbuf_tostring_free(s);
} }
void source_output_push(struct source_output *o, const struct memchunk *chunk) { void pa_source_output_push(struct pa_source_output *o, const struct pa_memchunk *chunk) {
struct memchunk rchunk; struct pa_memchunk rchunk;
assert(o && chunk && chunk->length && o->push); assert(o && chunk && chunk->length && o->push);
if (!o->resampler) { if (!o->resampler) {
@ -87,11 +87,11 @@ void source_output_push(struct source_output *o, const struct memchunk *chunk) {
return; return;
} }
resampler_run(o->resampler, chunk, &rchunk); pa_resampler_run(o->resampler, chunk, &rchunk);
if (!rchunk.length) if (!rchunk.length)
return; return;
assert(rchunk.memblock); assert(rchunk.memblock);
o->push(o, &rchunk); o->push(o, &rchunk);
memblock_unref(rchunk.memblock); pa_memblock_unref(rchunk.memblock);
} }

View file

@ -8,28 +8,28 @@
#include "memblockq.h" #include "memblockq.h"
#include "resampler.h" #include "resampler.h"
struct source_output { struct pa_source_output {
uint32_t index; uint32_t index;
char *name; char *name;
struct source *source; struct pa_source *source;
struct pa_sample_spec sample_spec; struct pa_sample_spec sample_spec;
void (*push)(struct source_output *o, const struct memchunk *chunk); void (*push)(struct pa_source_output *o, const struct pa_memchunk *chunk);
void (*kill)(struct source_output* o); void (*kill)(struct pa_source_output* o);
struct resampler* resampler; struct pa_resampler* resampler;
void *userdata; void *userdata;
}; };
struct source_output* source_output_new(struct source *s, const char *name, const struct pa_sample_spec *spec); struct pa_source_output* pa_source_output_new(struct pa_source *s, const char *name, const struct pa_sample_spec *spec);
void source_output_free(struct source_output* o); void pa_source_output_free(struct pa_source_output* o);
void source_output_kill(struct source_output*o); void pa_source_output_kill(struct pa_source_output*o);
char *source_output_list_to_string(struct core *c); char *pa_source_output_list_to_string(struct pa_core *c);
void source_output_push(struct source_output *o, const struct memchunk *chunk); void pa_source_output_push(struct pa_source_output *o, const struct pa_memchunk *chunk);
#endif #endif

View file

@ -11,20 +11,20 @@ struct chunk {
char text[]; char text[];
}; };
struct strbuf { struct pa_strbuf {
size_t length; size_t length;
struct chunk *head, *tail; struct chunk *head, *tail;
}; };
struct strbuf *strbuf_new(void) { struct pa_strbuf *pa_strbuf_new(void) {
struct strbuf *sb = malloc(sizeof(struct strbuf)); struct pa_strbuf *sb = malloc(sizeof(struct pa_strbuf));
assert(sb); assert(sb);
sb->length = 0; sb->length = 0;
sb->head = sb->tail = NULL; sb->head = sb->tail = NULL;
return sb; return sb;
} }
void strbuf_free(struct strbuf *sb) { void pa_strbuf_free(struct pa_strbuf *sb) {
assert(sb); assert(sb);
while (sb->head) { while (sb->head) {
struct chunk *c = sb->head; struct chunk *c = sb->head;
@ -35,7 +35,7 @@ void strbuf_free(struct strbuf *sb) {
free(sb); free(sb);
} }
char *strbuf_tostring(struct strbuf *sb) { char *pa_strbuf_tostring(struct pa_strbuf *sb) {
char *t, *e; char *t, *e;
struct chunk *c; struct chunk *c;
assert(sb); assert(sb);
@ -54,15 +54,15 @@ char *strbuf_tostring(struct strbuf *sb) {
return t; return t;
} }
char *strbuf_tostring_free(struct strbuf *sb) { char *pa_strbuf_tostring_free(struct pa_strbuf *sb) {
char *t; char *t;
assert(sb); assert(sb);
t = strbuf_tostring(sb); t = pa_strbuf_tostring(sb);
strbuf_free(sb); pa_strbuf_free(sb);
return t; return t;
} }
void strbuf_puts(struct strbuf *sb, const char *t) { void pa_strbuf_puts(struct pa_strbuf *sb, const char *t) {
struct chunk *c; struct chunk *c;
size_t l; size_t l;
assert(sb && t); assert(sb && t);
@ -87,7 +87,7 @@ void strbuf_puts(struct strbuf *sb, const char *t) {
sb->length += l; sb->length += l;
} }
int strbuf_printf(struct strbuf *sb, const char *format, ...) { int pa_strbuf_printf(struct pa_strbuf *sb, const char *format, ...) {
int r, size = 100; int r, size = 100;
struct chunk *c = NULL; struct chunk *c = NULL;

View file

@ -1,14 +1,14 @@
#ifndef foostrbufhfoo #ifndef foostrbufhfoo
#define foostrbufhfoo #define foostrbufhfoo
struct strbuf; struct pa_strbuf;
struct strbuf *strbuf_new(void); struct pa_strbuf *pa_strbuf_new(void);
void strbuf_free(struct strbuf *sb); void pa_strbuf_free(struct pa_strbuf *sb);
char *strbuf_tostring(struct strbuf *sb); char *pa_strbuf_tostring(struct pa_strbuf *sb);
char *strbuf_tostring_free(struct strbuf *sb); char *pa_strbuf_tostring_free(struct pa_strbuf *sb);
int strbuf_printf(struct strbuf *sb, const char *format, ...); int pa_strbuf_printf(struct pa_strbuf *sb, const char *format, ...);
void strbuf_puts(struct strbuf *sb, const char *t); void pa_strbuf_puts(struct pa_strbuf *sb, const char *t);
#endif #endif

View file

@ -16,7 +16,7 @@ enum tags {
TAG_SAMPLE_SPEC = 'a' TAG_SAMPLE_SPEC = 'a'
}; };
struct tagstruct { struct pa_tagstruct {
uint8_t *data; uint8_t *data;
size_t length, allocated; size_t length, allocated;
size_t rindex; size_t rindex;
@ -24,12 +24,12 @@ struct tagstruct {
int dynamic; int dynamic;
}; };
struct tagstruct *tagstruct_new(const uint8_t* data, size_t length) { struct pa_tagstruct *pa_tagstruct_new(const uint8_t* data, size_t length) {
struct tagstruct*t; struct pa_tagstruct*t;
assert(!data || (data && length)); assert(!data || (data && length));
t = malloc(sizeof(struct tagstruct)); t = malloc(sizeof(struct pa_tagstruct));
assert(t); assert(t);
t->data = (uint8_t*) data; t->data = (uint8_t*) data;
t->allocated = t->length = data ? length : 0; t->allocated = t->length = data ? length : 0;
@ -38,14 +38,14 @@ struct tagstruct *tagstruct_new(const uint8_t* data, size_t length) {
return t; return t;
} }
void tagstruct_free(struct tagstruct*t) { void pa_tagstruct_free(struct pa_tagstruct*t) {
assert(t); assert(t);
if (t->dynamic) if (t->dynamic)
free(t->data); free(t->data);
free(t); free(t);
} }
uint8_t* tagstruct_free_data(struct tagstruct*t, size_t *l) { uint8_t* pa_tagstruct_free_data(struct pa_tagstruct*t, size_t *l) {
uint8_t *p; uint8_t *p;
assert(t && t->dynamic && l); assert(t && t->dynamic && l);
p = t->data; p = t->data;
@ -54,7 +54,7 @@ uint8_t* tagstruct_free_data(struct tagstruct*t, size_t *l) {
return p; return p;
} }
static void extend(struct tagstruct*t, size_t l) { static void extend(struct pa_tagstruct*t, size_t l) {
assert(t && t->dynamic); assert(t && t->dynamic);
if (l <= t->allocated) if (l <= t->allocated)
@ -64,7 +64,7 @@ static void extend(struct tagstruct*t, size_t l) {
assert(t->data); assert(t->data);
} }
void tagstruct_puts(struct tagstruct*t, const char *s) { void pa_tagstruct_puts(struct pa_tagstruct*t, const char *s) {
size_t l; size_t l;
assert(t && s); assert(t && s);
l = strlen(s)+2; l = strlen(s)+2;
@ -74,7 +74,7 @@ void tagstruct_puts(struct tagstruct*t, const char *s) {
t->length += l; t->length += l;
} }
void tagstruct_putu32(struct tagstruct*t, uint32_t i) { void pa_tagstruct_putu32(struct pa_tagstruct*t, uint32_t i) {
assert(t); assert(t);
extend(t, 5); extend(t, 5);
t->data[t->length] = TAG_U32; t->data[t->length] = TAG_U32;
@ -82,7 +82,7 @@ void tagstruct_putu32(struct tagstruct*t, uint32_t i) {
t->length += 5; t->length += 5;
} }
void tagstruct_putu8(struct tagstruct*t, uint8_t c) { void pa_tagstruct_putu8(struct pa_tagstruct*t, uint8_t c) {
assert(t); assert(t);
extend(t, 2); extend(t, 2);
t->data[t->length] = TAG_U8; t->data[t->length] = TAG_U8;
@ -90,7 +90,7 @@ void tagstruct_putu8(struct tagstruct*t, uint8_t c) {
t->length += 2; t->length += 2;
} }
void tagstruct_put_sample_spec(struct tagstruct *t, const struct pa_sample_spec *ss) { void pa_tagstruct_put_sample_spec(struct pa_tagstruct *t, const struct pa_sample_spec *ss) {
assert(t && ss); assert(t && ss);
extend(t, 7); extend(t, 7);
t->data[t->length] = TAG_SAMPLE_SPEC; t->data[t->length] = TAG_SAMPLE_SPEC;
@ -100,7 +100,7 @@ void tagstruct_put_sample_spec(struct tagstruct *t, const struct pa_sample_spec
t->length += 7; t->length += 7;
} }
int tagstruct_gets(struct tagstruct*t, const char **s) { int pa_tagstruct_gets(struct pa_tagstruct*t, const char **s) {
int error = 0; int error = 0;
size_t n; size_t n;
char *c; char *c;
@ -128,7 +128,7 @@ int tagstruct_gets(struct tagstruct*t, const char **s) {
return 0; return 0;
} }
int tagstruct_getu32(struct tagstruct*t, uint32_t *i) { int pa_tagstruct_getu32(struct pa_tagstruct*t, uint32_t *i) {
assert(t && i); assert(t && i);
if (t->rindex+5 > t->length) if (t->rindex+5 > t->length)
@ -142,7 +142,7 @@ int tagstruct_getu32(struct tagstruct*t, uint32_t *i) {
return 0; return 0;
} }
int tagstruct_getu8(struct tagstruct*t, uint8_t *c) { int pa_tagstruct_getu8(struct pa_tagstruct*t, uint8_t *c) {
assert(t && c); assert(t && c);
if (t->rindex+2 > t->length) if (t->rindex+2 > t->length)
@ -156,7 +156,7 @@ int tagstruct_getu8(struct tagstruct*t, uint8_t *c) {
return 0; return 0;
} }
int tagstruct_get_sample_spec(struct tagstruct *t, struct pa_sample_spec *ss) { int pa_tagstruct_get_sample_spec(struct pa_tagstruct *t, struct pa_sample_spec *ss) {
assert(t && ss); assert(t && ss);
if (t->rindex+7 > t->length) if (t->rindex+7 > t->length)
@ -174,12 +174,12 @@ int tagstruct_get_sample_spec(struct tagstruct *t, struct pa_sample_spec *ss) {
} }
int tagstruct_eof(struct tagstruct*t) { int pa_tagstruct_eof(struct pa_tagstruct*t) {
assert(t); assert(t);
return t->rindex >= t->length; return t->rindex >= t->length;
} }
const uint8_t* tagstruct_data(struct tagstruct*t, size_t *l) { const uint8_t* pa_tagstruct_data(struct pa_tagstruct*t, size_t *l) {
assert(t && t->dynamic && l); assert(t && t->dynamic && l);
*l = t->length; *l = t->length;
return t->data; return t->data;

View file

@ -6,24 +6,24 @@
#include "sample.h" #include "sample.h"
struct tagstruct; struct pa_tagstruct;
struct tagstruct *tagstruct_new(const uint8_t* data, size_t length); struct pa_tagstruct *pa_tagstruct_new(const uint8_t* data, size_t length);
void tagstruct_free(struct tagstruct*t); void pa_tagstruct_free(struct pa_tagstruct*t);
uint8_t* tagstruct_free_data(struct tagstruct*t, size_t *l); uint8_t* pa_tagstruct_free_data(struct pa_tagstruct*t, size_t *l);
void tagstruct_puts(struct tagstruct*t, const char *s); void pa_tagstruct_puts(struct pa_tagstruct*t, const char *s);
void tagstruct_putu32(struct tagstruct*t, uint32_t i); void pa_tagstruct_putu32(struct pa_tagstruct*t, uint32_t i);
void tagstruct_putu8(struct tagstruct*t, uint8_t c); void pa_tagstruct_putu8(struct pa_tagstruct*t, uint8_t c);
void tagstruct_put_sample_spec(struct tagstruct *t, const struct pa_sample_spec *ss); void pa_tagstruct_put_sample_spec(struct pa_tagstruct *t, const struct pa_sample_spec *ss);
int tagstruct_gets(struct tagstruct*t, const char **s); int pa_tagstruct_gets(struct pa_tagstruct*t, const char **s);
int tagstruct_getu32(struct tagstruct*t, uint32_t *i); int pa_tagstruct_getu32(struct pa_tagstruct*t, uint32_t *i);
int tagstruct_getu8(struct tagstruct*t, uint8_t *c); int pa_tagstruct_getu8(struct pa_tagstruct*t, uint8_t *c);
int tagstruct_get_sample_spec(struct tagstruct *t, struct pa_sample_spec *ss); int pa_tagstruct_get_sample_spec(struct pa_tagstruct *t, struct pa_sample_spec *ss);
int tagstruct_eof(struct tagstruct*t); int pa_tagstruct_eof(struct pa_tagstruct*t);
const uint8_t* tagstruct_data(struct tagstruct*t, size_t *l); const uint8_t* pa_tagstruct_data(struct pa_tagstruct*t, size_t *l);

View file

@ -1,5 +1,4 @@
- recording (general, simple, esound, native) - recording (general, simple, esound, native)
- make it embedable (add pa_ prefix too all identifiers)
- native library/protocol: - native library/protocol:
sync() function sync() function
more functions more functions
@ -7,8 +6,10 @@
- kill() routines in all modules - kill() routines in all modules
- command line protocol: - command line protocol:
kill client/input/output kill client/input/output
default_sink/source
- config parser/cmdline - config parser/cmdline
- move more stuff from module-oss[-dma] to liboss-util - move more stuff from module-oss[-dma] to liboss-util
- stdin_inuse/stdout_inuse
- svn-id and license in every file - svn-id and license in every file
-- post 0.1 -- post 0.1

View file

@ -5,15 +5,15 @@
#include "tokenizer.h" #include "tokenizer.h"
#include "dynarray.h" #include "dynarray.h"
struct tokenizer { struct pa_tokenizer {
struct dynarray *dynarray; struct pa_dynarray *dynarray;
}; };
static void token_free(void *p, void *userdata) { static void token_free(void *p, void *userdata) {
free(p); free(p);
} }
static void parse(struct dynarray*a, const char *s, unsigned args) { static void parse(struct pa_dynarray*a, const char *s, unsigned args) {
int infty = 0; int infty = 0;
const char delimiter[] = " \t\n\r"; const char delimiter[] = " \t\n\r";
const char *p; const char *p;
@ -27,7 +27,7 @@ static void parse(struct dynarray*a, const char *s, unsigned args) {
size_t l = strcspn(p, delimiter); size_t l = strcspn(p, delimiter);
char *n = strndup(p, l); char *n = strndup(p, l);
assert(n); assert(n);
dynarray_append(a, n); pa_dynarray_append(a, n);
p += l; p += l;
p += strspn(p, delimiter); p += strspn(p, delimiter);
args--; args--;
@ -36,29 +36,29 @@ static void parse(struct dynarray*a, const char *s, unsigned args) {
if (args && *p) { if (args && *p) {
char *n = strdup(p); char *n = strdup(p);
assert(n); assert(n);
dynarray_append(a, n); pa_dynarray_append(a, n);
} }
} }
struct tokenizer* tokenizer_new(const char *s, unsigned args) { struct pa_tokenizer* pa_tokenizer_new(const char *s, unsigned args) {
struct tokenizer *t; struct pa_tokenizer *t;
t = malloc(sizeof(struct tokenizer)); t = malloc(sizeof(struct pa_tokenizer));
assert(t); assert(t);
t->dynarray = dynarray_new(); t->dynarray = pa_dynarray_new();
assert(t->dynarray); assert(t->dynarray);
parse(t->dynarray, s, args); parse(t->dynarray, s, args);
return t; return t;
} }
void tokenizer_free(struct tokenizer *t) { void pa_tokenizer_free(struct pa_tokenizer *t) {
assert(t); assert(t);
dynarray_free(t->dynarray, token_free, NULL); pa_dynarray_free(t->dynarray, token_free, NULL);
free(t); free(t);
} }
const char *tokenizer_get(struct tokenizer *t, unsigned i) { const char *pa_tokenizer_get(struct pa_tokenizer *t, unsigned i) {
assert(t); assert(t);
return dynarray_get(t->dynarray, i); return pa_dynarray_get(t->dynarray, i);
} }

View file

@ -1,11 +1,11 @@
#ifndef footokenizerhfoo #ifndef footokenizerhfoo
#define footokenizerhfoo #define footokenizerhfoo
struct tokenizer; struct pa_tokenizer;
struct tokenizer* tokenizer_new(const char *s, unsigned args); struct pa_tokenizer* pa_tokenizer_new(const char *s, unsigned args);
void tokenizer_free(struct tokenizer *t); void pa_tokenizer_free(struct pa_tokenizer *t);
const char *tokenizer_get(struct tokenizer *t, unsigned i); const char *pa_tokenizer_get(struct pa_tokenizer *t, unsigned i);
#endif #endif

View file

@ -12,7 +12,7 @@
#include "util.h" #include "util.h"
void make_nonblock_fd(int fd) { void pa_make_nonblock_fd(int fd) {
int v; int v;
if ((v = fcntl(fd, F_GETFL)) >= 0) if ((v = fcntl(fd, F_GETFL)) >= 0)
@ -20,7 +20,7 @@ void make_nonblock_fd(int fd) {
fcntl(fd, F_SETFL, v|O_NONBLOCK); fcntl(fd, F_SETFL, v|O_NONBLOCK);
} }
void peer_to_string(char *c, size_t l, int fd) { void pa_peer_to_string(char *c, size_t l, int fd) {
struct stat st; struct stat st;
assert(c && l && fd >= 0); assert(c && l && fd >= 0);
@ -66,7 +66,7 @@ void peer_to_string(char *c, size_t l, int fd) {
snprintf(c, l, "Unknown client"); snprintf(c, l, "Unknown client");
} }
int make_secure_dir(const char* dir) { int pa_make_secure_dir(const char* dir) {
struct stat st; struct stat st;
if (mkdir(dir, 0700) < 0) if (mkdir(dir, 0700) < 0)
@ -86,7 +86,7 @@ fail:
return -1; return -1;
} }
int make_socket_low_delay(int fd) { int pa_make_socket_low_delay(int fd) {
int ret = 0, buf_size, priority; int ret = 0, buf_size, priority;
assert(fd >= 0); assert(fd >= 0);
@ -106,12 +106,12 @@ int make_socket_low_delay(int fd) {
return ret; return ret;
} }
int make_tcp_socket_low_delay(int fd) { int pa_make_tcp_socket_low_delay(int fd) {
int ret, tos, on; int ret, tos, on;
assert(fd >= 0); assert(fd >= 0);
ret = make_socket_low_delay(fd); ret = pa_make_socket_low_delay(fd);
on = 1; on = 1;
if (setsockopt(fd, SOL_TCP, TCP_NODELAY, &on, sizeof(on)) < 0) if (setsockopt(fd, SOL_TCP, TCP_NODELAY, &on, sizeof(on)) < 0)

View file

@ -1,13 +1,15 @@
#ifndef fooutilhfoo #ifndef fooutilhfoo
#define fooutilhfoo #define fooutilhfoo
void make_nonblock_fd(int fd); #include <sys/types.h>
void peer_to_string(char *c, size_t l, int fd); void pa_make_nonblock_fd(int fd);
int make_secure_dir(const char* dir); void pa_peer_to_string(char *c, size_t l, int fd);
int make_socket_low_delay(int fd); int pa_make_secure_dir(const char* dir);
int make_tcp_socket_low_delay(int fd);
int pa_make_socket_low_delay(int fd);
int pa_make_tcp_socket_low_delay(int fd);
#endif #endif