mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-03 09:01:50 -05:00
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:
parent
a8a5ab1c79
commit
e61c2dddb7
91 changed files with 1795 additions and 1643 deletions
|
|
@ -20,17 +20,36 @@ AM_CFLAGS=-ansi -D_GNU_SOURCE
|
|||
|
||||
bin_PROGRAMS = polypaudio pacat
|
||||
|
||||
pkglib_LTLIBRARIES=libiochannel.la libsocket-server.la libsocket-client.la \
|
||||
libprotocol-simple.la module-simple-protocol-tcp.la \
|
||||
module-pipe-sink.la libpstream.la \
|
||||
libpacket.la module-oss.la module-oss-mmap.la liboss-util.la libioline.la \
|
||||
libcli.la module-cli.la libtokenizer.la libdynarray.la \
|
||||
module-simple-protocol-unix.la module-cli-protocol-tcp.la \
|
||||
libprotocol-cli.la module-cli-protocol-unix.la libtagstruct.la \
|
||||
libpdispatch.la libprotocol-native.la libpstream-util.la \
|
||||
module-native-protocol-tcp.la module-native-protocol-unix.la \
|
||||
libpolyp.la libprotocol-esound.la module-esound-protocol-unix.la \
|
||||
module-esound-protocol-tcp.la
|
||||
pkglib_LTLIBRARIES=libiochannel.la \
|
||||
libsocket-server.la \
|
||||
libsocket-client.la \
|
||||
libpstream.la \
|
||||
libpacket.la \
|
||||
liboss-util.la \
|
||||
libioline.la \
|
||||
libcli.la \
|
||||
libtokenizer.la \
|
||||
libdynarray.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 \
|
||||
queue.c queue.h \
|
||||
|
|
@ -56,7 +75,9 @@ polypaudio_SOURCES = idxset.c idxset.h \
|
|||
sconv.c sconv.h \
|
||||
resampler.c resampler.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_INCLUDES = $(INCLTDL)
|
||||
polypaudio_LDADD = $(LIBLTDL) $(LIBSAMPLERATE_LIBS)
|
||||
|
|
|
|||
248
src/cli.c
248
src/cli.c
|
|
@ -15,94 +15,94 @@
|
|||
#include "strbuf.h"
|
||||
#include "namereg.h"
|
||||
|
||||
struct cli {
|
||||
struct core *core;
|
||||
struct ioline *line;
|
||||
struct pa_cli {
|
||||
struct pa_core *core;
|
||||
struct pa_ioline *line;
|
||||
|
||||
void (*eof_callback)(struct cli *c, void *userdata);
|
||||
void (*eof_callback)(struct pa_cli *c, void *userdata);
|
||||
void *userdata;
|
||||
|
||||
struct client *client;
|
||||
struct pa_client *client;
|
||||
};
|
||||
|
||||
struct command {
|
||||
const char *name;
|
||||
void (*proc) (struct cli *cli, struct tokenizer*t);
|
||||
void (*proc) (struct pa_cli *cli, struct pa_tokenizer*t);
|
||||
const char *help;
|
||||
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 cli_command_help(struct cli *c, struct tokenizer *t);
|
||||
static void cli_command_modules(struct cli *c, struct tokenizer *t);
|
||||
static void cli_command_clients(struct cli *c, struct tokenizer *t);
|
||||
static void cli_command_sinks(struct cli *c, struct tokenizer *t);
|
||||
static void cli_command_sources(struct cli *c, struct tokenizer *t);
|
||||
static void cli_command_sink_inputs(struct cli *c, struct tokenizer *t);
|
||||
static void cli_command_source_outputs(struct cli *c, struct tokenizer *t);
|
||||
static void cli_command_stat(struct cli *c, struct tokenizer *t);
|
||||
static void cli_command_info(struct cli *c, struct tokenizer *t);
|
||||
static void cli_command_load(struct cli *c, struct tokenizer *t);
|
||||
static void cli_command_unload(struct cli *c, struct tokenizer *t);
|
||||
static void cli_command_sink_volume(struct cli *c, struct tokenizer *t);
|
||||
static void cli_command_sink_input_volume(struct cli *c, struct tokenizer *t);
|
||||
static void pa_cli_command_exit(struct pa_cli *c, struct pa_tokenizer *t);
|
||||
static void pa_cli_command_help(struct pa_cli *c, struct pa_tokenizer *t);
|
||||
static void pa_cli_command_modules(struct pa_cli *c, struct pa_tokenizer *t);
|
||||
static void pa_cli_command_clients(struct pa_cli *c, struct pa_tokenizer *t);
|
||||
static void pa_cli_command_sinks(struct pa_cli *c, struct pa_tokenizer *t);
|
||||
static void pa_cli_command_sources(struct pa_cli *c, struct pa_tokenizer *t);
|
||||
static void pa_cli_command_sink_inputs(struct pa_cli *c, struct pa_tokenizer *t);
|
||||
static void pa_cli_command_source_outputs(struct pa_cli *c, struct pa_tokenizer *t);
|
||||
static void pa_cli_command_stat(struct pa_cli *c, struct pa_tokenizer *t);
|
||||
static void pa_cli_command_info(struct pa_cli *c, struct pa_tokenizer *t);
|
||||
static void pa_cli_command_load(struct pa_cli *c, struct pa_tokenizer *t);
|
||||
static void pa_cli_command_unload(struct pa_cli *c, struct pa_tokenizer *t);
|
||||
static void pa_cli_command_sink_volume(struct pa_cli *c, struct pa_tokenizer *t);
|
||||
static void pa_cli_command_sink_input_volume(struct pa_cli *c, struct pa_tokenizer *t);
|
||||
|
||||
static const struct command commands[] = {
|
||||
{ "exit", cli_command_exit, "Terminate the daemon", 1 },
|
||||
{ "help", cli_command_help, "Show this help", 1 },
|
||||
{ "modules", cli_command_modules, "List loaded modules", 1 },
|
||||
{ "sinks", cli_command_sinks, "List loaded sinks", 1 },
|
||||
{ "sources", cli_command_sources, "List loaded sources", 1 },
|
||||
{ "clients", cli_command_clients, "List loaded clients", 1 },
|
||||
{ "sink_inputs", cli_command_sink_inputs, "List sink inputs", 1 },
|
||||
{ "source_outputs", cli_command_source_outputs, "List source outputs", 1 },
|
||||
{ "stat", cli_command_stat, "Show memory block statistics", 1 },
|
||||
{ "info", cli_command_info, "Show comprehensive status", 1 },
|
||||
{ "load", cli_command_load, "Load a module (args: name, arguments)", 3},
|
||||
{ "unload", 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_input_volume", cli_command_sink_input_volume, "Set the volume of a sink input (args: sink input, volume)", 3},
|
||||
{ "exit", pa_cli_command_exit, "Terminate the daemon", 1 },
|
||||
{ "help", pa_cli_command_help, "Show this help", 1 },
|
||||
{ "modules", pa_cli_command_modules, "List loaded modules", 1 },
|
||||
{ "sinks", pa_cli_command_sinks, "List loaded sinks", 1 },
|
||||
{ "sources", pa_cli_command_sources, "List loaded sources", 1 },
|
||||
{ "clients", pa_cli_command_clients, "List loaded clients", 1 },
|
||||
{ "sink_inputs", pa_cli_command_sink_inputs, "List sink inputs", 1 },
|
||||
{ "source_outputs", pa_cli_command_source_outputs, "List source outputs", 1 },
|
||||
{ "stat", pa_cli_command_stat, "Show memory block statistics", 1 },
|
||||
{ "info", pa_cli_command_info, "Show comprehensive status", 1 },
|
||||
{ "load", pa_cli_command_load, "Load a module (args: name, arguments)", 3},
|
||||
{ "unload", pa_cli_command_unload, "Unload a module (args: index)", 2},
|
||||
{ "sink_volume", pa_cli_command_sink_volume, "Set the volume of a sink (args: sink, 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 }
|
||||
};
|
||||
|
||||
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];
|
||||
struct cli *c;
|
||||
struct pa_cli *c;
|
||||
assert(io);
|
||||
|
||||
c = malloc(sizeof(struct cli));
|
||||
c = malloc(sizeof(struct pa_cli));
|
||||
assert(c);
|
||||
c->core = core;
|
||||
c->line = ioline_new(io);
|
||||
c->line = pa_ioline_new(io);
|
||||
assert(c->line);
|
||||
|
||||
c->userdata = NULL;
|
||||
c->eof_callback = NULL;
|
||||
|
||||
iochannel_peer_to_string(io, cname, sizeof(cname));
|
||||
c->client = client_new(core, "CLI", cname);
|
||||
pa_iochannel_peer_to_string(io, cname, sizeof(cname));
|
||||
c->client = pa_client_new(core, "CLI", cname);
|
||||
assert(c->client);
|
||||
|
||||
ioline_set_callback(c->line, line_callback, c);
|
||||
ioline_puts(c->line, "Welcome to polypaudio! Use \"help\" for usage information.\n");
|
||||
ioline_puts(c->line, prompt);
|
||||
pa_ioline_set_callback(c->line, line_callback, c);
|
||||
pa_ioline_puts(c->line, "Welcome to polypaudio! Use \"help\" for usage information.\n");
|
||||
pa_ioline_puts(c->line, prompt);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void cli_free(struct cli *c) {
|
||||
void pa_cli_free(struct pa_cli *c) {
|
||||
assert(c);
|
||||
ioline_free(c->line);
|
||||
client_free(c->client);
|
||||
pa_ioline_free(c->line);
|
||||
pa_client_free(c->client);
|
||||
free(c);
|
||||
}
|
||||
|
||||
static void line_callback(struct ioline *line, const char *s, void *userdata) {
|
||||
struct cli *c = userdata;
|
||||
static void line_callback(struct pa_ioline *line, const char *s, void *userdata) {
|
||||
struct pa_cli *c = userdata;
|
||||
const char *cs;
|
||||
const char delimiter[] = " \t\n\r";
|
||||
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++)
|
||||
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);
|
||||
command->proc(c, t);
|
||||
tokenizer_free(t);
|
||||
pa_tokenizer_free(t);
|
||||
unknown = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
c->eof_callback = cb;
|
||||
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);
|
||||
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;
|
||||
struct strbuf *strbuf;
|
||||
struct pa_strbuf *pa_strbuf;
|
||||
char *p;
|
||||
assert(c && t);
|
||||
|
||||
strbuf = strbuf_new();
|
||||
assert(strbuf);
|
||||
pa_strbuf = pa_strbuf_new();
|
||||
assert(pa_strbuf);
|
||||
|
||||
strbuf_puts(strbuf, "Available commands:\n");
|
||||
pa_strbuf_puts(pa_strbuf, "Available commands:\n");
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
assert(c && t);
|
||||
s = module_list_to_string(c->core);
|
||||
s = pa_module_list_to_string(c->core);
|
||||
assert(s);
|
||||
ioline_puts(c->line, s);
|
||||
pa_ioline_puts(c->line, 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;
|
||||
assert(c && t);
|
||||
s = client_list_to_string(c->core);
|
||||
s = pa_client_list_to_string(c->core);
|
||||
assert(s);
|
||||
ioline_puts(c->line, s);
|
||||
pa_ioline_puts(c->line, 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;
|
||||
assert(c && t);
|
||||
s = sink_list_to_string(c->core);
|
||||
s = pa_sink_list_to_string(c->core);
|
||||
assert(s);
|
||||
ioline_puts(c->line, s);
|
||||
pa_ioline_puts(c->line, 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;
|
||||
assert(c && t);
|
||||
s = source_list_to_string(c->core);
|
||||
s = pa_source_list_to_string(c->core);
|
||||
assert(s);
|
||||
ioline_puts(c->line, s);
|
||||
pa_ioline_puts(c->line, 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;
|
||||
assert(c && t);
|
||||
s = sink_input_list_to_string(c->core);
|
||||
s = pa_sink_input_list_to_string(c->core);
|
||||
assert(s);
|
||||
ioline_puts(c->line, s);
|
||||
pa_ioline_puts(c->line, 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;
|
||||
assert(c && t);
|
||||
s = source_output_list_to_string(c->core);
|
||||
s = pa_source_output_list_to_string(c->core);
|
||||
assert(s);
|
||||
ioline_puts(c->line, s);
|
||||
pa_ioline_puts(c->line, 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];
|
||||
assert(c && t);
|
||||
snprintf(txt, sizeof(txt), "Memory blocks allocated: %u, total size: %u bytes.\n", memblock_count, memblock_total);
|
||||
ioline_puts(c->line, txt);
|
||||
snprintf(txt, sizeof(txt), "Memory blocks allocated: %u, total size: %u bytes.\n", pa_memblock_count, pa_memblock_total);
|
||||
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);
|
||||
cli_command_stat(c, t);
|
||||
cli_command_modules(c, t);
|
||||
cli_command_sources(c, t);
|
||||
cli_command_sinks(c, t);
|
||||
cli_command_clients(c, t);
|
||||
cli_command_sink_inputs(c, t);
|
||||
cli_command_source_outputs(c, t);
|
||||
pa_cli_command_stat(c, t);
|
||||
pa_cli_command_modules(c, t);
|
||||
pa_cli_command_sources(c, t);
|
||||
pa_cli_command_sinks(c, t);
|
||||
pa_cli_command_clients(c, t);
|
||||
pa_cli_command_sink_inputs(c, t);
|
||||
pa_cli_command_source_outputs(c, t);
|
||||
}
|
||||
|
||||
static void cli_command_load(struct cli *c, struct tokenizer *t) {
|
||||
struct module *m;
|
||||
static void pa_cli_command_load(struct pa_cli *c, struct pa_tokenizer *t) {
|
||||
struct pa_module *m;
|
||||
const char *name;
|
||||
char txt[256];
|
||||
assert(c && t);
|
||||
|
||||
if (!(name = tokenizer_get(t, 1))) {
|
||||
ioline_puts(c->line, "You need to specfiy the module name and optionally arguments.\n");
|
||||
if (!(name = pa_tokenizer_get(t, 1))) {
|
||||
pa_ioline_puts(c->line, "You need to specfiy the module name and optionally arguments.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(m = module_load(c->core, name, tokenizer_get(t, 2)))) {
|
||||
ioline_puts(c->line, "Module load failed.\n");
|
||||
if (!(m = pa_module_load(c->core, name, pa_tokenizer_get(t, 2)))) {
|
||||
pa_ioline_puts(c->line, "Module load failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
struct module *m;
|
||||
static void pa_cli_command_unload(struct pa_cli *c, struct pa_tokenizer *t) {
|
||||
struct pa_module *m;
|
||||
uint32_t index;
|
||||
const char *i;
|
||||
char *e;
|
||||
assert(c && t);
|
||||
|
||||
if (!(i = tokenizer_get(t, 1))) {
|
||||
ioline_puts(c->line, "You need to specfiy the module index.\n");
|
||||
if (!(i = pa_tokenizer_get(t, 1))) {
|
||||
pa_ioline_puts(c->line, "You need to specfiy the module index.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
index = (uint32_t) strtoul(i, &e, 10);
|
||||
if (*e || !(m = idxset_get_by_index(c->core->modules, index))) {
|
||||
ioline_puts(c->line, "Invalid module index.\n");
|
||||
if (*e || !(m = pa_idxset_get_by_index(c->core->modules, index))) {
|
||||
pa_ioline_puts(c->line, "Invalid module index.\n");
|
||||
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;
|
||||
char *x = NULL;
|
||||
struct sink *sink;
|
||||
struct pa_sink *sink;
|
||||
long volume;
|
||||
|
||||
if (!(n = tokenizer_get(t, 1))) {
|
||||
ioline_puts(c->line, "You need to specify a sink either by its name or its index.\n");
|
||||
if (!(n = pa_tokenizer_get(t, 1))) {
|
||||
pa_ioline_puts(c->line, "You need to specify a sink either by its name or its index.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(v = tokenizer_get(t, 2))) {
|
||||
ioline_puts(c->line, "You need to specify a volume >= 0. (0 is muted, 0x100 is normal volume)\n");
|
||||
if (!(v = pa_tokenizer_get(t, 2))) {
|
||||
pa_ioline_puts(c->line, "You need to specify a volume >= 0. (0 is muted, 0x100 is normal volume)\n");
|
||||
return;
|
||||
}
|
||||
|
||||
volume = strtol(v, &x, 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;
|
||||
}
|
||||
|
||||
if (!(sink = namereg_get(c->core, n, NAMEREG_SINK))) {
|
||||
ioline_puts(c->line, "No sink found by this name or index.\n");
|
||||
if (!(sink = pa_namereg_get(c->core, n, PA_NAMEREG_SINK))) {
|
||||
pa_ioline_puts(c->line, "No sink found by this name or index.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
char *x = NULL;
|
||||
struct sink_input *si;
|
||||
struct pa_sink_input *si;
|
||||
long index, volume;
|
||||
|
||||
if (!(n = tokenizer_get(t, 1))) {
|
||||
ioline_puts(c->line, "You need to specify a sink input by its index.\n");
|
||||
if (!(n = pa_tokenizer_get(t, 1))) {
|
||||
pa_ioline_puts(c->line, "You need to specify a sink input by its index.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
index = strtol(n, &x, 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;
|
||||
}
|
||||
|
||||
if (!(v = tokenizer_get(t, 2))) {
|
||||
ioline_puts(c->line, "You need to specify a volume >= 0. (0 is muted, 0x100 is normal volume)\n");
|
||||
if (!(v = pa_tokenizer_get(t, 2))) {
|
||||
pa_ioline_puts(c->line, "You need to specify a volume >= 0. (0 is muted, 0x100 is normal volume)\n");
|
||||
return;
|
||||
}
|
||||
|
||||
x = NULL;
|
||||
volume = strtol(v, &x, 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;
|
||||
}
|
||||
|
||||
if (!(si = idxset_get_by_index(c->core->sink_inputs, (uint32_t) index))) {
|
||||
ioline_puts(c->line, "No sink input found with this index.\n");
|
||||
if (!(si = pa_idxset_get_by_index(c->core->sink_inputs, (uint32_t) index))) {
|
||||
pa_ioline_puts(c->line, "No sink input found with this index.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@
|
|||
#include "iochannel.h"
|
||||
#include "core.h"
|
||||
|
||||
struct cli;
|
||||
struct pa_cli;
|
||||
|
||||
struct cli* cli_new(struct core *core, struct iochannel *io);
|
||||
void cli_free(struct cli *cli);
|
||||
struct pa_cli* pa_cli_new(struct pa_core *core, struct pa_iochannel *io);
|
||||
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
|
||||
|
|
|
|||
36
src/client.c
36
src/client.c
|
|
@ -6,12 +6,12 @@
|
|||
#include "client.h"
|
||||
#include "strbuf.h"
|
||||
|
||||
struct client *client_new(struct core *core, const char *protocol_name, char *name) {
|
||||
struct client *c;
|
||||
struct pa_client *pa_client_new(struct pa_core *core, const char *protocol_name, char *name) {
|
||||
struct pa_client *c;
|
||||
int r;
|
||||
assert(core);
|
||||
|
||||
c = malloc(sizeof(struct client));
|
||||
c = malloc(sizeof(struct pa_client));
|
||||
assert(c);
|
||||
c->name = name ? strdup(name) : NULL;
|
||||
c->core = core;
|
||||
|
|
@ -20,48 +20,48 @@ struct client *client_new(struct core *core, const char *protocol_name, char *na
|
|||
c->kill = NULL;
|
||||
c->userdata = NULL;
|
||||
|
||||
r = idxset_put(core->clients, c, &c->index);
|
||||
assert(c->index != IDXSET_INVALID && r >= 0);
|
||||
r = pa_idxset_put(core->clients, c, &c->index);
|
||||
assert(c->index != PA_IDXSET_INVALID && r >= 0);
|
||||
|
||||
fprintf(stderr, "client: created %u \"%s\"\n", c->index, c->name);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void client_free(struct client *c) {
|
||||
void pa_client_free(struct pa_client *c) {
|
||||
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);
|
||||
free(c->name);
|
||||
free(c);
|
||||
}
|
||||
|
||||
void client_kill(struct client *c) {
|
||||
void pa_client_kill(struct pa_client *c) {
|
||||
assert(c);
|
||||
if (c->kill)
|
||||
c->kill(c);
|
||||
}
|
||||
|
||||
char *client_list_to_string(struct core *c) {
|
||||
struct strbuf *s;
|
||||
struct client *client;
|
||||
uint32_t index = IDXSET_INVALID;
|
||||
char *pa_client_list_to_string(struct pa_core *c) {
|
||||
struct pa_strbuf *s;
|
||||
struct pa_client *client;
|
||||
uint32_t index = PA_IDXSET_INVALID;
|
||||
assert(c);
|
||||
|
||||
s = strbuf_new();
|
||||
s = pa_strbuf_new();
|
||||
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))
|
||||
strbuf_printf(s, " index: %u, name: <%s>, protocol_name: <%s>\n", client->index, client->name, client->protocol_name);
|
||||
for (client = pa_idxset_first(c->clients, &index); client; client = pa_idxset_next(c->clients, &index))
|
||||
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);
|
||||
free(c->name);
|
||||
c->name = name ? strdup(name) : NULL;
|
||||
|
|
|
|||
16
src/client.h
16
src/client.h
|
|
@ -3,28 +3,28 @@
|
|||
|
||||
#include "core.h"
|
||||
|
||||
struct client {
|
||||
struct pa_client {
|
||||
uint32_t index;
|
||||
|
||||
char *name;
|
||||
struct core *core;
|
||||
struct pa_core *core;
|
||||
const char *protocol_name;
|
||||
|
||||
void (*kill)(struct client *c);
|
||||
void (*kill)(struct pa_client *c);
|
||||
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 */
|
||||
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
|
||||
* 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
|
||||
|
|
|
|||
44
src/core.c
44
src/core.c
|
|
@ -8,19 +8,19 @@
|
|||
#include "source.h"
|
||||
#include "namereg.h"
|
||||
|
||||
struct core* core_new(struct pa_mainloop_api *m) {
|
||||
struct core* c;
|
||||
c = malloc(sizeof(struct core));
|
||||
struct pa_core* pa_core_new(struct pa_mainloop_api *m) {
|
||||
struct pa_core* c;
|
||||
c = malloc(sizeof(struct pa_core));
|
||||
assert(c);
|
||||
|
||||
c->mainloop = m;
|
||||
c->clients = idxset_new(NULL, NULL);
|
||||
c->sinks = idxset_new(NULL, NULL);
|
||||
c->sources = idxset_new(NULL, NULL);
|
||||
c->source_outputs = idxset_new(NULL, NULL);
|
||||
c->sink_inputs = idxset_new(NULL, NULL);
|
||||
c->clients = pa_idxset_new(NULL, NULL);
|
||||
c->sinks = pa_idxset_new(NULL, NULL);
|
||||
c->sources = pa_idxset_new(NULL, NULL);
|
||||
c->source_outputs = pa_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->namereg = NULL;
|
||||
|
|
@ -28,28 +28,28 @@ struct core* core_new(struct pa_mainloop_api *m) {
|
|||
return c;
|
||||
};
|
||||
|
||||
void core_free(struct core *c) {
|
||||
void pa_core_free(struct pa_core *c) {
|
||||
assert(c);
|
||||
|
||||
module_unload_all(c);
|
||||
pa_module_unload_all(c);
|
||||
assert(!c->modules);
|
||||
|
||||
assert(idxset_isempty(c->clients));
|
||||
idxset_free(c->clients, NULL, NULL);
|
||||
assert(pa_idxset_isempty(c->clients));
|
||||
pa_idxset_free(c->clients, NULL, NULL);
|
||||
|
||||
assert(idxset_isempty(c->sinks));
|
||||
idxset_free(c->sinks, NULL, NULL);
|
||||
assert(pa_idxset_isempty(c->sinks));
|
||||
pa_idxset_free(c->sinks, NULL, NULL);
|
||||
|
||||
assert(idxset_isempty(c->sources));
|
||||
idxset_free(c->sources, NULL, NULL);
|
||||
assert(pa_idxset_isempty(c->sources));
|
||||
pa_idxset_free(c->sources, NULL, NULL);
|
||||
|
||||
assert(idxset_isempty(c->source_outputs));
|
||||
idxset_free(c->source_outputs, NULL, NULL);
|
||||
assert(pa_idxset_isempty(c->source_outputs));
|
||||
pa_idxset_free(c->source_outputs, NULL, NULL);
|
||||
|
||||
assert(idxset_isempty(c->sink_inputs));
|
||||
idxset_free(c->sink_inputs, NULL, NULL);
|
||||
assert(pa_idxset_isempty(c->sink_inputs));
|
||||
pa_idxset_free(c->sink_inputs, NULL, NULL);
|
||||
|
||||
namereg_free(c);
|
||||
pa_namereg_free(c);
|
||||
|
||||
free(c);
|
||||
};
|
||||
|
|
|
|||
10
src/core.h
10
src/core.h
|
|
@ -5,17 +5,17 @@
|
|||
#include "hashset.h"
|
||||
#include "mainloop-api.h"
|
||||
|
||||
struct core {
|
||||
struct pa_core {
|
||||
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;
|
||||
};
|
||||
|
||||
struct core* core_new(struct pa_mainloop_api *m);
|
||||
void core_free(struct core*c);
|
||||
struct pa_core* pa_core_new(struct pa_mainloop_api *m);
|
||||
void pa_core_free(struct pa_core*c);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@
|
|||
|
||||
#include "dynarray.h"
|
||||
|
||||
struct dynarray {
|
||||
struct pa_dynarray {
|
||||
void **data;
|
||||
unsigned n_allocated, n_entries;
|
||||
};
|
||||
|
||||
struct dynarray* dynarray_new(void) {
|
||||
struct dynarray *a;
|
||||
a = malloc(sizeof(struct dynarray));
|
||||
struct pa_dynarray* pa_dynarray_new(void) {
|
||||
struct pa_dynarray *a;
|
||||
a = malloc(sizeof(struct pa_dynarray));
|
||||
assert(a);
|
||||
a->data = NULL;
|
||||
a->n_entries = 0;
|
||||
|
|
@ -19,7 +19,7 @@ struct dynarray* dynarray_new(void) {
|
|||
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;
|
||||
assert(a);
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ void dynarray_free(struct dynarray* a, void (*func)(void *p, void *userdata), vo
|
|||
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);
|
||||
|
||||
if (i >= a->n_allocated) {
|
||||
|
|
@ -53,13 +53,13 @@ void dynarray_put(struct dynarray*a, unsigned i, void *p) {
|
|||
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;
|
||||
dynarray_put(a, i, p);
|
||||
pa_dynarray_put(a, i, p);
|
||||
return i;
|
||||
}
|
||||
|
||||
void *dynarray_get(struct dynarray*a, unsigned i) {
|
||||
void *pa_dynarray_get(struct pa_dynarray*a, unsigned i) {
|
||||
assert(a);
|
||||
if (i >= a->n_allocated)
|
||||
return NULL;
|
||||
|
|
@ -67,7 +67,7 @@ void *dynarray_get(struct dynarray*a, unsigned i) {
|
|||
return a->data[i];
|
||||
}
|
||||
|
||||
unsigned dynarray_ncontents(struct dynarray*a) {
|
||||
unsigned pa_dynarray_ncontents(struct pa_dynarray*a) {
|
||||
assert(a);
|
||||
return a->n_entries;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
#ifndef foodynarrayhfoo
|
||||
#define foodynarrayhfoo
|
||||
|
||||
struct dynarray;
|
||||
struct pa_dynarray;
|
||||
|
||||
struct dynarray* dynarray_new(void);
|
||||
void dynarray_free(struct dynarray* a, void (*func)(void *p, void *userdata), void *userdata);
|
||||
struct pa_dynarray* pa_dynarray_new(void);
|
||||
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);
|
||||
unsigned dynarray_append(struct dynarray*a, void *p);
|
||||
void pa_dynarray_put(struct pa_dynarray*a, unsigned i, 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
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ struct hashset_entry {
|
|||
void *value;
|
||||
};
|
||||
|
||||
struct hashset {
|
||||
struct pa_hashset {
|
||||
unsigned size;
|
||||
struct hashset_entry **data;
|
||||
struct hashset_entry *first_entry;
|
||||
|
|
@ -22,21 +22,21 @@ struct hashset {
|
|||
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 hashset *h;
|
||||
h = malloc(sizeof(struct hashset));
|
||||
struct pa_hashset *pa_hashset_new(unsigned (*hash_func) (const void *p), int (*compare_func) (const void*a, const void*b)) {
|
||||
struct pa_hashset *h;
|
||||
h = malloc(sizeof(struct pa_hashset));
|
||||
assert(h);
|
||||
h->data = malloc(sizeof(struct hashset_entry*)*(h->size = 1023));
|
||||
assert(h->data);
|
||||
memset(h->data, 0, sizeof(struct hashset_entry*)*(h->size = 1023));
|
||||
h->first_entry = NULL;
|
||||
h->n_entries = 0;
|
||||
h->hash_func = hash_func ? hash_func : idxset_trivial_hash_func;
|
||||
h->compare_func = compare_func ? compare_func : idxset_trivial_compare_func;
|
||||
h->hash_func = hash_func ? hash_func : pa_idxset_trivial_hash_func;
|
||||
h->compare_func = compare_func ? compare_func : pa_idxset_trivial_compare_func;
|
||||
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);
|
||||
|
||||
if (e->next)
|
||||
|
|
@ -57,7 +57,7 @@ static void remove(struct hashset *h, struct hashset_entry *e) {
|
|||
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);
|
||||
|
||||
while (h->first_entry) {
|
||||
|
|
@ -70,7 +70,7 @@ void hashset_free(struct hashset*h, void (*free_func)(void *p, void *userdata),
|
|||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
unsigned hash;
|
||||
assert(h && key);
|
||||
|
|
@ -113,7 +113,7 @@ int hashset_put(struct hashset *h, const void *key, void *value) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void* hashset_get(struct hashset *h, const void *key) {
|
||||
void* pa_hashset_get(struct pa_hashset *h, const void *key) {
|
||||
unsigned hash;
|
||||
struct hashset_entry *e;
|
||||
assert(h && key);
|
||||
|
|
@ -126,7 +126,7 @@ void* hashset_get(struct hashset *h, const void *key) {
|
|||
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;
|
||||
unsigned hash;
|
||||
assert(h && key);
|
||||
|
|
@ -140,6 +140,6 @@ int hashset_remove(struct hashset *h, const void *key) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
unsigned hashset_ncontents(struct hashset *h) {
|
||||
unsigned pa_hashset_ncontents(struct pa_hashset *h) {
|
||||
return h->n_entries;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
#ifndef 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));
|
||||
void hashset_free(struct hashset*, void (*free_func)(void *p, void *userdata), void *userdata);
|
||||
struct pa_hashset *pa_hashset_new(unsigned (*hash_func) (const void *p), int (*compare_func) (const void*a, const void*b));
|
||||
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);
|
||||
void* hashset_get(struct hashset *h, const void *key);
|
||||
int pa_hashset_put(struct pa_hashset *h, const void *key, void *value);
|
||||
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
|
||||
|
|
|
|||
54
src/idxset.c
54
src/idxset.c
|
|
@ -14,7 +14,7 @@ struct idxset_entry {
|
|||
struct idxset_entry* iterate_prev, *iterate_next;
|
||||
};
|
||||
|
||||
struct idxset {
|
||||
struct pa_idxset {
|
||||
unsigned (*hash_func) (const void *p);
|
||||
int (*compare_func)(const void *a, const void *b);
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ struct idxset {
|
|||
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;
|
||||
const char *c;
|
||||
|
||||
|
|
@ -33,25 +33,25 @@ unsigned idxset_string_hash_func(const void *p) {
|
|||
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);
|
||||
}
|
||||
|
||||
unsigned idxset_trivial_hash_func(const void *p) {
|
||||
unsigned pa_idxset_trivial_hash_func(const void *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;
|
||||
}
|
||||
|
||||
struct idxset* idxset_new(unsigned (*hash_func) (const void *p), int (*compare_func) (const void*a, const void*b)) {
|
||||
struct idxset *s;
|
||||
struct pa_idxset* pa_idxset_new(unsigned (*hash_func) (const void *p), int (*compare_func) (const void*a, const void*b)) {
|
||||
struct pa_idxset *s;
|
||||
|
||||
s = malloc(sizeof(struct idxset));
|
||||
s = malloc(sizeof(struct pa_idxset));
|
||||
assert(s);
|
||||
s->hash_func = hash_func ? hash_func : idxset_trivial_hash_func;
|
||||
s->compare_func = compare_func ? compare_func : idxset_trivial_compare_func;
|
||||
s->hash_func = hash_func ? hash_func : pa_idxset_trivial_hash_func;
|
||||
s->compare_func = compare_func ? compare_func : pa_idxset_trivial_compare_func;
|
||||
s->hash_table_size = 1023;
|
||||
s->hash_table = malloc(sizeof(struct idxset_entry*)*s->hash_table_size);
|
||||
assert(s->hash_table);
|
||||
|
|
@ -67,7 +67,7 @@ struct idxset* idxset_new(unsigned (*hash_func) (const void *p), int (*compare_f
|
|||
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);
|
||||
|
||||
if (free_func) {
|
||||
|
|
@ -86,7 +86,7 @@ void idxset_free(struct idxset *s, void (*free_func) (void *p, void *userdata),
|
|||
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(s->compare_func);
|
||||
|
|
@ -97,7 +97,7 @@ static struct idxset_entry* hash_scan(struct idxset *s, struct idxset_entry* e,
|
|||
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;
|
||||
struct idxset_entry** n;
|
||||
assert(index >= s->start_index);
|
||||
|
|
@ -124,7 +124,7 @@ static void extend_array(struct idxset *s, uint32_t index) {
|
|||
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)
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
struct idxset_entry *e, **a;
|
||||
assert(s && p);
|
||||
|
|
@ -191,7 +191,7 @@ int idxset_put(struct idxset*s, void *p, uint32_t *index) {
|
|||
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;
|
||||
assert(s);
|
||||
|
||||
|
|
@ -204,7 +204,7 @@ void* idxset_get_by_index(struct idxset*s, uint32_t index) {
|
|||
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;
|
||||
struct idxset_entry *e;
|
||||
assert(s && p);
|
||||
|
|
@ -222,7 +222,7 @@ void* idxset_get_by_data(struct idxset*s, void *p, uint32_t *index) {
|
|||
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;
|
||||
assert(s && e);
|
||||
|
||||
|
|
@ -257,7 +257,7 @@ static void remove_entry(struct idxset *s, struct idxset_entry *e) {
|
|||
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;
|
||||
void *data;
|
||||
|
||||
|
|
@ -272,7 +272,7 @@ void* idxset_remove_by_index(struct idxset*s, uint32_t index) {
|
|||
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;
|
||||
unsigned h;
|
||||
|
||||
|
|
@ -292,7 +292,7 @@ void* idxset_remove_by_data(struct idxset*s, void *data, uint32_t *index) {
|
|||
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;
|
||||
assert(s && index);
|
||||
|
||||
|
|
@ -309,7 +309,7 @@ void* idxset_rrobin(struct idxset *s, uint32_t *index) {
|
|||
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);
|
||||
|
||||
if (!s->iterate_list_head)
|
||||
|
|
@ -320,7 +320,7 @@ void* idxset_first(struct idxset *s, uint32_t *index) {
|
|||
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;
|
||||
assert(s && index);
|
||||
|
||||
|
|
@ -331,13 +331,13 @@ void *idxset_next(struct idxset *s, uint32_t *index) {
|
|||
*index = e->index;
|
||||
return e->data;
|
||||
} else {
|
||||
*index = IDXSET_INVALID;
|
||||
*index = PA_IDXSET_INVALID;
|
||||
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;
|
||||
assert(s && func);
|
||||
|
||||
|
|
@ -360,12 +360,12 @@ int idxset_foreach(struct idxset*s, int (*func)(void *p, uint32_t index, int *de
|
|||
return 0;
|
||||
}
|
||||
|
||||
unsigned idxset_ncontents(struct idxset*s) {
|
||||
unsigned pa_idxset_ncontents(struct pa_idxset*s) {
|
||||
assert(s);
|
||||
return s->n_entries;
|
||||
}
|
||||
|
||||
int idxset_isempty(struct idxset *s) {
|
||||
int pa_idxset_isempty(struct pa_idxset *s) {
|
||||
assert(s);
|
||||
return s->n_entries == 0;
|
||||
}
|
||||
|
|
|
|||
41
src/idxset.h
41
src/idxset.h
|
|
@ -3,41 +3,40 @@
|
|||
|
||||
#include <inttypes.h>
|
||||
|
||||
#define IDXSET_INVALID ((uint32_t) -1)
|
||||
#define PA_IDXSET_INVALID ((uint32_t) -1)
|
||||
|
||||
unsigned idxset_trivial_hash_func(const void *p);
|
||||
int idxset_trivial_compare_func(const void *a, const void *b);
|
||||
unsigned pa_idxset_trivial_hash_func(const void *p);
|
||||
int pa_idxset_trivial_compare_func(const void *a, const void *b);
|
||||
|
||||
unsigned idxset_string_hash_func(const void *p);
|
||||
int idxset_string_compare_func(const void *a, const void *b);
|
||||
unsigned pa_idxset_string_hash_func(const void *p);
|
||||
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));
|
||||
void idxset_free(struct idxset *s, void (*free_func) (void *p, void *userdata), void *userdata);
|
||||
struct pa_idxset* pa_idxset_new(unsigned (*hash_func) (const void *p), int (*compare_func) (const void*a, const void*b));
|
||||
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* idxset_get_by_data(struct idxset*s, void *p, uint32_t *index);
|
||||
void* pa_idxset_get_by_index(struct pa_idxset*s, 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* idxset_remove_by_data(struct idxset*s, void *p, uint32_t *index);
|
||||
void* pa_idxset_remove_by_index(struct pa_idxset*s, 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
|
||||
an invalid index value it returns the first entry, otherwise the
|
||||
next following. The function is best called with *index =
|
||||
IDXSET_VALID first. */
|
||||
void* idxset_rrobin(struct idxset *s, uint32_t *index);
|
||||
PA_IDXSET_VALID first. */
|
||||
void* pa_idxset_rrobin(struct pa_idxset *s, uint32_t *index);
|
||||
|
||||
/* Return the oldest entry in the idxset */
|
||||
void* idxset_first(struct idxset *s, uint32_t *index);
|
||||
void *idxset_next(struct idxset *s, uint32_t *index);
|
||||
void* pa_idxset_first(struct pa_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);
|
||||
|
||||
unsigned idxset_ncontents(struct idxset*s);
|
||||
int idxset_isempty(struct idxset *s);
|
||||
int pa_idxset_foreach(struct pa_idxset*s, int (*func)(void *p, uint32_t index, int *del, void*userdata), void *userdata);
|
||||
|
||||
unsigned pa_idxset_ncontents(struct pa_idxset*s);
|
||||
int pa_idxset_isempty(struct pa_idxset *s);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@
|
|||
#include "iochannel.h"
|
||||
#include "util.h"
|
||||
|
||||
struct iochannel {
|
||||
struct pa_iochannel {
|
||||
int ifd, ofd;
|
||||
struct pa_mainloop_api* mainloop;
|
||||
|
||||
void (*callback)(struct iochannel*io, void *userdata);
|
||||
void (*callback)(struct pa_iochannel*io, void *userdata);
|
||||
void*userdata;
|
||||
|
||||
int readable;
|
||||
|
|
@ -21,7 +21,7 @@ struct iochannel {
|
|||
void* input_source, *output_source;
|
||||
};
|
||||
|
||||
static void enable_mainloop_sources(struct iochannel *io) {
|
||||
static void enable_mainloop_sources(struct pa_iochannel *io) {
|
||||
assert(io);
|
||||
|
||||
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) {
|
||||
struct iochannel *io = userdata;
|
||||
struct pa_iochannel *io = userdata;
|
||||
int changed = 0;
|
||||
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 iochannel *io;
|
||||
struct pa_iochannel* pa_iochannel_new(struct pa_mainloop_api*m, int ifd, int ofd) {
|
||||
struct pa_iochannel *io;
|
||||
assert(m && (ifd >= 0 || ofd >= 0));
|
||||
|
||||
io = malloc(sizeof(struct iochannel));
|
||||
io = malloc(sizeof(struct pa_iochannel));
|
||||
io->ifd = ifd;
|
||||
io->ofd = ofd;
|
||||
io->mainloop = m;
|
||||
|
|
@ -84,18 +84,18 @@ struct iochannel* iochannel_new(struct pa_mainloop_api*m, int ifd, int ofd) {
|
|||
|
||||
if (ifd == ofd) {
|
||||
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);
|
||||
} else {
|
||||
|
||||
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);
|
||||
} else
|
||||
io->input_source = NULL;
|
||||
|
||||
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);
|
||||
} else
|
||||
io->output_source = NULL;
|
||||
|
|
@ -104,7 +104,7 @@ struct iochannel* iochannel_new(struct pa_mainloop_api*m, int ifd, int ofd) {
|
|||
return io;
|
||||
}
|
||||
|
||||
void iochannel_free(struct iochannel*io) {
|
||||
void pa_iochannel_free(struct pa_iochannel*io) {
|
||||
assert(io);
|
||||
|
||||
if (!io->no_close) {
|
||||
|
|
@ -122,17 +122,17 @@ void iochannel_free(struct iochannel*io) {
|
|||
free(io);
|
||||
}
|
||||
|
||||
int iochannel_is_readable(struct iochannel*io) {
|
||||
int pa_iochannel_is_readable(struct pa_iochannel*io) {
|
||||
assert(io);
|
||||
return io->readable;
|
||||
}
|
||||
|
||||
int iochannel_is_writable(struct iochannel*io) {
|
||||
int pa_iochannel_is_writable(struct pa_iochannel*io) {
|
||||
assert(io);
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
assert(io && data && io->ifd >= 0);
|
||||
|
|
@ -157,18 +157,18 @@ ssize_t iochannel_read(struct iochannel*io, void*data, size_t l) {
|
|||
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);
|
||||
io->callback = callback;
|
||||
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);
|
||||
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);
|
||||
peer_to_string(s, l, io->ifd);
|
||||
pa_peer_to_string(s, l, io->ifd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,21 +4,21 @@
|
|||
#include <sys/types.h>
|
||||
#include "mainloop-api.h"
|
||||
|
||||
struct iochannel;
|
||||
struct pa_iochannel;
|
||||
|
||||
struct iochannel* iochannel_new(struct pa_mainloop_api*m, int ifd, int ofd);
|
||||
void iochannel_free(struct iochannel*io);
|
||||
struct pa_iochannel* pa_iochannel_new(struct pa_mainloop_api*m, int ifd, int ofd);
|
||||
void pa_iochannel_free(struct pa_iochannel*io);
|
||||
|
||||
ssize_t iochannel_write(struct iochannel*io, const void*data, size_t l);
|
||||
ssize_t iochannel_read(struct iochannel*io, void*data, size_t l);
|
||||
ssize_t pa_iochannel_write(struct pa_iochannel*io, const 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 iochannel_is_writable(struct iochannel*io);
|
||||
int pa_iochannel_is_readable(struct pa_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
|
||||
|
|
|
|||
42
src/ioline.c
42
src/ioline.c
|
|
@ -9,8 +9,8 @@
|
|||
#define BUFFER_LIMIT (64*1024)
|
||||
#define READ_SIZE (1024)
|
||||
|
||||
struct ioline {
|
||||
struct iochannel *io;
|
||||
struct pa_ioline {
|
||||
struct pa_iochannel *io;
|
||||
int dead;
|
||||
|
||||
char *wbuf;
|
||||
|
|
@ -19,18 +19,18 @@ struct ioline {
|
|||
char *rbuf;
|
||||
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;
|
||||
};
|
||||
|
||||
static void io_callback(struct iochannel*io, void *userdata);
|
||||
static int do_write(struct ioline *l);
|
||||
static void io_callback(struct pa_iochannel*io, void *userdata);
|
||||
static int do_write(struct pa_ioline *l);
|
||||
|
||||
struct ioline* ioline_new(struct iochannel *io) {
|
||||
struct ioline *l;
|
||||
struct pa_ioline* pa_ioline_new(struct pa_iochannel *io) {
|
||||
struct pa_ioline *l;
|
||||
assert(io);
|
||||
|
||||
l = malloc(sizeof(struct ioline));
|
||||
l = malloc(sizeof(struct pa_ioline));
|
||||
assert(l);
|
||||
l->io = io;
|
||||
l->dead = 0;
|
||||
|
|
@ -44,20 +44,20 @@ struct ioline* ioline_new(struct iochannel *io) {
|
|||
l->callback = NULL;
|
||||
l->userdata = NULL;
|
||||
|
||||
iochannel_set_callback(io, io_callback, l);
|
||||
pa_iochannel_set_callback(io, io_callback, l);
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
void ioline_free(struct ioline *l) {
|
||||
void pa_ioline_free(struct pa_ioline *l) {
|
||||
assert(l);
|
||||
iochannel_free(l->io);
|
||||
pa_iochannel_free(l->io);
|
||||
free(l->wbuf);
|
||||
free(l->rbuf);
|
||||
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;
|
||||
assert(l && c);
|
||||
|
||||
|
|
@ -89,19 +89,19 @@ void ioline_puts(struct ioline *l, const char *c) {
|
|||
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);
|
||||
l->callback = callback;
|
||||
l->userdata = userdata;
|
||||
}
|
||||
|
||||
static int do_read(struct ioline *l) {
|
||||
static int do_read(struct pa_ioline *l) {
|
||||
ssize_t r;
|
||||
size_t m, len;
|
||||
char *e;
|
||||
assert(l);
|
||||
|
||||
if (!iochannel_is_readable(l->io))
|
||||
if (!pa_iochannel_is_readable(l->io))
|
||||
return 0;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static int do_write(struct ioline *l) {
|
||||
static int do_write(struct pa_ioline *l) {
|
||||
ssize_t r;
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
l->wbuf_valid_length -= r;
|
||||
|
|
@ -176,8 +176,8 @@ static int do_write(struct ioline *l) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void io_callback(struct iochannel*io, void *userdata) {
|
||||
struct ioline *l = userdata;
|
||||
static void io_callback(struct pa_iochannel*io, void *userdata) {
|
||||
struct pa_ioline *l = userdata;
|
||||
assert(io && l);
|
||||
|
||||
if (!l->dead && do_read(l) < 0)
|
||||
|
|
|
|||
10
src/ioline.h
10
src/ioline.h
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
#include "iochannel.h"
|
||||
|
||||
struct ioline;
|
||||
struct pa_ioline;
|
||||
|
||||
struct ioline* ioline_new(struct iochannel *io);
|
||||
void ioline_free(struct ioline *l);
|
||||
struct pa_ioline* pa_ioline_new(struct pa_iochannel *io);
|
||||
void pa_ioline_free(struct pa_ioline *l);
|
||||
|
||||
void ioline_puts(struct 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_puts(struct pa_ioline *s, const char *c);
|
||||
void pa_ioline_set_callback(struct pa_ioline*io, void (*callback)(struct pa_ioline*io, const char *s, void *userdata), void *userdata);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
28
src/main.c
28
src/main.c
|
|
@ -10,7 +10,7 @@
|
|||
#include "module.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;
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ static void signal_callback(void *id, int sig, void *userdata) {
|
|||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
struct core *c;
|
||||
struct pa_core *c;
|
||||
int r, retval = 0;
|
||||
|
||||
r = lt_dlinit();
|
||||
|
|
@ -35,26 +35,26 @@ int main(int argc, char *argv[]) {
|
|||
pa_signal_register(SIGINT, signal_callback, NULL);
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
c = core_new(pa_mainloop_get_api(mainloop));
|
||||
c = pa_core_new(pa_mainloop_get_api(mainloop));
|
||||
assert(c);
|
||||
|
||||
module_load(c, "module-oss-mmap", "/dev/dsp1");
|
||||
/* module_load(c, "module-pipe-sink", NULL);*/
|
||||
module_load(c, "module-simple-protocol-tcp", NULL);
|
||||
/* module_load(c, "module-simple-protocol-unix", NULL);
|
||||
module_load(c, "module-cli-protocol-tcp", NULL);
|
||||
module_load(c, "module-cli-protocol-unix", NULL);
|
||||
module_load(c, "module-native-protocol-tcp", NULL);*/
|
||||
module_load(c, "module-native-protocol-unix", NULL);
|
||||
/* module_load(c, "module-esound-protocol-tcp", NULL);*/
|
||||
module_load(c, "module-cli", NULL);
|
||||
pa_module_load(c, "module-oss", "/dev/dsp");
|
||||
/* pa_module_load(c, "module-pipe-sink", NULL);*/
|
||||
pa_module_load(c, "module-simple-protocol-tcp", NULL);
|
||||
/* pa_module_load(c, "module-simple-protocol-unix", NULL);
|
||||
pa_module_load(c, "module-cli-protocol-tcp", NULL);
|
||||
pa_module_load(c, "module-cli-protocol-unix", NULL);
|
||||
pa_module_load(c, "module-native-protocol-tcp", NULL);*/
|
||||
pa_module_load(c, "module-native-protocol-unix", NULL);
|
||||
/* pa_module_load(c, "module-esound-protocol-tcp", NULL);*/
|
||||
pa_module_load(c, "module-cli", NULL);
|
||||
|
||||
fprintf(stderr, "main: mainloop entry.\n");
|
||||
if (pa_mainloop_run(mainloop, &retval) < 0)
|
||||
retval = 1;
|
||||
fprintf(stderr, "main: mainloop exit.\n");
|
||||
|
||||
core_free(c);
|
||||
pa_core_free(c);
|
||||
|
||||
pa_signal_done();
|
||||
pa_mainloop_free(mainloop);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#ifndef foomainhfoo
|
||||
#define foomainhfoo
|
||||
|
||||
extern int stdin_inuse, stdout_inuse;
|
||||
extern int pa_stdin_inuse, pa_stdout_inuse;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@ int pa_signal_init(struct pa_mainloop_api *a) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
make_nonblock_fd(signal_pipe[0]);
|
||||
make_nonblock_fd(signal_pipe[1]);
|
||||
pa_make_nonblock_fd(signal_pipe[0]);
|
||||
pa_make_nonblock_fd(signal_pipe[1]);
|
||||
|
||||
api = a;
|
||||
mainloop_source = api->source_io(api, signal_pipe[0], PA_MAINLOOP_API_IO_EVENT_INPUT, callback, NULL);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ struct mainloop_source_time {
|
|||
};
|
||||
|
||||
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;
|
||||
|
||||
struct pollfd *pollfds;
|
||||
|
|
@ -65,10 +65,10 @@ struct pa_mainloop *pa_mainloop_new(void) {
|
|||
m = malloc(sizeof(struct pa_mainloop));
|
||||
assert(m);
|
||||
|
||||
m->io_sources = idxset_new(NULL, NULL);
|
||||
m->fixed_sources = idxset_new(NULL, NULL);
|
||||
m->idle_sources = idxset_new(NULL, NULL);
|
||||
m->time_sources = idxset_new(NULL, NULL);
|
||||
m->io_sources = pa_idxset_new(NULL, NULL);
|
||||
m->fixed_sources = pa_idxset_new(NULL, NULL);
|
||||
m->idle_sources = pa_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);
|
||||
|
||||
|
|
@ -100,15 +100,15 @@ static int foreach(void *p, uint32_t index, int *del, void*userdata) {
|
|||
void pa_mainloop_free(struct pa_mainloop* m) {
|
||||
int all = 1;
|
||||
assert(m);
|
||||
idxset_foreach(m->io_sources, foreach, &all);
|
||||
idxset_foreach(m->fixed_sources, foreach, &all);
|
||||
idxset_foreach(m->idle_sources, foreach, &all);
|
||||
idxset_foreach(m->time_sources, foreach, &all);
|
||||
pa_idxset_foreach(m->io_sources, foreach, &all);
|
||||
pa_idxset_foreach(m->fixed_sources, foreach, &all);
|
||||
pa_idxset_foreach(m->idle_sources, foreach, &all);
|
||||
pa_idxset_foreach(m->time_sources, foreach, &all);
|
||||
|
||||
idxset_free(m->io_sources, NULL, NULL);
|
||||
idxset_free(m->fixed_sources, NULL, NULL);
|
||||
idxset_free(m->idle_sources, NULL, NULL);
|
||||
idxset_free(m->time_sources, NULL, NULL);
|
||||
pa_idxset_free(m->io_sources, NULL, NULL);
|
||||
pa_idxset_free(m->fixed_sources, NULL, NULL);
|
||||
pa_idxset_free(m->idle_sources, NULL, NULL);
|
||||
pa_idxset_free(m->time_sources, NULL, NULL);
|
||||
|
||||
free(m->pollfds);
|
||||
free(m);
|
||||
|
|
@ -118,22 +118,22 @@ static void scan_dead(struct pa_mainloop *m) {
|
|||
int all = 0;
|
||||
assert(m);
|
||||
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)
|
||||
idxset_foreach(m->fixed_sources, foreach, &all);
|
||||
pa_idxset_foreach(m->fixed_sources, foreach, &all);
|
||||
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)
|
||||
idxset_foreach(m->time_sources, foreach, &all);
|
||||
pa_idxset_foreach(m->time_sources, foreach, &all);
|
||||
}
|
||||
|
||||
static void rebuild_pollfds(struct pa_mainloop *m) {
|
||||
struct mainloop_source_io*s;
|
||||
struct pollfd *p;
|
||||
uint32_t index = IDXSET_INVALID;
|
||||
uint32_t index = PA_IDXSET_INVALID;
|
||||
unsigned l;
|
||||
|
||||
l = idxset_ncontents(m->io_sources);
|
||||
l = pa_idxset_ncontents(m->io_sources);
|
||||
if (m->max_pollfds < l) {
|
||||
m->pollfds = realloc(m->pollfds, sizeof(struct pollfd)*l);
|
||||
m->max_pollfds = l;
|
||||
|
|
@ -141,7 +141,7 @@ static void rebuild_pollfds(struct pa_mainloop *m) {
|
|||
|
||||
m->n_pollfds = 0;
|
||||
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) {
|
||||
s->pollfd = NULL;
|
||||
continue;
|
||||
|
|
@ -158,10 +158,10 @@ static void rebuild_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;
|
||||
|
||||
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)
|
||||
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) {
|
||||
uint32_t index = IDXSET_INVALID;
|
||||
static void run_fixed_or_idle(struct pa_mainloop *m, struct pa_idxset *i) {
|
||||
uint32_t index = PA_IDXSET_INVALID;
|
||||
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)
|
||||
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) {
|
||||
uint32_t index = IDXSET_INVALID;
|
||||
uint32_t index = PA_IDXSET_INVALID;
|
||||
struct mainloop_source_time *s;
|
||||
struct timeval now;
|
||||
int t = -1;
|
||||
|
||||
if (idxset_isempty(m->time_sources))
|
||||
if (pa_idxset_isempty(m->time_sources))
|
||||
return -1;
|
||||
|
||||
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;
|
||||
|
||||
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) {
|
||||
uint32_t index = IDXSET_INVALID;
|
||||
uint32_t index = PA_IDXSET_INVALID;
|
||||
struct mainloop_source_time *s;
|
||||
struct timeval now;
|
||||
assert(m);
|
||||
|
||||
if (idxset_isempty(m->time_sources))
|
||||
if (pa_idxset_isempty(m->time_sources))
|
||||
return;
|
||||
|
||||
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)
|
||||
continue;
|
||||
|
|
@ -251,7 +251,7 @@ static int any_idle_sources(struct pa_mainloop *m) {
|
|||
uint32_t index;
|
||||
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)
|
||||
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->pollfd = NULL;
|
||||
|
||||
idxset_put(m->io_sources, s, NULL);
|
||||
pa_idxset_put(m->io_sources, s, NULL);
|
||||
m->rebuild_pollfds = 1;
|
||||
return s;
|
||||
}
|
||||
|
|
@ -380,7 +380,7 @@ static void* mainloop_source_fixed(struct pa_mainloop_api*a, void (*callback) (s
|
|||
s->callback = callback;
|
||||
s->userdata = userdata;
|
||||
|
||||
idxset_put(m->fixed_sources, s, NULL);
|
||||
pa_idxset_put(m->fixed_sources, s, NULL);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
@ -422,7 +422,7 @@ static void* mainloop_source_idle(struct pa_mainloop_api*a, void (*callback) (st
|
|||
s->callback = callback;
|
||||
s->userdata = userdata;
|
||||
|
||||
idxset_put(m->idle_sources, s, NULL);
|
||||
pa_idxset_put(m->idle_sources, s, NULL);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
@ -457,7 +457,7 @@ static void* mainloop_source_time(struct pa_mainloop_api*a, const struct timeval
|
|||
s->callback = callback;
|
||||
s->userdata = userdata;
|
||||
|
||||
idxset_put(m->time_sources, s, NULL);
|
||||
pa_idxset_put(m->time_sources, s, NULL);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,69 +5,69 @@
|
|||
|
||||
#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 memblock *b = malloc(sizeof(struct memblock)+length);
|
||||
b->type = MEMBLOCK_APPENDED;
|
||||
struct pa_memblock *pa_memblock_new(size_t length) {
|
||||
struct pa_memblock *b = malloc(sizeof(struct pa_memblock)+length);
|
||||
b->type = PA_MEMBLOCK_APPENDED;
|
||||
b->ref = 1;
|
||||
b->length = length;
|
||||
b->data = b+1;
|
||||
memblock_count++;
|
||||
memblock_total += length;
|
||||
pa_memblock_count++;
|
||||
pa_memblock_total += length;
|
||||
return b;
|
||||
}
|
||||
|
||||
struct memblock *memblock_new_fixed(void *d, size_t length) {
|
||||
struct memblock *b = malloc(sizeof(struct memblock));
|
||||
b->type = MEMBLOCK_FIXED;
|
||||
struct pa_memblock *pa_memblock_new_fixed(void *d, size_t length) {
|
||||
struct pa_memblock *b = malloc(sizeof(struct pa_memblock));
|
||||
b->type = PA_MEMBLOCK_FIXED;
|
||||
b->ref = 1;
|
||||
b->length = length;
|
||||
b->data = d;
|
||||
memblock_count++;
|
||||
memblock_total += length;
|
||||
pa_memblock_count++;
|
||||
pa_memblock_total += length;
|
||||
return b;
|
||||
}
|
||||
|
||||
struct memblock *memblock_new_dynamic(void *d, size_t length) {
|
||||
struct memblock *b = malloc(sizeof(struct memblock));
|
||||
b->type = MEMBLOCK_DYNAMIC;
|
||||
struct pa_memblock *pa_memblock_new_dynamic(void *d, size_t length) {
|
||||
struct pa_memblock *b = malloc(sizeof(struct pa_memblock));
|
||||
b->type = PA_MEMBLOCK_DYNAMIC;
|
||||
b->ref = 1;
|
||||
b->length = length;
|
||||
b->data = d;
|
||||
memblock_count++;
|
||||
memblock_total += length;
|
||||
pa_memblock_count++;
|
||||
pa_memblock_total += length;
|
||||
return b;
|
||||
}
|
||||
|
||||
struct memblock* memblock_ref(struct memblock*b) {
|
||||
struct pa_memblock* pa_memblock_ref(struct pa_memblock*b) {
|
||||
assert(b && b->ref >= 1);
|
||||
b->ref++;
|
||||
return b;
|
||||
}
|
||||
|
||||
void memblock_unref(struct memblock*b) {
|
||||
void pa_memblock_unref(struct pa_memblock*b) {
|
||||
assert(b && b->ref >= 1);
|
||||
b->ref--;
|
||||
|
||||
if (b->ref == 0) {
|
||||
if (b->type == MEMBLOCK_DYNAMIC)
|
||||
if (b->type == PA_MEMBLOCK_DYNAMIC)
|
||||
free(b->data);
|
||||
|
||||
memblock_count--;
|
||||
memblock_total -= b->length;
|
||||
pa_memblock_count--;
|
||||
pa_memblock_total -= b->length;
|
||||
|
||||
free(b);
|
||||
}
|
||||
}
|
||||
|
||||
void memblock_unref_fixed(struct memblock *b) {
|
||||
void pa_memblock_unref_fixed(struct pa_memblock *b) {
|
||||
void *d;
|
||||
|
||||
assert(b && b->ref >= 1);
|
||||
|
||||
if (b->ref == 1) {
|
||||
memblock_unref(b);
|
||||
pa_memblock_unref(b);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -75,6 +75,6 @@ void memblock_unref_fixed(struct memblock *b) {
|
|||
assert(d);
|
||||
memcpy(d, b->data, b->length);
|
||||
b->data = d;
|
||||
b->type = MEMBLOCK_DYNAMIC;
|
||||
b->type = PA_MEMBLOCK_DYNAMIC;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,26 +4,26 @@
|
|||
#include <sys/types.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 {
|
||||
enum memblock_type type;
|
||||
struct pa_memblock {
|
||||
enum pa_memblock_type type;
|
||||
unsigned ref;
|
||||
size_t length;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct memblock *memblock_new(size_t length);
|
||||
struct memblock *memblock_new_fixed(void *data, size_t length);
|
||||
struct memblock *memblock_new_dynamic(void *data, size_t length);
|
||||
struct pa_memblock *pa_memblock_new(size_t length);
|
||||
struct pa_memblock *pa_memblock_new_fixed(void *data, size_t length);
|
||||
struct pa_memblock *pa_memblock_new_dynamic(void *data, size_t length);
|
||||
|
||||
void memblock_unref(struct memblock*b);
|
||||
struct memblock* memblock_ref(struct memblock*b);
|
||||
void pa_memblock_unref(struct pa_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
|
||||
|
|
|
|||
|
|
@ -8,24 +8,24 @@
|
|||
|
||||
struct memblock_list {
|
||||
struct memblock_list *next;
|
||||
struct memchunk chunk;
|
||||
struct pa_memchunk chunk;
|
||||
struct timeval stamp;
|
||||
};
|
||||
|
||||
struct memblockq {
|
||||
struct pa_memblockq {
|
||||
struct memblock_list *blocks, *blocks_tail;
|
||||
unsigned n_blocks;
|
||||
size_t total_length, maxlength, base, prebuf;
|
||||
int measure_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 memblockq* bq;
|
||||
struct pa_memblockq* pa_memblockq_new(size_t maxlength, size_t base, size_t prebuf) {
|
||||
struct pa_memblockq* bq;
|
||||
assert(maxlength && base);
|
||||
|
||||
bq = malloc(sizeof(struct memblockq));
|
||||
bq = malloc(sizeof(struct pa_memblockq));
|
||||
assert(bq);
|
||||
bq->blocks = bq->blocks_tail = 0;
|
||||
bq->n_blocks = 0;
|
||||
|
|
@ -47,23 +47,23 @@ struct memblockq* memblockq_new(size_t maxlength, size_t base, size_t prebuf) {
|
|||
return bq;
|
||||
}
|
||||
|
||||
void memblockq_free(struct memblockq* bq) {
|
||||
void pa_memblockq_free(struct pa_memblockq* bq) {
|
||||
struct memblock_list *l;
|
||||
assert(bq);
|
||||
|
||||
if (bq->mcalign)
|
||||
mcalign_free(bq->mcalign);
|
||||
pa_mcalign_free(bq->mcalign);
|
||||
|
||||
while ((l = bq->blocks)) {
|
||||
bq->blocks = l->next;
|
||||
memblock_unref(l->chunk.memblock);
|
||||
pa_memblock_unref(l->chunk.memblock);
|
||||
free(l);
|
||||
}
|
||||
|
||||
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;
|
||||
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);
|
||||
|
||||
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);
|
||||
q->next = NULL;
|
||||
|
||||
|
|
@ -90,10 +90,10 @@ void memblockq_push(struct memblockq* bq, const struct memchunk *chunk, size_t d
|
|||
bq->n_blocks++;
|
||||
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);
|
||||
|
||||
if (!bq->blocks || bq->total_length < bq->prebuf)
|
||||
|
|
@ -102,16 +102,16 @@ int memblockq_peek(struct memblockq* bq, struct memchunk *chunk) {
|
|||
bq->prebuf = 0;
|
||||
|
||||
*chunk = bq->blocks->chunk;
|
||||
memblock_ref(chunk->memblock);
|
||||
pa_memblock_ref(chunk->memblock);
|
||||
|
||||
if (chunk->memblock->ref != 2)
|
||||
fprintf(stderr, "block %p with ref %u peeked.\n", chunk->memblock, chunk->memblock->ref);
|
||||
/* if (chunk->memblock->ref != 2) */
|
||||
/* fprintf(stderr, "block %p with ref %u peeked.\n", chunk->memblock, chunk->memblock->ref); */
|
||||
|
||||
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;
|
||||
|
||||
assert(bq && chunk);
|
||||
|
|
@ -154,7 +154,7 @@ static uint32_t age(struct timeval *tv) {
|
|||
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);
|
||||
|
||||
while (length > 0) {
|
||||
|
|
@ -178,7 +178,7 @@ void memblockq_drop(struct memblockq *bq, size_t length) {
|
|||
bq->blocks = bq->blocks->next;
|
||||
if (bq->blocks == NULL)
|
||||
bq->blocks_tail = NULL;
|
||||
memblock_unref(q->chunk.memblock);
|
||||
pa_memblock_unref(q->chunk.memblock);
|
||||
free(q);
|
||||
|
||||
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;
|
||||
assert(bq);
|
||||
|
||||
if (bq->total_length <= length)
|
||||
return;
|
||||
|
||||
fprintf(stderr, "Warning! memblockq_shorten()\n");
|
||||
fprintf(stderr, "Warning! pa_memblockq_shorten()\n");
|
||||
|
||||
l = bq->total_length - length;
|
||||
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);
|
||||
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);
|
||||
|
||||
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(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);
|
||||
return bq->delay;
|
||||
}
|
||||
|
||||
uint32_t memblockq_get_length(struct memblockq *bq) {
|
||||
uint32_t pa_memblockq_get_length(struct pa_memblockq *bq) {
|
||||
assert(bq);
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void memblockq_push_align(struct memblockq* bq, const struct memchunk *chunk, size_t delta) {
|
||||
struct memchunk rchunk;
|
||||
void pa_memblockq_push_align(struct pa_memblockq* bq, const struct pa_memchunk *chunk, size_t delta) {
|
||||
struct pa_memchunk rchunk;
|
||||
assert(bq && chunk && bq->base);
|
||||
|
||||
if (bq->base == 1) {
|
||||
memblockq_push(bq, chunk, delta);
|
||||
pa_memblockq_push(bq, chunk, delta);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bq->mcalign) {
|
||||
bq->mcalign = mcalign_new(bq->base);
|
||||
bq->mcalign = pa_mcalign_new(bq->base);
|
||||
assert(bq->mcalign);
|
||||
}
|
||||
|
||||
mcalign_push(bq->mcalign, chunk);
|
||||
pa_mcalign_push(bq->mcalign, chunk);
|
||||
|
||||
while (mcalign_pop(bq->mcalign, &rchunk) >= 0) {
|
||||
memblockq_push(bq, &rchunk, delta);
|
||||
memblock_unref(rchunk.memblock);
|
||||
while (pa_mcalign_pop(bq->mcalign, &rchunk) >= 0) {
|
||||
pa_memblockq_push(bq, &rchunk, delta);
|
||||
pa_memblock_unref(rchunk.memblock);
|
||||
delta = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,46 +6,46 @@
|
|||
#include "memblock.h"
|
||||
#include "memchunk.h"
|
||||
|
||||
struct memblockq;
|
||||
struct pa_memblockq;
|
||||
|
||||
/* Parameters: the maximum length of the memblock queue, a base value
|
||||
for all operations (that is, all byte operations shall work on
|
||||
multiples of this base value) and an amount of bytes to prebuffer
|
||||
before having memblockq_peek() succeed. */
|
||||
struct memblockq* memblockq_new(size_t maxlength, size_t base, size_t prebuf);
|
||||
void memblockq_free(struct memblockq*bq);
|
||||
before having pa_memblockq_peek() succeed. */
|
||||
struct pa_memblockq* pa_memblockq_new(size_t maxlength, size_t base, size_t prebuf);
|
||||
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! */
|
||||
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 */
|
||||
void memblockq_push_align(struct memblockq* bq, const struct memchunk *chunk, size_t delta);
|
||||
/* Same as pa_memblockq_push(), however chunks are filtered through a mcalign object, and thus aligned to multiples of base */
|
||||
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 */
|
||||
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 */
|
||||
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 */
|
||||
void memblockq_shorten(struct memblockq *bq, size_t length);
|
||||
/* Shorten the pa_memblockq to the specified length by dropping data at the end of the queue */
|
||||
void pa_memblockq_shorten(struct pa_memblockq *bq, size_t length);
|
||||
|
||||
/* Empty the memblockq */
|
||||
void memblockq_empty(struct memblockq *bq);
|
||||
/* Empty the pa_memblockq */
|
||||
void pa_memblockq_empty(struct pa_memblockq *bq);
|
||||
|
||||
/* Test if the memblockq is currently readable, that is, more data than base */
|
||||
int memblockq_is_readable(struct memblockq *bq);
|
||||
/* Test if the pa_memblockq is currently readable, that is, more data than base */
|
||||
int pa_memblockq_is_readable(struct pa_memblockq *bq);
|
||||
|
||||
/* Test if the memblockq is currently writable for the specified amount of bytes */
|
||||
int memblockq_is_writable(struct memblockq *bq, size_t length);
|
||||
/* Test if the pa_memblockq is currently writable for the specified amount of bytes */
|
||||
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 */
|
||||
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 */
|
||||
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 */
|
||||
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
|
||||
|
|
|
|||
|
|
@ -5,34 +5,34 @@
|
|||
|
||||
#include "memchunk.h"
|
||||
|
||||
void memchunk_make_writable(struct memchunk *c) {
|
||||
struct memblock *n;
|
||||
void pa_memchunk_make_writable(struct pa_memchunk *c) {
|
||||
struct pa_memblock *n;
|
||||
assert(c && c->memblock && c->memblock->ref >= 1);
|
||||
|
||||
if (c->memblock->ref == 1)
|
||||
return;
|
||||
|
||||
n = memblock_new(c->length);
|
||||
n = pa_memblock_new(c->length);
|
||||
assert(n);
|
||||
memcpy(n->data, c->memblock->data+c->index, c->length);
|
||||
memblock_unref(c->memblock);
|
||||
pa_memblock_unref(c->memblock);
|
||||
c->memblock = n;
|
||||
c->index = 0;
|
||||
}
|
||||
|
||||
|
||||
struct mcalign {
|
||||
struct pa_mcalign {
|
||||
size_t base;
|
||||
struct memchunk chunk;
|
||||
struct pa_memchunk chunk;
|
||||
uint8_t *buffer;
|
||||
size_t buffer_fill;
|
||||
};
|
||||
|
||||
struct mcalign *mcalign_new(size_t base) {
|
||||
struct mcalign *m;
|
||||
struct pa_mcalign *pa_mcalign_new(size_t base) {
|
||||
struct pa_mcalign *m;
|
||||
assert(base);
|
||||
|
||||
m = malloc(sizeof(struct mcalign));
|
||||
m = malloc(sizeof(struct pa_mcalign));
|
||||
assert(m);
|
||||
m->base = base;
|
||||
m->chunk.memblock = NULL;
|
||||
|
|
@ -42,25 +42,25 @@ struct mcalign *mcalign_new(size_t base) {
|
|||
return m;
|
||||
}
|
||||
|
||||
void mcalign_free(struct mcalign *m) {
|
||||
void pa_mcalign_free(struct pa_mcalign *m) {
|
||||
assert(m);
|
||||
|
||||
free(m->buffer);
|
||||
|
||||
if (m->chunk.memblock)
|
||||
memblock_unref(m->chunk.memblock);
|
||||
pa_memblock_unref(m->chunk.memblock);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
int ret;
|
||||
|
||||
|
|
@ -80,13 +80,13 @@ int mcalign_pop(struct mcalign *m, struct memchunk *c) {
|
|||
|
||||
if (m->chunk.length == 0) {
|
||||
m->chunk.length = m->chunk.index = 0;
|
||||
memblock_unref(m->chunk.memblock);
|
||||
pa_memblock_unref(m->chunk.memblock);
|
||||
m->chunk.memblock = NULL;
|
||||
}
|
||||
|
||||
assert(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);
|
||||
c->index = 0;
|
||||
c->length = m->base;
|
||||
|
|
@ -111,13 +111,13 @@ int mcalign_pop(struct mcalign *m, struct memchunk *c) {
|
|||
|
||||
if (m->chunk.length) {
|
||||
*c = m->chunk;
|
||||
memblock_ref(c->memblock);
|
||||
pa_memblock_ref(c->memblock);
|
||||
ret = 0;
|
||||
} else
|
||||
ret = -1;
|
||||
|
||||
m->chunk.length = m->chunk.index = 0;
|
||||
memblock_unref(m->chunk.memblock);
|
||||
pa_memblock_unref(m->chunk.memblock);
|
||||
m->chunk.memblock = NULL;
|
||||
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -3,18 +3,18 @@
|
|||
|
||||
#include "memblock.h"
|
||||
|
||||
struct memchunk {
|
||||
struct memblock *memblock;
|
||||
struct pa_memchunk {
|
||||
struct pa_memblock *memblock;
|
||||
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);
|
||||
void mcalign_free(struct mcalign *m);
|
||||
void mcalign_push(struct mcalign *m, const struct memchunk *c);
|
||||
int mcalign_pop(struct mcalign *m, struct memchunk *c);
|
||||
struct pa_mcalign *pa_mcalign_new(size_t base);
|
||||
void pa_mcalign_free(struct pa_mcalign *m);
|
||||
void pa_mcalign_push(struct pa_mcalign *m, const struct pa_memchunk *c);
|
||||
int pa_mcalign_pop(struct pa_mcalign *m, struct pa_memchunk *c);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,29 +7,29 @@
|
|||
#include "iochannel.h"
|
||||
#include "cli.h"
|
||||
|
||||
int module_init(struct core *c, struct module*m) {
|
||||
struct iochannel *io;
|
||||
int module_init(struct pa_core *c, struct pa_module*m) {
|
||||
struct pa_iochannel *io;
|
||||
assert(c && m);
|
||||
|
||||
if (stdin_inuse || stdout_inuse) {
|
||||
if (pa_stdin_inuse || pa_stdout_inuse) {
|
||||
fprintf(stderr, "STDIN/STDUSE already used\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
stdin_inuse = stdout_inuse = 1;
|
||||
io = iochannel_new(c->mainloop, STDIN_FILENO, STDOUT_FILENO);
|
||||
pa_stdin_inuse = pa_stdout_inuse = 1;
|
||||
io = pa_iochannel_new(c->mainloop, STDIN_FILENO, STDOUT_FILENO);
|
||||
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);
|
||||
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);
|
||||
|
||||
cli_free(m->userdata);
|
||||
assert(stdin_inuse && stdout_inuse);
|
||||
stdin_inuse = stdout_inuse = 0;
|
||||
pa_cli_free(m->userdata);
|
||||
assert(pa_stdin_inuse && pa_stdout_inuse);
|
||||
pa_stdin_inuse = pa_stdout_inuse = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@
|
|||
#include "sample-util.h"
|
||||
|
||||
struct userdata {
|
||||
struct sink *sink;
|
||||
struct source *source;
|
||||
struct core *core;
|
||||
struct pa_sink *sink;
|
||||
struct pa_source *source;
|
||||
struct pa_core *core;
|
||||
struct pa_sample_spec sample_spec;
|
||||
|
||||
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;
|
||||
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;
|
||||
};
|
||||
|
||||
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) {
|
||||
unsigned i = u->out_current;
|
||||
|
|
@ -48,7 +48,7 @@ static void out_clear_memblocks(struct userdata*u, unsigned n) {
|
|||
|
||||
while (n > 0) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -64,15 +64,15 @@ static void out_fill_memblocks(struct userdata *u, unsigned n) {
|
|||
assert(u && u->out_memblocks);
|
||||
|
||||
while (n > 0) {
|
||||
struct memchunk chunk;
|
||||
struct pa_memchunk chunk;
|
||||
|
||||
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.index = 0;
|
||||
|
||||
sink_render_into_full(u->sink, &chunk);
|
||||
pa_sink_render_into_full(u->sink, &chunk);
|
||||
}
|
||||
|
||||
u->out_current++;
|
||||
|
|
@ -106,14 +106,14 @@ static void in_post_memblocks(struct userdata *u, unsigned n) {
|
|||
assert(u && u->in_memblocks);
|
||||
|
||||
while (n > 0) {
|
||||
struct memchunk chunk;
|
||||
struct pa_memchunk chunk;
|
||||
|
||||
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.index = 0;
|
||||
|
||||
source_post(u->source, &chunk);
|
||||
pa_source_post(u->source, &chunk);
|
||||
}
|
||||
|
||||
u->in_current++;
|
||||
|
|
@ -133,7 +133,7 @@ static void in_clear_memblocks(struct userdata*u, unsigned n) {
|
|||
|
||||
while (n > 0) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -172,7 +172,7 @@ static void io_callback(struct pa_mainloop_api *m, void *id, int fd, enum pa_mai
|
|||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
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 userdata *u = NULL;
|
||||
char *p;
|
||||
|
|
@ -240,7 +240,7 @@ int module_init(struct core *c, struct module*m) {
|
|||
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;
|
||||
|
||||
if (mode != O_WRONLY) {
|
||||
|
|
@ -262,12 +262,12 @@ int module_init(struct core *c, struct module*m) {
|
|||
}
|
||||
} 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);
|
||||
u->source->userdata = u;
|
||||
|
||||
u->in_memblocks = malloc(sizeof(struct memblock *)*u->in_fragments);
|
||||
memset(u->in_memblocks, 0, sizeof(struct memblock *)*u->in_fragments);
|
||||
u->in_memblocks = malloc(sizeof(struct pa_memblock *)*u->in_fragments);
|
||||
memset(u->in_memblocks, 0, sizeof(struct pa_memblock *)*u->in_fragments);
|
||||
|
||||
enable_bits |= PCM_ENABLE_INPUT;
|
||||
}
|
||||
|
|
@ -291,15 +291,15 @@ int module_init(struct core *c, struct module*m) {
|
|||
goto fail;
|
||||
}
|
||||
} 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);
|
||||
u->sink->get_latency = sink_get_latency_cb;
|
||||
u->sink->userdata = u;
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
@ -329,7 +329,7 @@ fail:
|
|||
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;
|
||||
assert(c && m);
|
||||
|
||||
|
|
@ -353,10 +353,10 @@ void module_done(struct core *c, struct module*m) {
|
|||
munmap(u->out_mmap, u->out_mmap_length);
|
||||
|
||||
if (u->sink)
|
||||
sink_free(u->sink);
|
||||
pa_sink_free(u->sink);
|
||||
|
||||
if (u->source)
|
||||
source_free(u->source);
|
||||
pa_source_free(u->source);
|
||||
|
||||
if (u->mainloop_source)
|
||||
u->core->mainloop->cancel_io(u->core->mainloop, u->mainloop_source);
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@
|
|||
#include "sample-util.h"
|
||||
|
||||
struct userdata {
|
||||
struct sink *sink;
|
||||
struct source *source;
|
||||
struct iochannel *io;
|
||||
struct core *core;
|
||||
struct pa_sink *sink;
|
||||
struct pa_source *source;
|
||||
struct pa_iochannel *io;
|
||||
struct pa_core *core;
|
||||
|
||||
struct memchunk memchunk, silence;
|
||||
struct pa_memchunk memchunk, silence;
|
||||
|
||||
uint32_t in_fragment_size, out_fragment_size, sample_size;
|
||||
|
||||
|
|
@ -31,15 +31,15 @@ struct userdata {
|
|||
};
|
||||
|
||||
static void do_write(struct userdata *u) {
|
||||
struct memchunk *memchunk;
|
||||
struct pa_memchunk *memchunk;
|
||||
ssize_t r;
|
||||
assert(u);
|
||||
|
||||
if (!u->sink || !iochannel_is_writable(u->io))
|
||||
if (!u->sink || !pa_iochannel_is_writable(u->io))
|
||||
return;
|
||||
|
||||
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;
|
||||
else
|
||||
memchunk = &u->memchunk;
|
||||
|
|
@ -47,7 +47,7 @@ static void do_write(struct userdata *u) {
|
|||
|
||||
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));
|
||||
return;
|
||||
}
|
||||
|
|
@ -59,24 +59,24 @@ static void do_write(struct userdata *u) {
|
|||
u->memchunk.length -= r;
|
||||
|
||||
if (u->memchunk.length <= 0) {
|
||||
memblock_unref(u->memchunk.memblock);
|
||||
pa_memblock_unref(u->memchunk.memblock);
|
||||
u->memchunk.memblock = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void do_read(struct userdata *u) {
|
||||
struct memchunk memchunk;
|
||||
struct pa_memchunk memchunk;
|
||||
ssize_t r;
|
||||
assert(u);
|
||||
|
||||
if (!u->source || !iochannel_is_readable(u->io))
|
||||
if (!u->source || !pa_iochannel_is_readable(u->io))
|
||||
return;
|
||||
|
||||
memchunk.memblock = memblock_new(u->in_fragment_size);
|
||||
memchunk.memblock = pa_memblock_new(u->in_fragment_size);
|
||||
assert(memchunk.memblock);
|
||||
if ((r = iochannel_read(u->io, memchunk.memblock->data, memchunk.memblock->length)) < 0) {
|
||||
memblock_unref(memchunk.memblock);
|
||||
if ((r = pa_iochannel_read(u->io, memchunk.memblock->data, memchunk.memblock->length)) < 0) {
|
||||
pa_memblock_unref(memchunk.memblock);
|
||||
fprintf(stderr, "read() failed: %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
|
@ -85,18 +85,18 @@ static void do_read(struct userdata *u) {
|
|||
memchunk.length = memchunk.memblock->length = r;
|
||||
memchunk.index = 0;
|
||||
|
||||
source_post(u->source, &memchunk);
|
||||
memblock_unref(memchunk.memblock);
|
||||
pa_source_post(u->source, &memchunk);
|
||||
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;
|
||||
assert(u);
|
||||
do_write(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;
|
||||
struct userdata *u = s->userdata;
|
||||
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);
|
||||
}
|
||||
|
||||
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 userdata *u = NULL;
|
||||
char *p;
|
||||
|
|
@ -154,7 +154,7 @@ int module_init(struct core *c, struct module*m) {
|
|||
goto fail;
|
||||
}
|
||||
|
||||
if (oss_auto_format(fd, &ss) < 0)
|
||||
if (pa_oss_auto_format(fd, &ss) < 0)
|
||||
goto fail;
|
||||
|
||||
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;
|
||||
|
||||
if (mode != O_RDONLY) {
|
||||
u->sink = sink_new(c, "dsp", 0, &ss);
|
||||
u->sink = pa_sink_new(c, "dsp", 0, &ss);
|
||||
assert(u->sink);
|
||||
u->sink->get_latency = sink_get_latency_cb;
|
||||
u->sink->userdata = u;
|
||||
|
|
@ -188,7 +188,7 @@ int module_init(struct core *c, struct module*m) {
|
|||
u->sink = NULL;
|
||||
|
||||
if (mode != O_WRONLY) {
|
||||
u->source = source_new(c, "dsp", 0, &ss);
|
||||
u->source = pa_source_new(c, "dsp", 0, &ss);
|
||||
assert(u->source);
|
||||
u->source->userdata = u;
|
||||
} else
|
||||
|
|
@ -196,9 +196,9 @@ int module_init(struct core *c, struct module*m) {
|
|||
|
||||
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);
|
||||
iochannel_set_callback(u->io, io_callback, u);
|
||||
pa_iochannel_set_callback(u->io, io_callback, u);
|
||||
u->fd = fd;
|
||||
|
||||
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->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);
|
||||
silence_memblock(u->silence.memblock, &ss);
|
||||
pa_silence_memblock(u->silence.memblock, &ss);
|
||||
u->silence.index = 0;
|
||||
|
||||
m->userdata = u;
|
||||
|
|
@ -223,7 +223,7 @@ fail:
|
|||
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;
|
||||
assert(c && m);
|
||||
|
||||
|
|
@ -231,14 +231,14 @@ void module_done(struct core *c, struct module*m) {
|
|||
assert(u);
|
||||
|
||||
if (u->memchunk.memblock)
|
||||
memblock_unref(u->memchunk.memblock);
|
||||
pa_memblock_unref(u->memchunk.memblock);
|
||||
if (u->silence.memblock)
|
||||
memblock_unref(u->silence.memblock);
|
||||
pa_memblock_unref(u->silence.memblock);
|
||||
|
||||
if (u->sink)
|
||||
sink_free(u->sink);
|
||||
pa_sink_free(u->sink);
|
||||
if (u->source)
|
||||
source_free(u->source);
|
||||
iochannel_free(u->io);
|
||||
pa_source_free(u->source);
|
||||
pa_iochannel_free(u->io);
|
||||
free(u);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,13 +15,13 @@
|
|||
struct userdata {
|
||||
char *filename;
|
||||
|
||||
struct sink *sink;
|
||||
struct iochannel *io;
|
||||
struct core *core;
|
||||
struct pa_sink *sink;
|
||||
struct pa_iochannel *io;
|
||||
struct pa_core *core;
|
||||
void *mainloop_source;
|
||||
struct pa_mainloop_api *mainloop;
|
||||
|
||||
struct memchunk memchunk;
|
||||
struct pa_memchunk memchunk;
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
if (!iochannel_is_writable(u->io))
|
||||
if (!pa_iochannel_is_writable(u->io))
|
||||
return;
|
||||
|
||||
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;
|
||||
|
||||
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));
|
||||
return;
|
||||
}
|
||||
|
|
@ -48,16 +48,16 @@ static void do_write(struct userdata *u) {
|
|||
u->memchunk.length -= r;
|
||||
|
||||
if (u->memchunk.length <= 0) {
|
||||
memblock_unref(u->memchunk.memblock);
|
||||
pa_memblock_unref(u->memchunk.memblock);
|
||||
u->memchunk.memblock = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void notify_cb(struct sink*s) {
|
||||
static void notify_cb(struct pa_sink*s) {
|
||||
struct userdata *u = s->userdata;
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -67,13 +67,13 @@ static void fixed_callback(struct pa_mainloop_api *m, void *id, void *userdata)
|
|||
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;
|
||||
assert(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 stat st;
|
||||
char *p;
|
||||
|
|
@ -109,14 +109,14 @@ int module_init(struct core *c, struct module*m) {
|
|||
u->filename = strdup(p);
|
||||
assert(u->filename);
|
||||
u->core = c;
|
||||
u->sink = sink_new(c, "fifo", 0, &ss);
|
||||
u->sink = pa_sink_new(c, "fifo", 0, &ss);
|
||||
assert(u->sink);
|
||||
u->sink->notify = notify_cb;
|
||||
u->sink->userdata = u;
|
||||
|
||||
u->io = iochannel_new(c->mainloop, -1, fd);
|
||||
u->io = pa_iochannel_new(c->mainloop, -1, fd);
|
||||
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.length = 0;
|
||||
|
|
@ -137,7 +137,7 @@ fail:
|
|||
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;
|
||||
assert(c && m);
|
||||
|
||||
|
|
@ -145,10 +145,10 @@ void module_done(struct core *c, struct module*m) {
|
|||
assert(u);
|
||||
|
||||
if (u->memchunk.memblock)
|
||||
memblock_unref(u->memchunk.memblock);
|
||||
pa_memblock_unref(u->memchunk.memblock);
|
||||
|
||||
sink_free(u->sink);
|
||||
iochannel_free(u->io);
|
||||
pa_sink_free(u->sink);
|
||||
pa_iochannel_free(u->io);
|
||||
u->mainloop->cancel_fixed(u->mainloop, u->mainloop_source);
|
||||
|
||||
assert(u->filename);
|
||||
|
|
|
|||
|
|
@ -9,23 +9,23 @@
|
|||
|
||||
#ifdef USE_PROTOCOL_SIMPLE
|
||||
#include "protocol-simple.h"
|
||||
#define protocol_free protocol_simple_free
|
||||
#define protocol_free pa_protocol_simple_free
|
||||
#define IPV4_PORT 4711
|
||||
#define UNIX_SOCKET_DIR "/tmp/polypaudio"
|
||||
#define UNIX_SOCKET "/tmp/polypaudio/simple"
|
||||
#else
|
||||
#ifdef USE_PROTOCOL_CLI
|
||||
#include "protocol-cli.h"
|
||||
#define protocol_new protocol_cli_new
|
||||
#define protocol_free protocol_cli_free
|
||||
#define protocol_new pa_protocol_cli_new
|
||||
#define protocol_free pa_protocol_cli_free
|
||||
#define IPV4_PORT 4712
|
||||
#define UNIX_SOCKET_DIR "/tmp/polypaudio"
|
||||
#define UNIX_SOCKET "/tmp/polypaudio/cli"
|
||||
#else
|
||||
#ifdef USE_PROTOCOL_NATIVE
|
||||
#include "protocol-native.h"
|
||||
#define protocol_new protocol_native_new
|
||||
#define protocol_free protocol_native_free
|
||||
#define protocol_new pa_protocol_native_new
|
||||
#define protocol_free pa_protocol_native_free
|
||||
#define IPV4_PORT 4713
|
||||
#define UNIX_SOCKET_DIR "/tmp/polypaudio"
|
||||
#define UNIX_SOCKET "/tmp/polypaudio/native"
|
||||
|
|
@ -33,8 +33,8 @@
|
|||
#ifdef USE_PROTOCOL_ESOUND
|
||||
#include "protocol-esound.h"
|
||||
#include "esound-spec.h"
|
||||
#define protocol_new protocol_esound_new
|
||||
#define protocol_free protocol_esound_free
|
||||
#define protocol_new pa_protocol_esound_new
|
||||
#define protocol_free pa_protocol_esound_free
|
||||
#define IPV4_PORT ESD_DEFAULT_PORT
|
||||
#define UNIX_SOCKET_DIR ESD_UNIX_SOCKET_DIR
|
||||
#define UNIX_SOCKET ESD_UNIX_SOCKET_NAME
|
||||
|
|
@ -45,27 +45,27 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
int module_init(struct core *c, struct module*m) {
|
||||
struct socket_server *s;
|
||||
int module_init(struct pa_core *c, struct pa_module*m) {
|
||||
struct pa_socket_server *s;
|
||||
assert(c && m);
|
||||
|
||||
#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;
|
||||
#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");
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#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
|
||||
m->userdata = protocol_new(c, s);
|
||||
#endif
|
||||
|
|
@ -74,7 +74,7 @@ int module_init(struct core *c, struct module*m) {
|
|||
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);
|
||||
|
||||
protocol_free(m->userdata);
|
||||
|
|
|
|||
66
src/module.c
66
src/module.c
|
|
@ -8,13 +8,13 @@
|
|||
#include "module.h"
|
||||
#include "strbuf.h"
|
||||
|
||||
struct module* module_load(struct core *c, const char *name, const char *argument) {
|
||||
struct module *m = NULL;
|
||||
struct pa_module* pa_module_load(struct pa_core *c, const char *name, const char *argument) {
|
||||
struct pa_module *m = NULL;
|
||||
int r;
|
||||
|
||||
assert(c && name);
|
||||
|
||||
m = malloc(sizeof(struct module));
|
||||
m = malloc(sizeof(struct pa_module));
|
||||
assert(m);
|
||||
|
||||
m->name = strdup(name);
|
||||
|
|
@ -37,11 +37,11 @@ struct module* module_load(struct core *c, const char *name, const char *argumen
|
|||
goto fail;
|
||||
|
||||
if (!c->modules)
|
||||
c->modules = idxset_new(NULL, NULL);
|
||||
c->modules = pa_idxset_new(NULL, NULL);
|
||||
|
||||
assert(c->modules);
|
||||
r = idxset_put(c->modules, m, &m->index);
|
||||
assert(r >= 0 && m->index != IDXSET_INVALID);
|
||||
r = pa_idxset_put(c->modules, m, &m->index);
|
||||
assert(r >= 0 && m->index != PA_IDXSET_INVALID);
|
||||
|
||||
fprintf(stderr, "module: loaded %u \"%s\" with argument \"%s\".\n", m->index, m->name, m->argument);
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ fail:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void module_free(struct module *m) {
|
||||
static void pa_module_free(struct pa_module *m) {
|
||||
assert(m && m->done && m->core);
|
||||
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->modules);
|
||||
if (!(m = idxset_remove_by_data(c->modules, m, NULL)))
|
||||
if (!(m = pa_idxset_remove_by_data(c->modules, m, NULL)))
|
||||
return;
|
||||
|
||||
module_free(m);
|
||||
pa_module_free(m);
|
||||
}
|
||||
|
||||
void module_unload_by_index(struct core *c, uint32_t index) {
|
||||
struct module *m;
|
||||
assert(c && index != IDXSET_INVALID);
|
||||
void pa_module_unload_by_index(struct pa_core *c, uint32_t index) {
|
||||
struct pa_module *m;
|
||||
assert(c && index != PA_IDXSET_INVALID);
|
||||
|
||||
assert(c->modules);
|
||||
if (!(m = idxset_remove_by_index(c->modules, index)))
|
||||
if (!(m = pa_idxset_remove_by_index(c->modules, index)))
|
||||
return;
|
||||
|
||||
module_free(m);
|
||||
pa_module_free(m);
|
||||
}
|
||||
|
||||
void free_callback(void *p, void *userdata) {
|
||||
struct module *m = p;
|
||||
static void free_callback(void *p, void *userdata) {
|
||||
struct pa_module *m = p;
|
||||
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);
|
||||
|
||||
if (!c->modules)
|
||||
return;
|
||||
|
||||
idxset_free(c->modules, free_callback, NULL);
|
||||
pa_idxset_free(c->modules, free_callback, NULL);
|
||||
c->modules = NULL;
|
||||
}
|
||||
|
||||
char *module_list_to_string(struct core *c) {
|
||||
struct strbuf *s;
|
||||
struct module *m;
|
||||
uint32_t index = IDXSET_INVALID;
|
||||
char *pa_module_list_to_string(struct pa_core *c) {
|
||||
struct pa_strbuf *s;
|
||||
struct pa_module *m;
|
||||
uint32_t index = PA_IDXSET_INVALID;
|
||||
assert(c);
|
||||
|
||||
s = strbuf_new();
|
||||
s = pa_strbuf_new();
|
||||
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))
|
||||
strbuf_printf(s, " index: %u, name: <%s>, argument: <%s>\n", m->index, m->name, m->argument);
|
||||
for (m = pa_idxset_first(c->modules, &index); m; m = pa_idxset_next(c->modules, &index))
|
||||
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 core *core;
|
||||
struct pa_core *core;
|
||||
uint32_t index;
|
||||
};
|
||||
|
||||
|
||||
void module_unload_once_callback(void *userdata) {
|
||||
static void module_unload_once_callback(void *userdata) {
|
||||
struct once_info *i = userdata;
|
||||
assert(i);
|
||||
module_unload_by_index(i->core, i->index);
|
||||
pa_module_unload_by_index(i->core, i->index);
|
||||
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;
|
||||
assert(c && m);
|
||||
|
||||
|
|
|
|||
20
src/module.h
20
src/module.h
|
|
@ -6,28 +6,28 @@
|
|||
|
||||
#include "core.h"
|
||||
|
||||
struct module {
|
||||
struct core *core;
|
||||
struct pa_module {
|
||||
struct pa_core *core;
|
||||
char *name, *argument;
|
||||
uint32_t index;
|
||||
|
||||
lt_dlhandle dl;
|
||||
|
||||
int (*init)(struct core *c, struct module*m);
|
||||
void (*done)(struct core *c, struct module*m);
|
||||
int (*init)(struct pa_core *c, struct pa_module*m);
|
||||
void (*done)(struct pa_core *c, struct pa_module*m);
|
||||
|
||||
void *userdata;
|
||||
};
|
||||
|
||||
struct module* module_load(struct core *c, const char *name, const char*argument);
|
||||
void module_unload(struct core *c, struct module *m);
|
||||
void module_unload_by_index(struct core *c, uint32_t index);
|
||||
struct pa_module* pa_module_load(struct pa_core *c, const char *name, const char*argument);
|
||||
void pa_module_unload(struct pa_core *c, struct pa_module *m);
|
||||
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
|
||||
|
|
|
|||
|
|
@ -8,20 +8,20 @@
|
|||
#include "namereg.h"
|
||||
|
||||
struct namereg_entry {
|
||||
enum namereg_type type;
|
||||
enum pa_namereg_type type;
|
||||
char *name;
|
||||
void *data;
|
||||
};
|
||||
|
||||
void namereg_free(struct core *c) {
|
||||
void pa_namereg_free(struct pa_core *c) {
|
||||
assert(c);
|
||||
if (!c->namereg)
|
||||
return;
|
||||
assert(hashset_ncontents(c->namereg) == 0);
|
||||
hashset_free(c->namereg, NULL, NULL);
|
||||
assert(pa_hashset_ncontents(c->namereg) == 0);
|
||||
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;
|
||||
char *n = NULL;
|
||||
int r;
|
||||
|
|
@ -29,11 +29,11 @@ const char *namereg_register(struct core *c, const char *name, enum namereg_type
|
|||
assert(c && name && data);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if ((e = hashset_get(c->namereg, name)) && fail)
|
||||
if ((e = pa_hashset_get(c->namereg, name)) && fail)
|
||||
return NULL;
|
||||
|
||||
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++) {
|
||||
snprintf(n, l+2, "%s%u", name, i);
|
||||
|
||||
if (!(e = hashset_get(c->namereg, n)))
|
||||
if (!(e = pa_hashset_get(c->namereg, n)))
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -64,36 +64,36 @@ const char *namereg_register(struct core *c, const char *name, enum namereg_type
|
|||
e->name = n;
|
||||
e->data = data;
|
||||
|
||||
r = hashset_put(c->namereg, e->name, e);
|
||||
r = pa_hashset_put(c->namereg, e->name, e);
|
||||
assert (r >= 0);
|
||||
|
||||
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;
|
||||
int r;
|
||||
assert(c && name);
|
||||
|
||||
e = hashset_get(c->namereg, name);
|
||||
e = pa_hashset_get(c->namereg, name);
|
||||
assert(e);
|
||||
|
||||
r = hashset_remove(c->namereg, name);
|
||||
r = pa_hashset_remove(c->namereg, name);
|
||||
assert(r >= 0);
|
||||
|
||||
free(e->name);
|
||||
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;
|
||||
uint32_t index;
|
||||
char *x = NULL;
|
||||
void *d = NULL;
|
||||
assert(c && name);
|
||||
|
||||
if ((e = hashset_get(c->namereg, name)))
|
||||
if ((e = pa_hashset_get(c->namereg, name)))
|
||||
if (e->type == e->type)
|
||||
return e->data;
|
||||
|
||||
|
|
@ -102,10 +102,10 @@ void* namereg_get(struct core *c, const char *name, enum namereg_type type) {
|
|||
if (!x || *x != 0)
|
||||
return NULL;
|
||||
|
||||
if (type == NAMEREG_SINK)
|
||||
d = idxset_get_by_index(c->sinks, index);
|
||||
else if (type == NAMEREG_SOURCE)
|
||||
d = idxset_get_by_index(c->sources, index);
|
||||
if (type == PA_NAMEREG_SINK)
|
||||
d = pa_idxset_get_by_index(c->sinks, index);
|
||||
else if (type == PA_NAMEREG_SOURCE)
|
||||
d = pa_idxset_get_by_index(c->sources, index);
|
||||
|
||||
return d;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,15 @@
|
|||
|
||||
#include "core.h"
|
||||
|
||||
enum namereg_type {
|
||||
NAMEREG_SINK,
|
||||
NAMEREG_SOURCE
|
||||
enum pa_namereg_type {
|
||||
PA_NAMEREG_SINK,
|
||||
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);
|
||||
void namereg_unregister(struct core *c, const char *name);
|
||||
void* namereg_get(struct core *c, const char *name, enum namereg_type type);
|
||||
const char *pa_namereg_register(struct pa_core *c, const char *name, enum pa_namereg_type type, void *data, int fail);
|
||||
void pa_namereg_unregister(struct pa_core *c, const char *name);
|
||||
void* pa_namereg_get(struct pa_core *c, const char *name, enum pa_namereg_type type);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#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;
|
||||
|
||||
assert(fd >= 0 && ss);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@
|
|||
|
||||
#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
|
||||
|
|
|
|||
|
|
@ -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 const struct pa_sample_spec ss = {
|
||||
.format = PA_SAMPLE_S16NE,
|
||||
.format = PA_SAMPLE_S16LE,
|
||||
.rate = 44100,
|
||||
.channels = 1
|
||||
.channels = 2
|
||||
};
|
||||
|
||||
assert(c && !stream);
|
||||
|
|
|
|||
22
src/packet.c
22
src/packet.c
|
|
@ -3,44 +3,44 @@
|
|||
|
||||
#include "packet.h"
|
||||
|
||||
struct packet* packet_new(size_t length) {
|
||||
struct packet *p;
|
||||
struct pa_packet* pa_packet_new(size_t length) {
|
||||
struct pa_packet *p;
|
||||
assert(length);
|
||||
p = malloc(sizeof(struct packet)+length);
|
||||
p = malloc(sizeof(struct pa_packet)+length);
|
||||
assert(p);
|
||||
|
||||
p->ref = 1;
|
||||
p->length = length;
|
||||
p->data = (uint8_t*) (p+1);
|
||||
p->type = PACKET_APPENDED;
|
||||
p->type = PA_PACKET_APPENDED;
|
||||
return p;
|
||||
}
|
||||
|
||||
struct packet* packet_new_dynamic(uint8_t* data, size_t length) {
|
||||
struct packet *p;
|
||||
struct pa_packet* pa_packet_new_dynamic(uint8_t* data, size_t length) {
|
||||
struct pa_packet *p;
|
||||
assert(data && length);
|
||||
p = malloc(sizeof(struct packet));
|
||||
p = malloc(sizeof(struct pa_packet));
|
||||
assert(p);
|
||||
|
||||
p->ref = 1;
|
||||
p->length = length;
|
||||
p->data = data;
|
||||
p->type = PACKET_DYNAMIC;
|
||||
p->type = PA_PACKET_DYNAMIC;
|
||||
return p;
|
||||
}
|
||||
|
||||
struct packet* packet_ref(struct packet *p) {
|
||||
struct pa_packet* pa_packet_ref(struct pa_packet *p) {
|
||||
assert(p && p->ref >= 1);
|
||||
p->ref++;
|
||||
return p;
|
||||
}
|
||||
|
||||
void packet_unref(struct packet *p) {
|
||||
void pa_packet_unref(struct pa_packet *p) {
|
||||
assert(p && p->ref >= 1);
|
||||
p->ref--;
|
||||
|
||||
if (p->ref == 0) {
|
||||
if (p->type == PACKET_DYNAMIC)
|
||||
if (p->type == PA_PACKET_DYNAMIC)
|
||||
free(p->data);
|
||||
free(p);
|
||||
}
|
||||
|
|
|
|||
12
src/packet.h
12
src/packet.h
|
|
@ -4,17 +4,17 @@
|
|||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct packet {
|
||||
enum { PACKET_APPENDED, PACKET_DYNAMIC } type;
|
||||
struct pa_packet {
|
||||
enum { PA_PACKET_APPENDED, PA_PACKET_DYNAMIC } type;
|
||||
unsigned ref;
|
||||
size_t length;
|
||||
uint8_t *data;
|
||||
};
|
||||
|
||||
struct packet* packet_new(size_t length);
|
||||
struct packet* packet_new_dynamic(uint8_t* data, size_t length);
|
||||
struct pa_packet* pa_packet_new(size_t length);
|
||||
struct pa_packet* pa_packet_new_dynamic(uint8_t* data, size_t length);
|
||||
|
||||
struct packet* packet_ref(struct packet *p);
|
||||
void packet_unref(struct packet *p);
|
||||
struct pa_packet* pa_packet_ref(struct pa_packet *p);
|
||||
void pa_packet_unref(struct pa_packet *p);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -5,17 +5,17 @@
|
|||
#include "protocol-native-spec.h"
|
||||
|
||||
struct reply_info {
|
||||
struct pdispatch *pdispatch;
|
||||
struct pa_pdispatch *pdispatch;
|
||||
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;
|
||||
uint32_t tag;
|
||||
void *mainloop_timeout;
|
||||
};
|
||||
|
||||
struct pdispatch {
|
||||
struct pa_pdispatch {
|
||||
struct pa_mainloop_api *mainloop;
|
||||
const struct pdispatch_command *command_table;
|
||||
const struct pa_pdispatch_command *command_table;
|
||||
unsigned n_commands;
|
||||
struct reply_info *replies;
|
||||
};
|
||||
|
|
@ -37,13 +37,13 @@ static void reply_info_free(struct reply_info *r) {
|
|||
free(r);
|
||||
}
|
||||
|
||||
struct pdispatch* pdispatch_new(struct pa_mainloop_api *mainloop, const struct pdispatch_command*table, unsigned entries) {
|
||||
struct pdispatch *pd;
|
||||
struct pa_pdispatch* pa_pdispatch_new(struct pa_mainloop_api *mainloop, const struct pa_pdispatch_command*table, unsigned entries) {
|
||||
struct pa_pdispatch *pd;
|
||||
assert(mainloop);
|
||||
|
||||
assert((entries && table) || (!entries && !table));
|
||||
|
||||
pd = malloc(sizeof(struct pdispatch));
|
||||
pd = malloc(sizeof(struct pa_pdispatch));
|
||||
assert(pd);
|
||||
pd->mainloop = mainloop;
|
||||
pd->command_table = table;
|
||||
|
|
@ -52,27 +52,27 @@ struct pdispatch* pdispatch_new(struct pa_mainloop_api *mainloop, const struct p
|
|||
return pd;
|
||||
}
|
||||
|
||||
void pdispatch_free(struct pdispatch *pd) {
|
||||
void pa_pdispatch_free(struct pa_pdispatch *pd) {
|
||||
assert(pd);
|
||||
while (pd->replies)
|
||||
reply_info_free(pd->replies);
|
||||
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;
|
||||
assert(pd && packet);
|
||||
struct tagstruct *ts = NULL;
|
||||
struct pa_tagstruct *ts = NULL;
|
||||
assert(pd && packet && packet->data);
|
||||
|
||||
if (packet->length <= 8)
|
||||
goto fail;
|
||||
|
||||
ts = tagstruct_new(packet->data, packet->length);
|
||||
ts = pa_tagstruct_new(packet->data, packet->length);
|
||||
assert(ts);
|
||||
|
||||
if (tagstruct_getu32(ts, &command) < 0 ||
|
||||
tagstruct_getu32(ts, &tag) < 0)
|
||||
if (pa_tagstruct_getu32(ts, &command) < 0 ||
|
||||
pa_tagstruct_getu32(ts, &tag) < 0)
|
||||
goto fail;
|
||||
|
||||
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;
|
||||
|
||||
} 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)
|
||||
goto fail;
|
||||
|
|
@ -106,13 +106,13 @@ int pdispatch_run(struct pdispatch *pd, struct packet*packet, void *userdata) {
|
|||
} else
|
||||
goto fail;
|
||||
|
||||
tagstruct_free(ts);
|
||||
pa_tagstruct_free(ts);
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
if (ts)
|
||||
tagstruct_free(ts);
|
||||
pa_tagstruct_free(ts);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -125,7 +125,7 @@ static void timeout_callback(struct pa_mainloop_api*m, void *id, const struct ti
|
|||
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 timeval tv;
|
||||
assert(pd && cb);
|
||||
|
|
|
|||
|
|
@ -6,17 +6,17 @@
|
|||
#include "packet.h"
|
||||
#include "mainloop-api.h"
|
||||
|
||||
struct pdispatch;
|
||||
struct pa_pdispatch;
|
||||
|
||||
struct pdispatch_command {
|
||||
int (*proc)(struct pdispatch *pd, uint32_t command, uint32_t tag, struct tagstruct *t, void *userdata);
|
||||
struct pa_pdispatch_command {
|
||||
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);
|
||||
void pdispatch_free(struct pdispatch *pd);
|
||||
struct pa_pdispatch* pa_pdispatch_new(struct pa_mainloop_api *m, const struct pa_pdispatch_command*table, unsigned entries);
|
||||
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
|
||||
|
|
|
|||
116
src/polyp.c
116
src/polyp.c
|
|
@ -20,10 +20,10 @@
|
|||
struct pa_context {
|
||||
char *name;
|
||||
struct pa_mainloop_api* mainloop;
|
||||
struct socket_client *client;
|
||||
struct pstream *pstream;
|
||||
struct pdispatch *pdispatch;
|
||||
struct dynarray *streams;
|
||||
struct pa_socket_client *client;
|
||||
struct pa_pstream *pstream;
|
||||
struct pa_pdispatch *pdispatch;
|
||||
struct pa_dynarray *streams;
|
||||
struct pa_stream *first_stream;
|
||||
uint32_t ctag;
|
||||
uint32_t errno;
|
||||
|
|
@ -59,9 +59,9 @@ struct pa_stream {
|
|||
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_REPLY] = { 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->pstream = NULL;
|
||||
c->pdispatch = NULL;
|
||||
c->streams = dynarray_new();
|
||||
c->streams = pa_dynarray_new();
|
||||
assert(c->streams);
|
||||
c->first_stream = NULL;
|
||||
c->errno = PA_ERROR_OK;
|
||||
|
|
@ -105,13 +105,13 @@ void pa_context_free(struct pa_context *c) {
|
|||
pa_stream_free(c->first_stream);
|
||||
|
||||
if (c->client)
|
||||
socket_client_free(c->client);
|
||||
pa_socket_client_free(c->client);
|
||||
if (c->pdispatch)
|
||||
pdispatch_free(c->pdispatch);
|
||||
pa_pdispatch_free(c->pdispatch);
|
||||
if (c->pstream)
|
||||
pstream_free(c->pstream);
|
||||
pa_pstream_free(c->pstream);
|
||||
if (c->streams)
|
||||
dynarray_free(c->streams, NULL, NULL);
|
||||
pa_dynarray_free(c->streams, NULL, NULL);
|
||||
|
||||
free(c->name);
|
||||
free(c);
|
||||
|
|
@ -141,7 +141,7 @@ static void context_dead(struct pa_context *c) {
|
|||
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;
|
||||
assert(p && c);
|
||||
|
||||
|
|
@ -152,11 +152,11 @@ static void pstream_die_callback(struct pstream *p, void *userdata) {
|
|||
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;
|
||||
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");
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -164,12 +164,12 @@ static int pstream_packet_callback(struct pstream *p, struct packet *packet, voi
|
|||
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_stream *s;
|
||||
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;
|
||||
|
||||
if (s->read_callback)
|
||||
|
|
@ -178,11 +178,11 @@ static int pstream_memblock_callback(struct pstream *p, uint32_t channel, int32_
|
|||
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;
|
||||
assert(client && io && c && c->state == CONTEXT_CONNECTING);
|
||||
|
||||
socket_client_free(client);
|
||||
pa_socket_client_free(client);
|
||||
c->client = NULL;
|
||||
|
||||
if (!io) {
|
||||
|
|
@ -195,13 +195,13 @@ static void on_connection(struct socket_client *client, struct iochannel*io, voi
|
|||
return;
|
||||
}
|
||||
|
||||
c->pstream = pstream_new(c->mainloop, io);
|
||||
c->pstream = pa_pstream_new(c->mainloop, io);
|
||||
assert(c->pstream);
|
||||
pstream_set_die_callback(c->pstream, pstream_die_callback, c);
|
||||
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_die_callback(c->pstream, pstream_die_callback, c);
|
||||
pa_pstream_set_recieve_packet_callback(c->pstream, pstream_packet_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);
|
||||
|
||||
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->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;
|
||||
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_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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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_context *c = userdata;
|
||||
uint32_t bytes, channel;
|
||||
assert(pd && command == PA_COMMAND_REQUEST && t && c);
|
||||
|
||||
if (tagstruct_getu32(t, &channel) < 0 ||
|
||||
tagstruct_getu32(t, &bytes) < 0 ||
|
||||
!tagstruct_eof(t)) {
|
||||
if (pa_tagstruct_getu32(t, &channel) < 0 ||
|
||||
pa_tagstruct_getu32(t, &bytes) < 0 ||
|
||||
!pa_tagstruct_eof(t)) {
|
||||
c->errno = PA_ERROR_PROTOCOL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(s = dynarray_get(c->streams, channel))) {
|
||||
if (!(s = pa_dynarray_get(c->streams, channel))) {
|
||||
c->errno = PA_ERROR_PROTOCOL;
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -277,7 +277,7 @@ static int command_request(struct pdispatch *pd, uint32_t command, uint32_t tag,
|
|||
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;
|
||||
struct pa_stream *s = userdata;
|
||||
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;
|
||||
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;
|
||||
ret = -1;
|
||||
} else if (command == PA_COMMAND_TIMEOUT) {
|
||||
|
|
@ -297,16 +297,16 @@ static int create_playback_callback(struct pdispatch *pd, uint32_t command, uint
|
|||
goto fail;
|
||||
}
|
||||
|
||||
if (tagstruct_getu32(t, &s->channel) < 0 ||
|
||||
tagstruct_getu32(t, &s->device_index) < 0 ||
|
||||
!tagstruct_eof(t)) {
|
||||
if (pa_tagstruct_getu32(t, &s->channel) < 0 ||
|
||||
pa_tagstruct_getu32(t, &s->device_index) < 0 ||
|
||||
!pa_tagstruct_eof(t)) {
|
||||
s->context->errno = PA_ERROR_PROTOCOL;
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
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;
|
||||
assert(s->create_complete_callback);
|
||||
|
|
@ -331,7 +331,7 @@ int pa_stream_new(
|
|||
void *userdata) {
|
||||
|
||||
struct pa_stream *s;
|
||||
struct tagstruct *t;
|
||||
struct pa_tagstruct *t;
|
||||
uint32_t tag;
|
||||
|
||||
assert(c && name && ss && c->state == CONTEXT_READY && complete);
|
||||
|
|
@ -356,21 +356,21 @@ int pa_stream_new(
|
|||
s->device_index = (uint32_t) -1;
|
||||
s->direction = dir;
|
||||
|
||||
t = tagstruct_new(NULL, 0);
|
||||
t = pa_tagstruct_new(NULL, 0);
|
||||
assert(t);
|
||||
|
||||
tagstruct_putu32(t, dir == PA_STREAM_PLAYBACK ? PA_COMMAND_CREATE_PLAYBACK_STREAM : PA_COMMAND_CREATE_RECORD_STREAM);
|
||||
tagstruct_putu32(t, tag = c->ctag++);
|
||||
tagstruct_puts(t, name);
|
||||
tagstruct_put_sample_spec(t, ss);
|
||||
tagstruct_putu32(t, (uint32_t) -1);
|
||||
tagstruct_putu32(t, attr ? attr->queue_length : DEFAULT_QUEUE_LENGTH);
|
||||
tagstruct_putu32(t, attr ? attr->max_length : DEFAULT_MAX_LENGTH);
|
||||
tagstruct_putu32(t, attr ? attr->prebuf : DEFAULT_PREBUF);
|
||||
pa_tagstruct_putu32(t, dir == PA_STREAM_PLAYBACK ? PA_COMMAND_CREATE_PLAYBACK_STREAM : PA_COMMAND_CREATE_RECORD_STREAM);
|
||||
pa_tagstruct_putu32(t, tag = c->ctag++);
|
||||
pa_tagstruct_puts(t, name);
|
||||
pa_tagstruct_put_sample_spec(t, ss);
|
||||
pa_tagstruct_putu32(t, (uint32_t) -1);
|
||||
pa_tagstruct_putu32(t, attr ? attr->queue_length : DEFAULT_QUEUE_LENGTH);
|
||||
pa_tagstruct_putu32(t, attr ? attr->max_length : DEFAULT_MAX_LENGTH);
|
||||
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;
|
||||
if (s->next)
|
||||
|
|
@ -385,17 +385,17 @@ void pa_stream_free(struct pa_stream *s) {
|
|||
assert(s && s->context);
|
||||
|
||||
if (s->channel_valid) {
|
||||
struct tagstruct *t = tagstruct_new(NULL, 0);
|
||||
struct pa_tagstruct *t = pa_tagstruct_new(NULL, 0);
|
||||
assert(t);
|
||||
|
||||
tagstruct_putu32(t, PA_COMMAND_DELETE_PLAYBACK_STREAM);
|
||||
tagstruct_putu32(t, s->context->ctag++);
|
||||
tagstruct_putu32(t, s->channel);
|
||||
pstream_send_tagstruct(s->context->pstream, t);
|
||||
pa_tagstruct_putu32(t, PA_COMMAND_DELETE_PLAYBACK_STREAM);
|
||||
pa_tagstruct_putu32(t, s->context->ctag++);
|
||||
pa_tagstruct_putu32(t, s->channel);
|
||||
pa_pstream_send_tagstruct(s->context->pstream, t);
|
||||
}
|
||||
|
||||
if (s->channel_valid)
|
||||
dynarray_put(s->context->streams, s->channel, NULL);
|
||||
pa_dynarray_put(s->context->streams, s->channel, NULL);
|
||||
|
||||
if (s->next)
|
||||
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) {
|
||||
struct memchunk chunk;
|
||||
struct pa_memchunk chunk;
|
||||
assert(s && s->context && data && length);
|
||||
|
||||
chunk.memblock = memblock_new(length);
|
||||
chunk.memblock = pa_memblock_new(length);
|
||||
assert(chunk.memblock && chunk.memblock->data);
|
||||
memcpy(chunk.memblock->data, data, length);
|
||||
chunk.index = 0;
|
||||
chunk.length = length;
|
||||
|
||||
pstream_send_memblock(s->context->pstream, s->channel, 0, &chunk);
|
||||
memblock_unref(chunk.memblock);
|
||||
pa_pstream_send_memblock(s->context->pstream, s->channel, 0, &chunk);
|
||||
pa_memblock_unref(chunk.memblock);
|
||||
|
||||
/*fprintf(stderr, "Sent %u bytes\n", length);*/
|
||||
|
||||
|
|
|
|||
|
|
@ -4,55 +4,55 @@
|
|||
#include "protocol-cli.h"
|
||||
#include "cli.h"
|
||||
|
||||
struct protocol_cli {
|
||||
struct core *core;
|
||||
struct socket_server*server;
|
||||
struct idxset *connections;
|
||||
struct pa_protocol_cli {
|
||||
struct pa_core *core;
|
||||
struct pa_socket_server*server;
|
||||
struct pa_idxset *connections;
|
||||
};
|
||||
|
||||
static void cli_eof_cb(struct cli*c, void*userdata) {
|
||||
struct protocol_cli *p = userdata;
|
||||
static void cli_eof_cb(struct pa_cli*c, void*userdata) {
|
||||
struct pa_protocol_cli *p = userdata;
|
||||
assert(p);
|
||||
idxset_remove_by_data(p->connections, c, NULL);
|
||||
cli_free(c);
|
||||
pa_idxset_remove_by_data(p->connections, c, NULL);
|
||||
pa_cli_free(c);
|
||||
}
|
||||
|
||||
static void on_connection(struct socket_server*s, struct iochannel *io, void *userdata) {
|
||||
struct protocol_cli *p = userdata;
|
||||
struct cli *c;
|
||||
static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, void *userdata) {
|
||||
struct pa_protocol_cli *p = userdata;
|
||||
struct pa_cli *c;
|
||||
assert(s && io && p);
|
||||
|
||||
c = cli_new(p->core, io);
|
||||
c = pa_cli_new(p->core, io);
|
||||
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 protocol_cli* p;
|
||||
struct pa_protocol_cli* pa_protocol_cli_new(struct pa_core *core, struct pa_socket_server *server) {
|
||||
struct pa_protocol_cli* p;
|
||||
assert(core && server);
|
||||
|
||||
p = malloc(sizeof(struct protocol_cli));
|
||||
p = malloc(sizeof(struct pa_protocol_cli));
|
||||
assert(p);
|
||||
p->core = core;
|
||||
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;
|
||||
}
|
||||
|
||||
static void free_connection(void *p, void *userdata) {
|
||||
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);
|
||||
|
||||
idxset_free(p->connections, free_connection, NULL);
|
||||
socket_server_free(p->server);
|
||||
pa_idxset_free(p->connections, free_connection, NULL);
|
||||
pa_socket_server_free(p->server);
|
||||
free(p);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
#include "core.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);
|
||||
void protocol_cli_free(struct protocol_cli *n);
|
||||
struct pa_protocol_cli* pa_protocol_cli_new(struct pa_core *core, struct pa_socket_server *server);
|
||||
void pa_protocol_cli_free(struct pa_protocol_cli *n);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@
|
|||
|
||||
struct connection {
|
||||
uint32_t index;
|
||||
struct protocol_esound *protocol;
|
||||
struct iochannel *io;
|
||||
struct client *client;
|
||||
struct pa_protocol_esound *protocol;
|
||||
struct pa_iochannel *io;
|
||||
struct pa_client *client;
|
||||
int authorized, swap_byte_order;
|
||||
void *read_data;
|
||||
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;
|
||||
esd_proto_t request;
|
||||
esd_client_state_t state;
|
||||
struct sink_input *sink_input;
|
||||
struct memblockq *input_memblockq;
|
||||
struct pa_sink_input *sink_input;
|
||||
struct pa_memblockq *input_memblockq;
|
||||
};
|
||||
|
||||
struct protocol_esound {
|
||||
struct pa_protocol_esound {
|
||||
int public;
|
||||
struct core *core;
|
||||
struct socket_server *server;
|
||||
struct idxset *connections;
|
||||
struct pa_core *core;
|
||||
struct pa_socket_server *server;
|
||||
struct pa_idxset *connections;
|
||||
uint32_t sink_index;
|
||||
unsigned n_player;
|
||||
};
|
||||
|
|
@ -51,10 +51,10 @@ typedef struct proto_handler {
|
|||
|
||||
#define BUFSIZE (1024)
|
||||
|
||||
static void sink_input_drop_cb(struct sink_input *i, size_t length);
|
||||
static int sink_input_peek_cb(struct sink_input *i, struct memchunk *chunk);
|
||||
static void sink_input_kill_cb(struct sink_input *i);
|
||||
static uint32_t sink_input_get_latency_cb(struct sink_input *i);
|
||||
static void sink_input_drop_cb(struct pa_sink_input *i, size_t length);
|
||||
static int sink_input_peek_cb(struct pa_sink_input *i, struct pa_memchunk *chunk);
|
||||
static void sink_input_kill_cb(struct pa_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_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) {
|
||||
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)
|
||||
c->protocol->n_player--;
|
||||
|
||||
client_free(c->client);
|
||||
pa_client_free(c->client);
|
||||
|
||||
if (c->sink_input)
|
||||
sink_input_free(c->sink_input);
|
||||
pa_sink_input_free(c->sink_input);
|
||||
if (c->input_memblockq)
|
||||
memblockq_free(c->input_memblockq);
|
||||
pa_memblockq_free(c->input_memblockq);
|
||||
|
||||
free(c->read_data);
|
||||
free(c->write_data);
|
||||
|
||||
iochannel_free(c->io);
|
||||
pa_iochannel_free(c->io);
|
||||
free(c);
|
||||
}
|
||||
|
||||
static struct sink* get_output_sink(struct protocol_esound *p) {
|
||||
struct sink *s;
|
||||
static struct pa_sink* get_output_sink(struct pa_protocol_esound *p) {
|
||||
struct pa_sink *s;
|
||||
assert(p);
|
||||
|
||||
if (!(s = idxset_get_by_index(p->core->sinks, p->sink_index)))
|
||||
s = sink_get_default(p->core);
|
||||
if (!(s = pa_idxset_get_by_index(p->core->sinks, p->sink_index)))
|
||||
s = pa_sink_get_default(p->core);
|
||||
|
||||
if (s->index)
|
||||
p->sink_index = s->index;
|
||||
else
|
||||
p->sink_index = IDXSET_INVALID;
|
||||
p->sink_index = PA_IDXSET_INVALID;
|
||||
|
||||
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) {
|
||||
char name[ESD_NAME_MAX];
|
||||
int format, rate;
|
||||
struct sink *sink;
|
||||
struct pa_sink *sink;
|
||||
struct pa_sample_spec ss;
|
||||
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));
|
||||
name[sizeof(name)-1] = 0;
|
||||
|
||||
client_rename(c->client, name);
|
||||
pa_client_rename(c->client, name);
|
||||
|
||||
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->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);
|
||||
|
||||
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) {
|
||||
struct sink *sink;
|
||||
struct pa_sink *sink;
|
||||
int latency, *lag;
|
||||
assert(c && !data && length == 0);
|
||||
|
||||
if (!(sink = get_output_sink(c->protocol)))
|
||||
latency = 0;
|
||||
else {
|
||||
float usec = sink_get_latency(sink);
|
||||
float usec = pa_sink_get_latency(sink);
|
||||
usec += pa_samples_usec(MEMBLOCKQ_LENGTH-BUFSIZE, &sink->sample_spec);
|
||||
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) {
|
||||
int rate = 44100, format = ESD_STEREO|ESD_BITS16;
|
||||
int *response;
|
||||
struct sink *sink;
|
||||
struct pa_sink *sink;
|
||||
assert(c && data && length == sizeof(int));
|
||||
|
||||
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;
|
||||
size_t t, k, s;
|
||||
struct connection *conn;
|
||||
size_t index = IDXSET_INVALID;
|
||||
size_t index = PA_IDXSET_INVALID;
|
||||
assert(c && data && length == sizeof(int));
|
||||
|
||||
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)));
|
||||
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;
|
||||
|
||||
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));
|
||||
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);
|
||||
conn->sink_input->volume = volume;
|
||||
*ok = 1;
|
||||
|
|
@ -359,24 +359,24 @@ static int esd_proto_stream_pan(struct connection *c, const void *data, size_t l
|
|||
|
||||
/*** client callbacks ***/
|
||||
|
||||
static void client_kill_cb(struct client *c) {
|
||||
static void client_kill_cb(struct pa_client *c) {
|
||||
assert(c && c->userdata);
|
||||
connection_free(c->userdata);
|
||||
}
|
||||
|
||||
/*** iochannel callbacks ***/
|
||||
/*** pa_iochannel callbacks ***/
|
||||
|
||||
static int do_read(struct connection *c) {
|
||||
assert(c && c->io);
|
||||
|
||||
if (!iochannel_is_readable(c->io))
|
||||
if (!pa_iochannel_is_readable(c->io))
|
||||
return 0;
|
||||
|
||||
if (c->state == ESD_NEXT_REQUEST) {
|
||||
ssize_t r;
|
||||
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));
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -423,7 +423,7 @@ static int do_read(struct connection *c) {
|
|||
|
||||
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));
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -439,20 +439,20 @@ static int do_read(struct connection *c) {
|
|||
return -1;
|
||||
}
|
||||
} else if (c->state == ESD_STREAMING_DATA) {
|
||||
struct memchunk chunk;
|
||||
struct pa_memchunk chunk;
|
||||
ssize_t r;
|
||||
|
||||
assert(c->input_memblockq);
|
||||
|
||||
if (!memblockq_is_writable(c->input_memblockq, BUFSIZE))
|
||||
if (!pa_memblockq_is_writable(c->input_memblockq, BUFSIZE))
|
||||
return 0;
|
||||
|
||||
chunk.memblock = memblock_new(BUFSIZE);
|
||||
chunk.memblock = pa_memblock_new(BUFSIZE);
|
||||
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));
|
||||
memblock_unref(chunk.memblock);
|
||||
pa_memblock_unref(chunk.memblock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -460,10 +460,10 @@ static int do_read(struct connection *c) {
|
|||
chunk.index = 0;
|
||||
|
||||
assert(c->input_memblockq);
|
||||
memblockq_push_align(c->input_memblockq, &chunk, 0);
|
||||
memblock_unref(chunk.memblock);
|
||||
pa_memblockq_push_align(c->input_memblockq, &chunk, 0);
|
||||
pa_memblock_unref(chunk.memblock);
|
||||
assert(c->sink_input);
|
||||
sink_notify(c->sink_input->sink);
|
||||
pa_sink_notify(c->sink_input->sink);
|
||||
|
||||
} else
|
||||
assert(0);
|
||||
|
|
@ -475,14 +475,14 @@ static int do_write(struct connection *c) {
|
|||
ssize_t r;
|
||||
assert(c && c->io);
|
||||
|
||||
if (!iochannel_is_writable(c->io))
|
||||
if (!pa_iochannel_is_writable(c->io))
|
||||
return 0;
|
||||
|
||||
if (!c->write_data_length)
|
||||
return 0;
|
||||
|
||||
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));
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -493,7 +493,7 @@ static int do_write(struct connection *c) {
|
|||
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;
|
||||
assert(io && c && c->io == io);
|
||||
|
||||
|
|
@ -503,42 +503,42 @@ static void io_callback(struct iochannel*io, void *userdata) {
|
|||
|
||||
/*** 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;
|
||||
assert(i && i->userdata && chunk);
|
||||
c = i->userdata;
|
||||
|
||||
if (memblockq_peek(c->input_memblockq, chunk) < 0)
|
||||
if (pa_memblockq_peek(c->input_memblockq, chunk) < 0)
|
||||
return -1;
|
||||
|
||||
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;
|
||||
assert(i && c && length);
|
||||
|
||||
memblockq_drop(c->input_memblockq, length);
|
||||
pa_memblockq_drop(c->input_memblockq, length);
|
||||
|
||||
if (do_read(c) < 0)
|
||||
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);
|
||||
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;
|
||||
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 ***/
|
||||
|
||||
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;
|
||||
char cname[256];
|
||||
assert(s && io && userdata);
|
||||
|
|
@ -547,11 +547,11 @@ static void on_connection(struct socket_server*s, struct iochannel *io, void *us
|
|||
assert(c);
|
||||
c->protocol = userdata;
|
||||
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);
|
||||
c->client = client_new(c->protocol->core, "ESOUND", cname);
|
||||
c->client = pa_client_new(c->protocol->core, "ESOUND", cname);
|
||||
assert(c->client);
|
||||
c->client->kill = client_kill_cb;
|
||||
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->input_memblockq = NULL;
|
||||
|
||||
idxset_put(c->protocol->connections, c, &c->index);
|
||||
pa_idxset_put(c->protocol->connections, c, &c->index);
|
||||
}
|
||||
|
||||
/*** entry points ***/
|
||||
|
||||
struct protocol_esound* protocol_esound_new(struct core*core, struct socket_server *server) {
|
||||
struct protocol_esound *p;
|
||||
struct pa_protocol_esound* pa_protocol_esound_new(struct pa_core*core, struct pa_socket_server *server) {
|
||||
struct pa_protocol_esound *p;
|
||||
assert(core && server);
|
||||
|
||||
p = malloc(sizeof(struct protocol_esound));
|
||||
p = malloc(sizeof(struct pa_protocol_esound));
|
||||
assert(p);
|
||||
p->public = 1;
|
||||
p->server = server;
|
||||
p->core = core;
|
||||
p->connections = idxset_new(NULL, NULL);
|
||||
p->connections = pa_idxset_new(NULL, NULL);
|
||||
assert(p->connections);
|
||||
p->sink_index = IDXSET_INVALID;
|
||||
p->sink_index = PA_IDXSET_INVALID;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void protocol_esound_free(struct protocol_esound *p) {
|
||||
void pa_protocol_esound_free(struct pa_protocol_esound *p) {
|
||||
struct connection *c;
|
||||
assert(p);
|
||||
|
||||
while ((c = idxset_first(p->connections, NULL)))
|
||||
while ((c = pa_idxset_first(p->connections, NULL)))
|
||||
connection_free(c);
|
||||
|
||||
idxset_free(p->connections, NULL, NULL);
|
||||
socket_server_free(p->server);
|
||||
pa_idxset_free(p->connections, NULL, NULL);
|
||||
pa_socket_server_free(p->server);
|
||||
free(p);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
#include "core.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);
|
||||
void protocol_esound_free(struct protocol_esound *p);
|
||||
struct pa_protocol_esound* pa_protocol_esound_new(struct pa_core*core, struct pa_socket_server *server);
|
||||
void pa_protocol_esound_free(struct pa_protocol_esound *p);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -14,52 +14,52 @@
|
|||
#include "pstream-util.h"
|
||||
|
||||
struct connection;
|
||||
struct protocol_native;
|
||||
struct pa_protocol_native;
|
||||
|
||||
struct record_stream {
|
||||
struct connection *connection;
|
||||
uint32_t index;
|
||||
struct source_output *source_output;
|
||||
struct memblockq *memblockq;
|
||||
struct pa_source_output *source_output;
|
||||
struct pa_memblockq *memblockq;
|
||||
};
|
||||
|
||||
struct playback_stream {
|
||||
struct connection *connection;
|
||||
uint32_t index;
|
||||
size_t qlength;
|
||||
struct sink_input *sink_input;
|
||||
struct memblockq *memblockq;
|
||||
struct pa_sink_input *sink_input;
|
||||
struct pa_memblockq *memblockq;
|
||||
size_t requested_bytes;
|
||||
};
|
||||
|
||||
struct connection {
|
||||
int authorized;
|
||||
struct protocol_native *protocol;
|
||||
struct client *client;
|
||||
struct pstream *pstream;
|
||||
struct pdispatch *pdispatch;
|
||||
struct idxset *record_streams, *playback_streams;
|
||||
struct pa_protocol_native *protocol;
|
||||
struct pa_client *client;
|
||||
struct pa_pstream *pstream;
|
||||
struct pa_pdispatch *pdispatch;
|
||||
struct pa_idxset *record_streams, *playback_streams;
|
||||
};
|
||||
|
||||
struct protocol_native {
|
||||
struct pa_protocol_native {
|
||||
int public;
|
||||
struct core *core;
|
||||
struct socket_server *server;
|
||||
struct idxset *connections;
|
||||
struct pa_core *core;
|
||||
struct pa_socket_server *server;
|
||||
struct pa_idxset *connections;
|
||||
};
|
||||
|
||||
static int sink_input_peek_cb(struct sink_input *i, struct memchunk *chunk);
|
||||
static void sink_input_drop_cb(struct sink_input *i, size_t length);
|
||||
static void sink_input_kill_cb(struct sink_input *i);
|
||||
static uint32_t sink_input_get_latency_cb(struct sink_input *i);
|
||||
static int sink_input_peek_cb(struct pa_sink_input *i, struct pa_memchunk *chunk);
|
||||
static void sink_input_drop_cb(struct pa_sink_input *i, size_t length);
|
||||
static void sink_input_kill_cb(struct pa_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 int command_exit(struct pdispatch *pd, uint32_t command, uint32_t tag, struct 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_delete_playback_stream(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 pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_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_REPLY] = { NULL },
|
||||
[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) {
|
||||
assert(r && r->connection);
|
||||
|
||||
idxset_remove_by_data(r->connection->record_streams, r, NULL);
|
||||
source_output_free(r->source_output);
|
||||
memblockq_free(r->memblockq);
|
||||
pa_idxset_remove_by_data(r->connection->record_streams, r, NULL);
|
||||
pa_source_output_free(r->source_output);
|
||||
pa_memblockq_free(r->memblockq);
|
||||
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;
|
||||
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->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);
|
||||
s->sink_input->peek = sink_input_peek_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->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);
|
||||
|
||||
s->requested_bytes = 0;
|
||||
|
||||
idxset_put(c->playback_streams, s, &s->index);
|
||||
pa_idxset_put(c->playback_streams, s, &s->index);
|
||||
return s;
|
||||
}
|
||||
|
||||
static void playback_stream_free(struct playback_stream* p) {
|
||||
assert(p && p->connection);
|
||||
|
||||
idxset_remove_by_data(p->connection->playback_streams, p, NULL);
|
||||
sink_input_free(p->sink_input);
|
||||
memblockq_free(p->memblockq);
|
||||
pa_idxset_remove_by_data(p->connection->playback_streams, p, NULL);
|
||||
pa_sink_input_free(p->sink_input);
|
||||
pa_memblockq_free(p->memblockq);
|
||||
free(p);
|
||||
}
|
||||
|
||||
|
|
@ -120,27 +120,27 @@ static void connection_free(struct connection *c) {
|
|||
struct playback_stream *p;
|
||||
assert(c && c->protocol);
|
||||
|
||||
idxset_remove_by_data(c->protocol->connections, c, NULL);
|
||||
while ((r = idxset_first(c->record_streams, NULL)))
|
||||
pa_idxset_remove_by_data(c->protocol->connections, c, NULL);
|
||||
while ((r = pa_idxset_first(c->record_streams, NULL)))
|
||||
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);
|
||||
idxset_free(c->playback_streams, NULL, NULL);
|
||||
pa_idxset_free(c->playback_streams, NULL, NULL);
|
||||
|
||||
pdispatch_free(c->pdispatch);
|
||||
pstream_free(c->pstream);
|
||||
client_free(c->client);
|
||||
pa_pdispatch_free(c->pdispatch);
|
||||
pa_pstream_free(c->pstream);
|
||||
pa_client_free(c->client);
|
||||
free(c);
|
||||
}
|
||||
|
||||
static void request_bytes(struct playback_stream *s) {
|
||||
struct tagstruct *t;
|
||||
struct pa_tagstruct *t;
|
||||
size_t l;
|
||||
assert(s);
|
||||
|
||||
if (!(l = memblockq_missing_to(s->memblockq, s->qlength)))
|
||||
if (!(l = pa_memblockq_missing_to(s->memblockq, s->qlength)))
|
||||
return;
|
||||
|
||||
if (l <= s->requested_bytes)
|
||||
|
|
@ -149,40 +149,40 @@ static void request_bytes(struct playback_stream *s) {
|
|||
l -= s->requested_bytes;
|
||||
s->requested_bytes += l;
|
||||
|
||||
t = tagstruct_new(NULL, 0);
|
||||
t = pa_tagstruct_new(NULL, 0);
|
||||
assert(t);
|
||||
tagstruct_putu32(t, PA_COMMAND_REQUEST);
|
||||
tagstruct_putu32(t, (uint32_t) -1); /* tag */
|
||||
tagstruct_putu32(t, s->index);
|
||||
tagstruct_putu32(t, l);
|
||||
pstream_send_tagstruct(s->connection->pstream, t);
|
||||
pa_tagstruct_putu32(t, PA_COMMAND_REQUEST);
|
||||
pa_tagstruct_putu32(t, (uint32_t) -1); /* tag */
|
||||
pa_tagstruct_putu32(t, s->index);
|
||||
pa_tagstruct_putu32(t, l);
|
||||
pa_pstream_send_tagstruct(s->connection->pstream, t);
|
||||
|
||||
/* fprintf(stderr, "Requesting %u bytes\n", l);*/
|
||||
}
|
||||
|
||||
/*** 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;
|
||||
assert(i && i->userdata && chunk);
|
||||
s = i->userdata;
|
||||
|
||||
if (memblockq_peek(s->memblockq, chunk) < 0)
|
||||
if (pa_memblockq_peek(s->memblockq, chunk) < 0)
|
||||
return -1;
|
||||
|
||||
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;
|
||||
assert(i && i->userdata && length);
|
||||
s = i->userdata;
|
||||
|
||||
memblockq_drop(s->memblockq, length);
|
||||
pa_memblockq_drop(s->memblockq, length);
|
||||
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;
|
||||
assert(i && i->userdata);
|
||||
s = i->userdata;
|
||||
|
|
@ -190,117 +190,117 @@ static void sink_input_kill_cb(struct sink_input *i) {
|
|||
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;
|
||||
assert(i && 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 ***/
|
||||
|
||||
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 playback_stream *s;
|
||||
size_t maxlength, prebuf, qlength;
|
||||
uint32_t sink_index;
|
||||
const char *name;
|
||||
struct pa_sample_spec ss;
|
||||
struct tagstruct *reply;
|
||||
struct sink *sink;
|
||||
struct pa_tagstruct *reply;
|
||||
struct pa_sink *sink;
|
||||
assert(c && t && c->protocol && c->protocol->core);
|
||||
|
||||
if (tagstruct_gets(t, &name) < 0 ||
|
||||
tagstruct_get_sample_spec(t, &ss) < 0 ||
|
||||
tagstruct_getu32(t, &sink_index) < 0 ||
|
||||
tagstruct_getu32(t, &qlength) < 0 ||
|
||||
tagstruct_getu32(t, &maxlength) < 0 ||
|
||||
tagstruct_getu32(t, &prebuf) < 0 ||
|
||||
!tagstruct_eof(t))
|
||||
if (pa_tagstruct_gets(t, &name) < 0 ||
|
||||
pa_tagstruct_get_sample_spec(t, &ss) < 0 ||
|
||||
pa_tagstruct_getu32(t, &sink_index) < 0 ||
|
||||
pa_tagstruct_getu32(t, &qlength) < 0 ||
|
||||
pa_tagstruct_getu32(t, &maxlength) < 0 ||
|
||||
pa_tagstruct_getu32(t, &prebuf) < 0 ||
|
||||
!pa_tagstruct_eof(t))
|
||||
return -1;
|
||||
|
||||
if (!c->authorized) {
|
||||
pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
|
||||
pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sink_index == (uint32_t) -1)
|
||||
sink = sink_get_default(c->protocol->core);
|
||||
sink = pa_sink_get_default(c->protocol->core);
|
||||
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) {
|
||||
pstream_send_error(c->pstream, tag, PA_ERROR_EXIST);
|
||||
pa_pstream_send_error(c->pstream, tag, PA_ERROR_EXIST);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
reply = tagstruct_new(NULL, 0);
|
||||
reply = pa_tagstruct_new(NULL, 0);
|
||||
assert(reply);
|
||||
tagstruct_putu32(reply, PA_COMMAND_REPLY);
|
||||
tagstruct_putu32(reply, tag);
|
||||
tagstruct_putu32(reply, s->index);
|
||||
pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
|
||||
pa_tagstruct_putu32(reply, tag);
|
||||
pa_tagstruct_putu32(reply, s->index);
|
||||
assert(s->sink_input);
|
||||
tagstruct_putu32(reply, s->sink_input->index);
|
||||
pstream_send_tagstruct(c->pstream, reply);
|
||||
pa_tagstruct_putu32(reply, s->sink_input->index);
|
||||
pa_pstream_send_tagstruct(c->pstream, reply);
|
||||
request_bytes(s);
|
||||
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;
|
||||
uint32_t channel;
|
||||
struct playback_stream *s;
|
||||
assert(c && t);
|
||||
|
||||
if (tagstruct_getu32(t, &channel) < 0 ||
|
||||
!tagstruct_eof(t))
|
||||
if (pa_tagstruct_getu32(t, &channel) < 0 ||
|
||||
!pa_tagstruct_eof(t))
|
||||
return -1;
|
||||
|
||||
if (!c->authorized) {
|
||||
pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
|
||||
pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(s = idxset_get_by_index(c->playback_streams, channel))) {
|
||||
pstream_send_error(c->pstream, tag, PA_ERROR_EXIST);
|
||||
if (!(s = pa_idxset_get_by_index(c->playback_streams, channel))) {
|
||||
pa_pstream_send_error(c->pstream, tag, PA_ERROR_EXIST);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pstream_send_simple_ack(c->pstream, tag);
|
||||
pa_pstream_send_simple_ack(c->pstream, tag);
|
||||
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;
|
||||
assert(c && t);
|
||||
|
||||
if (!tagstruct_eof(t))
|
||||
if (!pa_tagstruct_eof(t))
|
||||
return -1;
|
||||
|
||||
if (!c->authorized) {
|
||||
pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
|
||||
pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
assert(c->protocol && c->protocol->core && c->protocol->core->mainloop);
|
||||
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;
|
||||
}
|
||||
|
||||
/*** 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;
|
||||
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");
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -308,12 +308,12 @@ static int packet_callback(struct pstream *p, struct packet *packet, void *userd
|
|||
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 playback_stream *stream;
|
||||
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");
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -323,16 +323,16 @@ static int memblock_callback(struct pstream *p, uint32_t channel, int32_t delta,
|
|||
else
|
||||
stream->requested_bytes -= chunk->length;
|
||||
|
||||
memblockq_push_align(stream->memblockq, chunk, delta);
|
||||
pa_memblockq_push_align(stream->memblockq, chunk, delta);
|
||||
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);*/
|
||||
|
||||
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;
|
||||
assert(p && c);
|
||||
connection_free(c);
|
||||
|
|
@ -342,8 +342,8 @@ static void die_callback(struct pstream *p, void *userdata) {
|
|||
|
||||
/*** socket server callbacks ***/
|
||||
|
||||
static void on_connection(struct socket_server*s, struct iochannel *io, void *userdata) {
|
||||
struct protocol_native *p = userdata;
|
||||
static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, void *userdata) {
|
||||
struct pa_protocol_native *p = userdata;
|
||||
struct connection *c;
|
||||
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->protocol = p;
|
||||
assert(p->core);
|
||||
c->client = client_new(p->core, "NATIVE", "Client");
|
||||
c->client = pa_client_new(p->core, "NATIVE", "Client");
|
||||
assert(c->client);
|
||||
c->pstream = pstream_new(p->core->mainloop, io);
|
||||
c->pstream = pa_pstream_new(p->core->mainloop, io);
|
||||
assert(c->pstream);
|
||||
|
||||
pstream_set_recieve_packet_callback(c->pstream, packet_callback, c);
|
||||
pstream_set_recieve_memblock_callback(c->pstream, memblock_callback, c);
|
||||
pstream_set_die_callback(c->pstream, die_callback, c);
|
||||
pa_pstream_set_recieve_packet_callback(c->pstream, packet_callback, c);
|
||||
pa_pstream_set_recieve_memblock_callback(c->pstream, memblock_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);
|
||||
|
||||
c->record_streams = idxset_new(NULL, NULL);
|
||||
c->playback_streams = idxset_new(NULL, NULL);
|
||||
c->record_streams = pa_idxset_new(NULL, NULL);
|
||||
c->playback_streams = pa_idxset_new(NULL, NULL);
|
||||
assert(c->record_streams && c->playback_streams);
|
||||
|
||||
idxset_put(p->connections, c, NULL);
|
||||
pa_idxset_put(p->connections, c, NULL);
|
||||
}
|
||||
|
||||
/*** module entry points ***/
|
||||
|
||||
struct protocol_native* protocol_native_new(struct core *core, struct socket_server *server) {
|
||||
struct protocol_native *p;
|
||||
struct pa_protocol_native* pa_protocol_native_new(struct pa_core *core, struct pa_socket_server *server) {
|
||||
struct pa_protocol_native *p;
|
||||
assert(core && server);
|
||||
|
||||
p = malloc(sizeof(struct protocol_native));
|
||||
p = malloc(sizeof(struct pa_protocol_native));
|
||||
assert(p);
|
||||
|
||||
p->public = 1;
|
||||
p->server = server;
|
||||
p->core = core;
|
||||
p->connections = idxset_new(NULL, NULL);
|
||||
p->connections = pa_idxset_new(NULL, NULL);
|
||||
assert(p->connections);
|
||||
|
||||
socket_server_set_callback(p->server, on_connection, p);
|
||||
pa_socket_server_set_callback(p->server, on_connection, p);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void protocol_native_free(struct protocol_native *p) {
|
||||
void pa_protocol_native_free(struct pa_protocol_native *p) {
|
||||
struct connection *c;
|
||||
assert(p);
|
||||
|
||||
while ((c = idxset_first(p->connections, NULL)))
|
||||
while ((c = pa_idxset_first(p->connections, NULL)))
|
||||
connection_free(c);
|
||||
idxset_free(p->connections, NULL, NULL);
|
||||
socket_server_free(p->server);
|
||||
pa_idxset_free(p->connections, NULL, NULL);
|
||||
pa_socket_server_free(p->server);
|
||||
free(p);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
#include "core.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);
|
||||
void protocol_native_free(struct protocol_native *n);
|
||||
struct pa_protocol_native* pa_protocol_native_new(struct pa_core*core, struct pa_socket_server *server);
|
||||
void pa_protocol_native_free(struct pa_protocol_native *n);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -12,19 +12,19 @@
|
|||
#include "sample-util.h"
|
||||
|
||||
struct connection {
|
||||
struct protocol_simple *protocol;
|
||||
struct iochannel *io;
|
||||
struct sink_input *sink_input;
|
||||
struct source_output *source_output;
|
||||
struct client *client;
|
||||
struct memblockq *input_memblockq, *output_memblockq;
|
||||
struct pa_protocol_simple *protocol;
|
||||
struct pa_iochannel *io;
|
||||
struct pa_sink_input *sink_input;
|
||||
struct pa_source_output *source_output;
|
||||
struct pa_client *client;
|
||||
struct pa_memblockq *input_memblockq, *output_memblockq;
|
||||
};
|
||||
|
||||
struct protocol_simple {
|
||||
struct core *core;
|
||||
struct socket_server*server;
|
||||
struct idxset *connections;
|
||||
enum protocol_simple_mode mode;
|
||||
struct pa_protocol_simple {
|
||||
struct pa_core *core;
|
||||
struct pa_socket_server*server;
|
||||
struct pa_idxset *connections;
|
||||
enum pa_protocol_simple_mode mode;
|
||||
struct pa_sample_spec sample_spec;
|
||||
};
|
||||
|
||||
|
|
@ -33,38 +33,38 @@ struct protocol_simple {
|
|||
static void connection_free(struct connection *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)
|
||||
sink_input_free(c->sink_input);
|
||||
pa_sink_input_free(c->sink_input);
|
||||
if (c->source_output)
|
||||
source_output_free(c->source_output);
|
||||
pa_source_output_free(c->source_output);
|
||||
if (c->client)
|
||||
client_free(c->client);
|
||||
pa_client_free(c->client);
|
||||
if (c->io)
|
||||
iochannel_free(c->io);
|
||||
pa_iochannel_free(c->io);
|
||||
if (c->input_memblockq)
|
||||
memblockq_free(c->input_memblockq);
|
||||
pa_memblockq_free(c->input_memblockq);
|
||||
if (c->output_memblockq)
|
||||
memblockq_free(c->output_memblockq);
|
||||
pa_memblockq_free(c->output_memblockq);
|
||||
free(c);
|
||||
}
|
||||
static int do_read(struct connection *c) {
|
||||
struct memchunk chunk;
|
||||
struct pa_memchunk chunk;
|
||||
ssize_t r;
|
||||
|
||||
if (!iochannel_is_readable(c->io))
|
||||
if (!pa_iochannel_is_readable(c->io))
|
||||
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;
|
||||
|
||||
chunk.memblock = memblock_new(BUFSIZE);
|
||||
chunk.memblock = pa_memblock_new(BUFSIZE);
|
||||
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));
|
||||
memblock_unref(chunk.memblock);
|
||||
pa_memblock_unref(chunk.memblock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -72,103 +72,103 @@ static int do_read(struct connection *c) {
|
|||
chunk.index = 0;
|
||||
|
||||
assert(c->input_memblockq);
|
||||
memblockq_push_align(c->input_memblockq, &chunk, 0);
|
||||
memblock_unref(chunk.memblock);
|
||||
pa_memblockq_push_align(c->input_memblockq, &chunk, 0);
|
||||
pa_memblock_unref(chunk.memblock);
|
||||
assert(c->sink_input);
|
||||
sink_notify(c->sink_input->sink);
|
||||
pa_sink_notify(c->sink_input->sink);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_write(struct connection *c) {
|
||||
struct memchunk chunk;
|
||||
struct pa_memchunk chunk;
|
||||
ssize_t r;
|
||||
|
||||
if (!iochannel_is_writable(c->io))
|
||||
if (!pa_iochannel_is_writable(c->io))
|
||||
return 0;
|
||||
|
||||
if (!c->source_output)
|
||||
return 0;
|
||||
|
||||
assert(c->output_memblockq);
|
||||
if (memblockq_peek(c->output_memblockq, &chunk) < 0)
|
||||
if (pa_memblockq_peek(c->output_memblockq, &chunk) < 0)
|
||||
return 0;
|
||||
|
||||
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));
|
||||
memblock_unref(chunk.memblock);
|
||||
pa_memblock_unref(chunk.memblock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memblockq_drop(c->output_memblockq, r);
|
||||
memblock_unref(chunk.memblock);
|
||||
pa_memblockq_drop(c->output_memblockq, r);
|
||||
pa_memblock_unref(chunk.memblock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*** 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;
|
||||
assert(i && i->userdata && chunk);
|
||||
c = i->userdata;
|
||||
|
||||
if (memblockq_peek(c->input_memblockq, chunk) < 0)
|
||||
if (pa_memblockq_peek(c->input_memblockq, chunk) < 0)
|
||||
return -1;
|
||||
|
||||
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;
|
||||
assert(i && c && length);
|
||||
|
||||
memblockq_drop(c->input_memblockq, length);
|
||||
pa_memblockq_drop(c->input_memblockq, length);
|
||||
|
||||
if (do_read(c) < 0)
|
||||
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);
|
||||
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;
|
||||
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 ***/
|
||||
|
||||
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;
|
||||
assert(o && c && chunk);
|
||||
|
||||
memblockq_push(c->output_memblockq, chunk, 0);
|
||||
pa_memblockq_push(c->output_memblockq, chunk, 0);
|
||||
|
||||
if (do_write(c) < 0)
|
||||
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);
|
||||
connection_free((struct connection *) o->userdata);
|
||||
}
|
||||
|
||||
/*** client callbacks ***/
|
||||
|
||||
static void client_kill_cb(struct client *c) {
|
||||
static void client_kill_cb(struct pa_client *c) {
|
||||
assert(c && 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;
|
||||
assert(io && c && c->io == io);
|
||||
|
||||
|
|
@ -178,8 +178,8 @@ static void io_callback(struct iochannel*io, void *userdata) {
|
|||
|
||||
/*** socket_server callbacks */
|
||||
|
||||
static void on_connection(struct socket_server*s, struct iochannel *io, void *userdata) {
|
||||
struct protocol_simple *p = userdata;
|
||||
static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, void *userdata) {
|
||||
struct pa_protocol_simple *p = userdata;
|
||||
struct connection *c = NULL;
|
||||
char cname[256];
|
||||
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->protocol = p;
|
||||
|
||||
iochannel_peer_to_string(io, cname, sizeof(cname));
|
||||
c->client = client_new(p->core, "SIMPLE", cname);
|
||||
pa_iochannel_peer_to_string(io, cname, sizeof(cname));
|
||||
c->client = pa_client_new(p->core, "SIMPLE", cname);
|
||||
assert(c->client);
|
||||
c->client->kill = client_kill_cb;
|
||||
c->client->userdata = c;
|
||||
|
||||
if (p->mode & PROTOCOL_SIMPLE_RECORD) {
|
||||
struct source *source;
|
||||
if (p->mode & PA_PROTOCOL_SIMPLE_RECORD) {
|
||||
struct pa_source *source;
|
||||
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");
|
||||
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);
|
||||
c->source_output->push = source_output_push_cb;
|
||||
c->source_output->kill = source_output_kill_cb;
|
||||
c->source_output->userdata = c;
|
||||
|
||||
l = 5*pa_bytes_per_second(&DEFAULT_SAMPLE_SPEC); /* 5s */
|
||||
c->output_memblockq = memblockq_new(l, pa_sample_size(&p->sample_spec), l/2);
|
||||
l = 5*pa_bytes_per_second(&p->sample_spec); /* 5s */
|
||||
c->output_memblockq = pa_memblockq_new(l, pa_sample_size(&p->sample_spec), l/2);
|
||||
}
|
||||
|
||||
if (p->mode & PROTOCOL_SIMPLE_PLAYBACK) {
|
||||
struct sink *sink;
|
||||
if (p->mode & PA_PROTOCOL_SIMPLE_PLAYBACK) {
|
||||
struct pa_sink *sink;
|
||||
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");
|
||||
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);
|
||||
c->sink_input->peek = sink_input_peek_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->userdata = c;
|
||||
|
||||
l = pa_bytes_per_second(&DEFAULT_SAMPLE_SPEC)/2; /* half a second */
|
||||
c->input_memblockq = memblockq_new(l, pa_sample_size(&p->sample_spec), l/2);
|
||||
l = pa_bytes_per_second(&p->sample_spec)/2; /* half a second */
|
||||
c->input_memblockq = pa_memblockq_new(l, pa_sample_size(&p->sample_spec), l/2);
|
||||
}
|
||||
|
||||
|
||||
iochannel_set_callback(c->io, io_callback, c);
|
||||
idxset_put(p->connections, c, NULL);
|
||||
pa_iochannel_set_callback(c->io, io_callback, c);
|
||||
pa_idxset_put(p->connections, c, NULL);
|
||||
return;
|
||||
|
||||
fail:
|
||||
|
|
@ -248,34 +248,34 @@ fail:
|
|||
connection_free(c);
|
||||
}
|
||||
|
||||
struct protocol_simple* protocol_simple_new(struct core *core, struct socket_server *server, enum protocol_simple_mode mode) {
|
||||
struct protocol_simple* p;
|
||||
assert(core && server && mode <= PROTOCOL_SIMPLE_DUPLEX && mode > 0);
|
||||
struct pa_protocol_simple* pa_protocol_simple_new(struct pa_core *core, struct pa_socket_server *server, enum pa_protocol_simple_mode mode) {
|
||||
struct pa_protocol_simple* p;
|
||||
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);
|
||||
p->core = core;
|
||||
p->server = server;
|
||||
p->connections = idxset_new(NULL, NULL);
|
||||
p->connections = pa_idxset_new(NULL, NULL);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
void protocol_simple_free(struct protocol_simple *p) {
|
||||
void pa_protocol_simple_free(struct pa_protocol_simple *p) {
|
||||
struct connection *c;
|
||||
assert(p);
|
||||
|
||||
while((c = idxset_first(p->connections, NULL)))
|
||||
while((c = pa_idxset_first(p->connections, NULL)))
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,15 +3,15 @@
|
|||
|
||||
#include "socket-server.h"
|
||||
|
||||
struct protocol_simple;
|
||||
struct pa_protocol_simple;
|
||||
|
||||
enum protocol_simple_mode {
|
||||
PROTOCOL_SIMPLE_RECORD = 1,
|
||||
PROTOCOL_SIMPLE_PLAYBACK = 2,
|
||||
PROTOCOL_SIMPLE_DUPLEX = 3
|
||||
enum pa_protocol_simple_mode {
|
||||
PA_PROTOCOL_SIMPLE_RECORD = 1,
|
||||
PA_PROTOCOL_SIMPLE_PLAYBACK = 2,
|
||||
PA_PROTOCOL_SIMPLE_DUPLEX = 3
|
||||
};
|
||||
|
||||
struct protocol_simple* protocol_simple_new(struct core *core, struct socket_server *server, enum protocol_simple_mode mode);
|
||||
void protocol_simple_free(struct protocol_simple *n);
|
||||
struct pa_protocol_simple* pa_protocol_simple_new(struct pa_core *core, struct pa_socket_server *server, enum pa_protocol_simple_mode mode);
|
||||
void pa_protocol_simple_free(struct pa_protocol_simple *n);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,33 +3,33 @@
|
|||
#include "protocol-native-spec.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;
|
||||
uint8_t *data;
|
||||
struct packet *packet;
|
||||
struct pa_packet *packet;
|
||||
assert(p && t);
|
||||
|
||||
data = tagstruct_free_data(t, &length);
|
||||
data = pa_tagstruct_free_data(t, &length);
|
||||
assert(data && length);
|
||||
packet = packet_new_dynamic(data, length);
|
||||
packet = pa_packet_new_dynamic(data, length);
|
||||
assert(packet);
|
||||
pstream_send_packet(p, packet);
|
||||
packet_unref(packet);
|
||||
pa_pstream_send_packet(p, packet);
|
||||
pa_packet_unref(packet);
|
||||
}
|
||||
|
||||
void pstream_send_error(struct pstream *p, uint32_t tag, uint32_t error) {
|
||||
struct tagstruct *t = tagstruct_new(NULL, 0);
|
||||
void pa_pstream_send_error(struct pa_pstream *p, uint32_t tag, uint32_t error) {
|
||||
struct pa_tagstruct *t = pa_tagstruct_new(NULL, 0);
|
||||
assert(t);
|
||||
tagstruct_putu32(t, PA_COMMAND_ERROR);
|
||||
tagstruct_putu32(t, tag);
|
||||
tagstruct_putu32(t, error);
|
||||
pstream_send_tagstruct(p, t);
|
||||
pa_tagstruct_putu32(t, PA_COMMAND_ERROR);
|
||||
pa_tagstruct_putu32(t, tag);
|
||||
pa_tagstruct_putu32(t, error);
|
||||
pa_pstream_send_tagstruct(p, t);
|
||||
}
|
||||
|
||||
void pstream_send_simple_ack(struct pstream *p, uint32_t tag) {
|
||||
struct tagstruct *t = tagstruct_new(NULL, 0);
|
||||
void pa_pstream_send_simple_ack(struct pa_pstream *p, uint32_t tag) {
|
||||
struct pa_tagstruct *t = pa_tagstruct_new(NULL, 0);
|
||||
assert(t);
|
||||
tagstruct_putu32(t, PA_COMMAND_REPLY);
|
||||
tagstruct_putu32(t, tag);
|
||||
pstream_send_tagstruct(p, t);
|
||||
pa_tagstruct_putu32(t, PA_COMMAND_REPLY);
|
||||
pa_tagstruct_putu32(t, tag);
|
||||
pa_pstream_send_tagstruct(p, t);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@
|
|||
#include "tagstruct.h"
|
||||
|
||||
/* 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 pstream_send_simple_ack(struct pstream *p, uint32_t tag);
|
||||
void pa_pstream_send_error(struct pa_pstream *p, uint32_t tag, uint32_t error);
|
||||
void pa_pstream_send_simple_ack(struct pa_pstream *p, uint32_t tag);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
184
src/pstream.c
184
src/pstream.c
|
|
@ -5,70 +5,70 @@
|
|||
#include "pstream.h"
|
||||
#include "queue.h"
|
||||
|
||||
enum pstream_descriptor_index {
|
||||
PSTREAM_DESCRIPTOR_LENGTH,
|
||||
PSTREAM_DESCRIPTOR_CHANNEL,
|
||||
PSTREAM_DESCRIPTOR_DELTA,
|
||||
PSTREAM_DESCRIPTOR_MAX
|
||||
enum pa_pstream_descriptor_index {
|
||||
PA_PSTREAM_DESCRIPTOR_LENGTH,
|
||||
PA_PSTREAM_DESCRIPTOR_CHANNEL,
|
||||
PA_PSTREAM_DESCRIPTOR_DELTA,
|
||||
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)
|
||||
|
||||
struct item_info {
|
||||
enum { PSTREAM_ITEM_PACKET, PSTREAM_ITEM_MEMBLOCK } type;
|
||||
enum { PA_PSTREAM_ITEM_PACKET, PA_PSTREAM_ITEM_MEMBLOCK } type;
|
||||
|
||||
/* memblock info */
|
||||
struct memchunk chunk;
|
||||
struct pa_memchunk chunk;
|
||||
uint32_t channel;
|
||||
int32_t delta;
|
||||
|
||||
/* packet info */
|
||||
struct packet *packet;
|
||||
struct pa_packet *packet;
|
||||
};
|
||||
|
||||
struct pstream {
|
||||
struct pa_pstream {
|
||||
struct pa_mainloop_api *mainloop;
|
||||
struct mainloop_source *mainloop_source;
|
||||
struct iochannel *io;
|
||||
struct queue *send_queue;
|
||||
struct pa_iochannel *io;
|
||||
struct pa_queue *send_queue;
|
||||
|
||||
int dead;
|
||||
void (*die_callback) (struct pstream *p, void *userdad);
|
||||
void (*die_callback) (struct pa_pstream *p, void *userdad);
|
||||
void *die_callback_userdata;
|
||||
|
||||
struct {
|
||||
struct item_info* current;
|
||||
pstream_descriptor descriptor;
|
||||
pa_pstream_descriptor descriptor;
|
||||
void *data;
|
||||
size_t index;
|
||||
} write;
|
||||
|
||||
void (*send_callback) (struct pstream *p, void *userdata);
|
||||
void (*send_callback) (struct pa_pstream *p, void *userdata);
|
||||
void *send_callback_userdata;
|
||||
|
||||
struct {
|
||||
struct memblock *memblock;
|
||||
struct packet *packet;
|
||||
pstream_descriptor descriptor;
|
||||
struct pa_memblock *memblock;
|
||||
struct pa_packet *packet;
|
||||
pa_pstream_descriptor descriptor;
|
||||
void *data;
|
||||
size_t index;
|
||||
} 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;
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
static void do_write(struct pstream *p);
|
||||
static void do_read(struct pstream *p);
|
||||
static void do_write(struct pa_pstream *p);
|
||||
static void do_read(struct pa_pstream *p);
|
||||
|
||||
static void io_callback(struct iochannel*io, void *userdata) {
|
||||
struct pstream *p = userdata;
|
||||
static void io_callback(struct pa_iochannel*io, void *userdata) {
|
||||
struct pa_pstream *p = userdata;
|
||||
assert(p && p->io == io);
|
||||
|
||||
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) {
|
||||
struct pstream *p = userdata;
|
||||
struct pa_pstream *p = userdata;
|
||||
assert(p && p->mainloop_source == id && p->mainloop == m);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
struct pstream *pstream_new(struct pa_mainloop_api *m, struct iochannel *io) {
|
||||
struct pstream *p;
|
||||
struct pa_pstream *pa_pstream_new(struct pa_mainloop_api *m, struct pa_iochannel *io) {
|
||||
struct pa_pstream *p;
|
||||
assert(io);
|
||||
|
||||
p = malloc(sizeof(struct pstream));
|
||||
p = malloc(sizeof(struct pa_pstream));
|
||||
assert(p);
|
||||
|
||||
p->io = io;
|
||||
iochannel_set_callback(io, io_callback, p);
|
||||
pa_iochannel_set_callback(io, io_callback, p);
|
||||
|
||||
p->dead = 0;
|
||||
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);
|
||||
m->enable_fixed(m, p->mainloop_source, 0);
|
||||
|
||||
p->send_queue = queue_new();
|
||||
p->send_queue = pa_queue_new();
|
||||
assert(p->send_queue);
|
||||
|
||||
p->write.current = NULL;
|
||||
|
|
@ -131,118 +131,118 @@ static void item_free(void *item, void *p) {
|
|||
struct item_info *i = item;
|
||||
assert(i);
|
||||
|
||||
if (i->type == PSTREAM_ITEM_MEMBLOCK) {
|
||||
if (i->type == PA_PSTREAM_ITEM_MEMBLOCK) {
|
||||
assert(i->chunk.memblock);
|
||||
memblock_unref(i->chunk.memblock);
|
||||
pa_memblock_unref(i->chunk.memblock);
|
||||
} else {
|
||||
assert(i->type == PSTREAM_ITEM_PACKET);
|
||||
assert(i->type == PA_PSTREAM_ITEM_PACKET);
|
||||
assert(i->packet);
|
||||
packet_unref(i->packet);
|
||||
pa_packet_unref(i->packet);
|
||||
}
|
||||
|
||||
free(i);
|
||||
}
|
||||
|
||||
void pstream_free(struct pstream *p) {
|
||||
void pa_pstream_free(struct pa_pstream *p) {
|
||||
assert(p);
|
||||
|
||||
iochannel_free(p->io);
|
||||
queue_free(p->send_queue, item_free, NULL);
|
||||
pa_iochannel_free(p->io);
|
||||
pa_queue_free(p->send_queue, item_free, NULL);
|
||||
|
||||
if (p->write.current)
|
||||
item_free(p->write.current, NULL);
|
||||
|
||||
if (p->read.memblock)
|
||||
memblock_unref(p->read.memblock);
|
||||
pa_memblock_unref(p->read.memblock);
|
||||
|
||||
if (p->read.packet)
|
||||
packet_unref(p->read.packet);
|
||||
pa_packet_unref(p->read.packet);
|
||||
|
||||
p->mainloop->cancel_fixed(p->mainloop, p->mainloop_source);
|
||||
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);
|
||||
|
||||
p->send_callback = callback;
|
||||
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;
|
||||
assert(p && packet);
|
||||
|
||||
i = malloc(sizeof(struct item_info));
|
||||
assert(i);
|
||||
i->type = PSTREAM_ITEM_PACKET;
|
||||
i->packet = packet_ref(packet);
|
||||
i->type = PA_PSTREAM_ITEM_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);
|
||||
}
|
||||
|
||||
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;
|
||||
assert(p && channel != (uint32_t) -1 && chunk);
|
||||
|
||||
i = malloc(sizeof(struct item_info));
|
||||
assert(i);
|
||||
i->type = PSTREAM_ITEM_MEMBLOCK;
|
||||
i->type = PA_PSTREAM_ITEM_MEMBLOCK;
|
||||
i->chunk = *chunk;
|
||||
i->channel = channel;
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
p->recieve_packet_callback = callback;
|
||||
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);
|
||||
|
||||
p->recieve_memblock_callback = callback;
|
||||
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);
|
||||
|
||||
if (!(p->write.current = queue_pop(p->send_queue)))
|
||||
if (!(p->write.current = pa_queue_pop(p->send_queue)))
|
||||
return;
|
||||
|
||||
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);
|
||||
p->write.data = p->write.current->packet->data;
|
||||
p->write.descriptor[PSTREAM_DESCRIPTOR_LENGTH] = htonl(p->write.current->packet->length);
|
||||
p->write.descriptor[PSTREAM_DESCRIPTOR_CHANNEL] = htonl((uint32_t) -1);
|
||||
p->write.descriptor[PSTREAM_DESCRIPTOR_DELTA] = 0;
|
||||
p->write.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH] = htonl(p->write.current->packet->length);
|
||||
p->write.descriptor[PA_PSTREAM_DESCRIPTOR_CHANNEL] = htonl((uint32_t) -1);
|
||||
p->write.descriptor[PA_PSTREAM_DESCRIPTOR_DELTA] = 0;
|
||||
} 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.descriptor[PSTREAM_DESCRIPTOR_LENGTH] = htonl(p->write.current->chunk.length);
|
||||
p->write.descriptor[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_LENGTH] = htonl(p->write.current->chunk.length);
|
||||
p->write.descriptor[PA_PSTREAM_DESCRIPTOR_CHANNEL] = htonl(p->write.current->channel);
|
||||
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;
|
||||
size_t l;
|
||||
ssize_t r;
|
||||
assert(p);
|
||||
|
||||
if (p->dead || !iochannel_is_writable(p->io))
|
||||
if (p->dead || !pa_iochannel_is_writable(p->io))
|
||||
return;
|
||||
|
||||
if (!p->write.current)
|
||||
|
|
@ -253,25 +253,25 @@ static void do_write(struct pstream *p) {
|
|||
|
||||
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;
|
||||
l = PSTREAM_DESCRIPTOR_SIZE - p->write.index;
|
||||
l = PA_PSTREAM_DESCRIPTOR_SIZE - p->write.index;
|
||||
} else {
|
||||
d = (void*) p->write.data + p->write.index - PSTREAM_DESCRIPTOR_SIZE;
|
||||
l = ntohl(p->write.descriptor[PSTREAM_DESCRIPTOR_LENGTH]) - (p->write.index - PSTREAM_DESCRIPTOR_SIZE);
|
||||
d = (void*) p->write.data + p->write.index - PA_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;
|
||||
|
||||
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);
|
||||
item_free(p->write.current, (void *) 1);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -283,68 +283,68 @@ die:
|
|||
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;
|
||||
size_t l;
|
||||
ssize_t r;
|
||||
assert(p);
|
||||
|
||||
if (p->dead || !iochannel_is_readable(p->io))
|
||||
if (p->dead || !pa_iochannel_is_readable(p->io))
|
||||
return;
|
||||
|
||||
if (p->read.index < PSTREAM_DESCRIPTOR_SIZE) {
|
||||
if (p->read.index < PA_PSTREAM_DESCRIPTOR_SIZE) {
|
||||
d = (void*) p->read.descriptor + p->read.index;
|
||||
l = PSTREAM_DESCRIPTOR_SIZE - p->read.index;
|
||||
l = PA_PSTREAM_DESCRIPTOR_SIZE - p->read.index;
|
||||
} else {
|
||||
assert(p->read.data);
|
||||
d = (void*) p->read.data + p->read.index - PSTREAM_DESCRIPTOR_SIZE;
|
||||
l = ntohl(p->read.descriptor[PSTREAM_DESCRIPTOR_LENGTH]) - (p->read.index - PSTREAM_DESCRIPTOR_SIZE);
|
||||
d = (void*) p->read.data + p->read.index - PA_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;
|
||||
|
||||
p->read.index += r;
|
||||
|
||||
if (p->read.index == PSTREAM_DESCRIPTOR_SIZE) {
|
||||
if (p->read.index == PA_PSTREAM_DESCRIPTOR_SIZE) {
|
||||
/* Reading of frame descriptor complete */
|
||||
|
||||
/* 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;
|
||||
|
||||
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 */
|
||||
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);
|
||||
p->read.data = p->read.packet->data;
|
||||
} else {
|
||||
/* 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);
|
||||
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 */
|
||||
|
||||
if (p->read.memblock && p->recieve_memblock_callback) { /* Is this memblock data? Than pass it to the user */
|
||||
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) {
|
||||
struct memchunk chunk;
|
||||
struct pa_memchunk chunk;
|
||||
|
||||
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;
|
||||
|
||||
if (p->recieve_memblock_callback(p,
|
||||
ntohl(p->read.descriptor[PSTREAM_DESCRIPTOR_CHANNEL]),
|
||||
(int32_t) ntohl(p->read.descriptor[PSTREAM_DESCRIPTOR_DELTA]),
|
||||
ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_CHANNEL]),
|
||||
(int32_t) ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_DELTA]),
|
||||
&chunk,
|
||||
p->recieve_memblock_callback_userdata) < 0)
|
||||
goto die;
|
||||
|
|
@ -352,11 +352,11 @@ static void do_read(struct pstream *p) {
|
|||
}
|
||||
|
||||
/* 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) {
|
||||
assert(!p->read.packet);
|
||||
|
||||
memblock_unref(p->read.memblock);
|
||||
pa_memblock_unref(p->read.memblock);
|
||||
p->read.memblock = NULL;
|
||||
} else {
|
||||
int r = 0;
|
||||
|
|
@ -365,7 +365,7 @@ static void do_read(struct pstream *p) {
|
|||
if (p->recieve_packet_callback)
|
||||
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;
|
||||
|
||||
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);
|
||||
p->die_callback = callback;
|
||||
p->die_callback_userdata = userdata;
|
||||
|
|
|
|||
|
|
@ -9,18 +9,18 @@
|
|||
#include "mainloop-api.h"
|
||||
#include "memchunk.h"
|
||||
|
||||
struct pstream;
|
||||
struct pa_pstream;
|
||||
|
||||
struct pstream* pstream_new(struct pa_mainloop_api *m, struct iochannel *io);
|
||||
void pstream_free(struct pstream*p);
|
||||
struct pa_pstream* pa_pstream_new(struct pa_mainloop_api *m, struct pa_iochannel *io);
|
||||
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 pstream_send_packet(struct pstream*p, struct packet *packet);
|
||||
void pstream_send_memblock(struct pstream*p, uint32_t channel, int32_t delta, struct memchunk *chunk);
|
||||
void pa_pstream_set_send_callback(struct pa_pstream*p, void (*callback) (struct pa_pstream *p, void *userdata), void *userdata);
|
||||
void pa_pstream_send_packet(struct pa_pstream*p, struct pa_packet *packet);
|
||||
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 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_packet_callback(struct pa_pstream *p, int (*callback) (struct pa_pstream *p, struct pa_packet *packet, 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
|
||||
|
|
|
|||
14
src/queue.c
14
src/queue.c
|
|
@ -8,20 +8,20 @@ struct queue_entry {
|
|||
void *data;
|
||||
};
|
||||
|
||||
struct queue {
|
||||
struct pa_queue {
|
||||
struct queue_entry *front, *back;
|
||||
unsigned length;
|
||||
};
|
||||
|
||||
struct queue* queue_new(void) {
|
||||
struct queue *q = malloc(sizeof(struct queue));
|
||||
struct pa_queue* pa_queue_new(void) {
|
||||
struct pa_queue *q = malloc(sizeof(struct pa_queue));
|
||||
assert(q);
|
||||
q->front = q->back = NULL;
|
||||
q->length = 0;
|
||||
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;
|
||||
assert(q);
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ void queue_free(struct queue* q, void (*destroy)(void *p, void *userdata), void
|
|||
free(q);
|
||||
}
|
||||
|
||||
void queue_push(struct queue *q, void *p) {
|
||||
void pa_queue_push(struct pa_queue *q, void *p) {
|
||||
struct queue_entry *e;
|
||||
|
||||
e = malloc(sizeof(struct queue_entry));
|
||||
|
|
@ -58,7 +58,7 @@ void queue_push(struct queue *q, void *p) {
|
|||
q->length++;
|
||||
}
|
||||
|
||||
void* queue_pop(struct queue *q) {
|
||||
void* pa_queue_pop(struct pa_queue *q) {
|
||||
void *p;
|
||||
struct queue_entry *e;
|
||||
assert(q);
|
||||
|
|
@ -78,7 +78,7 @@ void* queue_pop(struct queue *q) {
|
|||
return p;
|
||||
}
|
||||
|
||||
int queue_is_empty(struct queue *q) {
|
||||
int pa_queue_is_empty(struct pa_queue *q) {
|
||||
assert(q);
|
||||
return q->length == 0;
|
||||
}
|
||||
|
|
|
|||
12
src/queue.h
12
src/queue.h
|
|
@ -1,13 +1,13 @@
|
|||
#ifndef fooqueuehfoo
|
||||
#define fooqueuehfoo
|
||||
|
||||
struct queue;
|
||||
struct pa_queue;
|
||||
|
||||
struct queue* queue_new(void);
|
||||
void queue_free(struct queue* q, void (*destroy)(void *p, void *userdata), void *userdata);
|
||||
void queue_push(struct queue *q, void *p);
|
||||
void* queue_pop(struct queue *q);
|
||||
struct pa_queue* pa_queue_new(void);
|
||||
void pa_queue_free(struct pa_queue* q, void (*destroy)(void *p, void *userdata), void *userdata);
|
||||
void pa_queue_push(struct pa_queue *q, void *p);
|
||||
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
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#include "resampler.h"
|
||||
#include "sconv.h"
|
||||
|
||||
struct resampler {
|
||||
struct pa_resampler {
|
||||
struct pa_sample_spec i_ss, o_ss;
|
||||
float* i_buf, *o_buf;
|
||||
unsigned i_alloc, o_alloc;
|
||||
|
|
@ -14,13 +14,13 @@ struct resampler {
|
|||
|
||||
int channels;
|
||||
|
||||
convert_to_float32_func_t to_float32_func;
|
||||
convert_from_float32_func_t from_float32_func;
|
||||
pa_convert_to_float32_func_t to_float32_func;
|
||||
pa_convert_from_float32_func_t from_float32_func;
|
||||
SRC_STATE *src_state;
|
||||
};
|
||||
|
||||
struct resampler* resampler_new(const struct pa_sample_spec *a, const struct pa_sample_spec *b) {
|
||||
struct resampler *r;
|
||||
struct pa_resampler* pa_resampler_new(const struct pa_sample_spec *a, const struct pa_sample_spec *b) {
|
||||
struct pa_resampler *r;
|
||||
int err;
|
||||
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)
|
||||
goto fail;
|
||||
|
||||
r = malloc(sizeof(struct resampler));
|
||||
r = malloc(sizeof(struct pa_resampler));
|
||||
assert(r);
|
||||
|
||||
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->o_sz = pa_sample_size(b);
|
||||
|
||||
r->to_float32_func = get_convert_to_float32_function(a->format);
|
||||
r->from_float32_func = get_convert_from_float32_function(b->format);
|
||||
r->to_float32_func = pa_get_convert_to_float32_function(a->format);
|
||||
r->from_float32_func = pa_get_convert_from_float32_function(b->format);
|
||||
|
||||
assert(r->to_float32_func && r->from_float32_func);
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ fail:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void resampler_free(struct resampler *r) {
|
||||
void pa_resampler_free(struct pa_resampler *r) {
|
||||
assert(r);
|
||||
if (r->src_state)
|
||||
src_delete(r->src_state);
|
||||
|
|
@ -76,14 +76,14 @@ void resampler_free(struct resampler *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);
|
||||
|
||||
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;
|
||||
float *cbuf;
|
||||
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;
|
||||
}
|
||||
|
||||
out->memblock = memblock_new(out->length = (ons*r->o_sz));
|
||||
out->memblock = pa_memblock_new(out->length = (ons*r->o_sz));
|
||||
out->index = 0;
|
||||
assert(out->memblock);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@
|
|||
#include "memblock.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);
|
||||
void resampler_free(struct resampler *r);
|
||||
struct pa_resampler* pa_resampler_new(const struct pa_sample_spec *a, const struct pa_sample_spec *b);
|
||||
void pa_resampler_free(struct pa_resampler *r);
|
||||
|
||||
size_t resampler_request(struct resampler *r, size_t out_length);
|
||||
void resampler_run(struct resampler *r, const struct memchunk *in, struct memchunk *out);
|
||||
size_t pa_resampler_request(struct pa_resampler *r, size_t out_length);
|
||||
void pa_resampler_run(struct pa_resampler *r, const struct pa_memchunk *in, struct pa_memchunk *out);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -4,26 +4,26 @@
|
|||
|
||||
#include "sample-util.h"
|
||||
|
||||
struct pa_sample_spec default_sample_spec = {
|
||||
struct pa_sample_spec pa_default_sample_spec = {
|
||||
.format = PA_SAMPLE_S16NE,
|
||||
.rate = 44100,
|
||||
.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);
|
||||
memblock_assert_exclusive(b);
|
||||
silence_memory(b->data, b->length, spec);
|
||||
pa_memblock_assert_exclusive(b);
|
||||
pa_silence_memory(b->data, b->length, spec);
|
||||
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);
|
||||
memblock_assert_exclusive(c->memblock);
|
||||
silence_memory(c->memblock->data+c->index, c->length, spec);
|
||||
pa_memblock_assert_exclusive(c->memblock);
|
||||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
assert(channels && data && length && spec);
|
||||
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)
|
||||
return d;
|
||||
|
||||
if (volume == VOLUME_MUTE)
|
||||
if (volume == PA_VOLUME_MUTE)
|
||||
v = 0;
|
||||
else {
|
||||
v = *((int16_t*) (channels[c].chunk.memblock->data + channels[c].chunk.index + d));
|
||||
|
||||
if (volume != VOLUME_NORM)
|
||||
v = (int32_t) ((float)v*volume/VOLUME_NORM);
|
||||
if (volume != PA_VOLUME_NORM)
|
||||
v = (int32_t) ((float)v*volume/PA_VOLUME_NORM);
|
||||
}
|
||||
|
||||
sum += v;
|
||||
}
|
||||
|
||||
if (volume == VOLUME_MUTE)
|
||||
if (volume == PA_VOLUME_MUTE)
|
||||
sum = 0;
|
||||
else if (volume != VOLUME_NORM)
|
||||
sum = (int32_t) ((float) sum*volume/VOLUME_NORM);
|
||||
else if (volume != PA_VOLUME_NORM)
|
||||
sum = (int32_t) ((float) sum*volume/PA_VOLUME_NORM);
|
||||
|
||||
if (sum < -0x8000) sum = -0x8000;
|
||||
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;
|
||||
size_t n;
|
||||
assert(c && spec && (c->length % pa_sample_size(spec) == 0));
|
||||
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;
|
||||
|
||||
if (volume == VOLUME_MUTE) {
|
||||
silence_memchunk(c, spec);
|
||||
if (volume == PA_VOLUME_MUTE) {
|
||||
pa_silence_memchunk(c, spec);
|
||||
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);
|
||||
|
||||
t *= volume;
|
||||
t /= VOLUME_NORM;
|
||||
t /= PA_VOLUME_NORM;
|
||||
|
||||
if (t < -0x8000) t = -0x8000;
|
||||
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;
|
||||
p *= b;
|
||||
p /= VOLUME_NORM;
|
||||
p /= PA_VOLUME_NORM;
|
||||
|
||||
return (uint32_t) p;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,27 +5,27 @@
|
|||
#include "memblock.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 VOLUME_MUTE (0)
|
||||
#define PA_VOLUME_NORM (0x100)
|
||||
#define PA_VOLUME_MUTE (0)
|
||||
|
||||
struct memblock *silence_memblock(struct memblock* b, struct pa_sample_spec *spec);
|
||||
void silence_memchunk(struct memchunk *c, struct pa_sample_spec *spec);
|
||||
void silence_memory(void *p, size_t length, struct pa_sample_spec *spec);
|
||||
struct pa_memblock *pa_silence_memblock(struct pa_memblock* b, const struct pa_sample_spec *spec);
|
||||
void pa_silence_memchunk(struct pa_memchunk *c, const struct pa_sample_spec *spec);
|
||||
void pa_silence_memory(void *p, size_t length, const struct pa_sample_spec *spec);
|
||||
|
||||
struct mix_info {
|
||||
struct memchunk chunk;
|
||||
struct pa_mix_info {
|
||||
struct pa_memchunk chunk;
|
||||
uint32_t volume;
|
||||
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
|
||||
|
|
|
|||
17
src/sample.c
17
src/sample.c
|
|
@ -1,3 +1,4 @@
|
|||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "sample.h"
|
||||
|
|
@ -44,7 +45,7 @@ int pa_sample_spec_valid(const struct pa_sample_spec *spec) {
|
|||
if (!spec->rate || !spec->channels)
|
||||
return 0;
|
||||
|
||||
if (spec->format <= 0 || spec->format >= PA_SAMPLE_MAX)
|
||||
if (spec->format >= PA_SAMPLE_MAX)
|
||||
return 0;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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_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
|
||||
|
|
|
|||
9
src/sconv-s16be.c
Normal file
9
src/sconv-s16be.c
Normal 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
7
src/sconv-s16be.h
Normal 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
57
src/sconv-s16le.c
Normal 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
7
src/sconv-s16le.h
Normal 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
|
||||
47
src/sconv.c
47
src/sconv.c
|
|
@ -1,19 +1,23 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "endianmacros.h"
|
||||
#include "sconv.h"
|
||||
|
||||
static void s16le_to_float32(unsigned n, const void *a, unsigned an, float *b) {
|
||||
const int16_t *ca = a;
|
||||
#include "sconv-s16le.h"
|
||||
#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);
|
||||
|
||||
for (; n > 0; n--) {
|
||||
unsigned i;
|
||||
float sum = 0;
|
||||
|
||||
for (i = 0; i < an; i++) {
|
||||
int16_t s = *(ca++);
|
||||
sum += ((float) INT16_FROM_LE(s))/0x7FFF;
|
||||
uint8_t v = *(ca++);
|
||||
sum += (((float) v)-127)/127;
|
||||
}
|
||||
|
||||
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) {
|
||||
int16_t *cb = b;
|
||||
assert(n && a && b && bn);
|
||||
|
||||
for (; n > 0; n--) {
|
||||
static void u8_from_float32(unsigned n, const float *a, void *b, unsigned bn) {
|
||||
unsigned i;
|
||||
int16_t s;
|
||||
uint8_t *cb = b;
|
||||
|
||||
assert(n && a && b && bn);
|
||||
for (; n > 0; n--) {
|
||||
float v = *(a++);
|
||||
uint8_t u;
|
||||
|
||||
if (v > 1)
|
||||
v = 1;
|
||||
|
||||
if (v < -1)
|
||||
v = -1;
|
||||
|
||||
s = (int16_t) (v * 0x7FFF);
|
||||
u = (uint8_t) (v*127+127);
|
||||
|
||||
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) {
|
||||
case PA_SAMPLE_U8:
|
||||
return u8_to_float32;
|
||||
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:
|
||||
return float32_to_float32;
|
||||
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) {
|
||||
case PA_SAMPLE_U8:
|
||||
return u8_from_float32;
|
||||
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:
|
||||
return float32_from_float32;
|
||||
default:
|
||||
|
|
|
|||
10
src/sconv.h
10
src/sconv.h
|
|
@ -3,12 +3,10 @@
|
|||
|
||||
#include "sample.h"
|
||||
|
||||
typedef void (*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);
|
||||
|
||||
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);
|
||||
|
||||
typedef void (*pa_convert_to_float32_func_t)(unsigned n, const void *a, unsigned an, float *b);
|
||||
typedef void (*pa_convert_from_float32_func_t)(unsigned n, const float *a, void *b, unsigned bn);
|
||||
|
||||
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
|
||||
|
|
|
|||
144
src/sink.c
144
src/sink.c
|
|
@ -11,16 +11,17 @@
|
|||
|
||||
#define MAX_MIX_CHANNELS 32
|
||||
|
||||
struct sink* sink_new(struct core *core, const char *name, int fail, const struct pa_sample_spec *spec) {
|
||||
struct sink *s;
|
||||
struct pa_sink* pa_sink_new(struct pa_core *core, const char *name, int fail, const struct pa_sample_spec *spec) {
|
||||
struct pa_sink *s;
|
||||
char *n = NULL;
|
||||
char st[256];
|
||||
int r;
|
||||
assert(core && spec);
|
||||
|
||||
s = malloc(sizeof(struct sink));
|
||||
s = malloc(sizeof(struct pa_sink));
|
||||
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);
|
||||
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->core = core;
|
||||
s->sample_spec = *spec;
|
||||
s->inputs = idxset_new(NULL, NULL);
|
||||
s->inputs = pa_idxset_new(NULL, NULL);
|
||||
|
||||
if (name) {
|
||||
n = malloc(strlen(name)+9);
|
||||
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);
|
||||
free(n);
|
||||
|
||||
s->volume = VOLUME_NORM;
|
||||
s->volume = PA_VOLUME_NORM;
|
||||
|
||||
s->notify = NULL;
|
||||
s->get_latency = NULL;
|
||||
s->userdata = NULL;
|
||||
|
||||
r = idxset_put(core->sinks, s, &s->index);
|
||||
assert(s->index != IDXSET_INVALID && r >= 0);
|
||||
r = pa_idxset_put(core->sinks, s, &s->index);
|
||||
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;
|
||||
}
|
||||
|
||||
void sink_free(struct sink *s) {
|
||||
struct sink_input *i, *j = NULL;
|
||||
void pa_sink_free(struct pa_sink *s) {
|
||||
struct pa_sink_input *i, *j = NULL;
|
||||
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);
|
||||
sink_input_kill(i);
|
||||
pa_sink_input_kill(i);
|
||||
j = i;
|
||||
}
|
||||
idxset_free(s->inputs, NULL, NULL);
|
||||
pa_idxset_free(s->inputs, NULL, NULL);
|
||||
|
||||
source_free(s->monitor_source);
|
||||
idxset_remove_by_data(s->core->sinks, s, NULL);
|
||||
pa_source_free(s->monitor_source);
|
||||
pa_idxset_remove_by_data(s->core->sinks, s, NULL);
|
||||
|
||||
fprintf(stderr, "sink: freed %u \"%s\"\n", s->index, s->name);
|
||||
|
||||
|
|
@ -75,22 +77,22 @@ void sink_free(struct sink *s) {
|
|||
free(s);
|
||||
}
|
||||
|
||||
void sink_notify(struct sink*s) {
|
||||
void pa_sink_notify(struct pa_sink*s) {
|
||||
assert(s);
|
||||
|
||||
if (s->notify)
|
||||
s->notify(s);
|
||||
}
|
||||
|
||||
static unsigned fill_mix_info(struct sink *s, struct mix_info *info, unsigned maxinfo) {
|
||||
uint32_t index = IDXSET_INVALID;
|
||||
struct sink_input *i;
|
||||
static unsigned fill_mix_info(struct pa_sink *s, struct pa_mix_info *info, unsigned maxinfo) {
|
||||
uint32_t index = PA_IDXSET_INVALID;
|
||||
struct pa_sink_input *i;
|
||||
unsigned n = 0;
|
||||
|
||||
assert(s && info);
|
||||
|
||||
for (i = idxset_first(s->inputs, &index); maxinfo > 0 && i; i = idxset_next(s->inputs, &index)) {
|
||||
if (sink_input_peek(i, &info->chunk) < 0)
|
||||
for (i = pa_idxset_first(s->inputs, &index); maxinfo > 0 && i; i = pa_idxset_next(s->inputs, &index)) {
|
||||
if (pa_sink_input_peek(i, &info->chunk) < 0)
|
||||
continue;
|
||||
|
||||
info->volume = i->volume;
|
||||
|
|
@ -106,20 +108,20 @@ static unsigned fill_mix_info(struct sink *s, struct mix_info *info, unsigned ma
|
|||
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);
|
||||
|
||||
for (; maxinfo > 0; maxinfo--, info++) {
|
||||
struct sink_input *i = info->userdata;
|
||||
struct pa_sink_input *i = info->userdata;
|
||||
assert(i && info->chunk.memblock);
|
||||
|
||||
memblock_unref(info->chunk.memblock);
|
||||
sink_input_drop(i, length);
|
||||
pa_memblock_unref(info->chunk.memblock);
|
||||
pa_sink_input_drop(i, length);
|
||||
}
|
||||
}
|
||||
|
||||
int sink_render(struct sink*s, size_t length, struct memchunk *result) {
|
||||
struct mix_info info[MAX_MIX_CHANNELS];
|
||||
int pa_sink_render(struct pa_sink*s, size_t length, struct pa_memchunk *result) {
|
||||
struct pa_mix_info info[MAX_MIX_CHANNELS];
|
||||
unsigned n;
|
||||
size_t l;
|
||||
assert(s && length && result);
|
||||
|
|
@ -130,29 +132,29 @@ int sink_render(struct sink*s, size_t length, struct memchunk *result) {
|
|||
return -1;
|
||||
|
||||
if (n == 1) {
|
||||
uint32_t volume = VOLUME_NORM;
|
||||
struct sink_info *i = info[0].userdata;
|
||||
uint32_t volume = PA_VOLUME_NORM;
|
||||
struct pa_sink_input *i = info[0].userdata;
|
||||
assert(i);
|
||||
*result = info[0].chunk;
|
||||
memblock_ref(result->memblock);
|
||||
pa_memblock_ref(result->memblock);
|
||||
|
||||
if (result->length > length)
|
||||
result->length = length;
|
||||
|
||||
l = result->length;
|
||||
|
||||
if (s->volume != VOLUME_NORM || info[0].volume != VOLUME_NORM)
|
||||
volume = volume_multiply(s->volume, info[0].volume);
|
||||
if (s->volume != PA_VOLUME_NORM || info[0].volume != PA_VOLUME_NORM)
|
||||
volume = pa_volume_multiply(s->volume, info[0].volume);
|
||||
|
||||
if (volume != VOLUME_NORM) {
|
||||
memchunk_make_writable(result);
|
||||
volume_memchunk(result, &s->sample_spec, volume);
|
||||
if (volume != PA_VOLUME_NORM) {
|
||||
pa_memchunk_make_writable(result);
|
||||
pa_volume_memchunk(result, &s->sample_spec, volume);
|
||||
}
|
||||
} else {
|
||||
result->memblock = memblock_new(length);
|
||||
result->memblock = pa_memblock_new(length);
|
||||
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;
|
||||
|
||||
assert(l);
|
||||
|
|
@ -161,17 +163,17 @@ int sink_render(struct sink*s, size_t length, struct memchunk *result) {
|
|||
inputs_drop(s, info, n, l);
|
||||
|
||||
assert(s->monitor_source);
|
||||
source_post(s->monitor_source, result);
|
||||
pa_source_post(s->monitor_source, result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sink_render_into(struct sink*s, struct memchunk *target) {
|
||||
struct mix_info info[MAX_MIX_CHANNELS];
|
||||
int pa_sink_render_into(struct pa_sink*s, struct pa_memchunk *target) {
|
||||
struct pa_mix_info info[MAX_MIX_CHANNELS];
|
||||
unsigned n;
|
||||
size_t l;
|
||||
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);
|
||||
|
||||
|
|
@ -179,8 +181,8 @@ int sink_render_into(struct sink*s, struct memchunk *target) {
|
|||
return -1;
|
||||
|
||||
if (n == 1) {
|
||||
uint32_t volume = VOLUME_NORM;
|
||||
struct sink_info *i = info[0].userdata;
|
||||
uint32_t volume = PA_VOLUME_NORM;
|
||||
struct pa_sink_info *i = info[0].userdata;
|
||||
assert(i);
|
||||
|
||||
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);
|
||||
target->length = l;
|
||||
|
||||
if (s->volume != VOLUME_NORM || info[0].volume != VOLUME_NORM)
|
||||
volume = volume_multiply(s->volume, info[0].volume);
|
||||
if (s->volume != PA_VOLUME_NORM || info[0].volume != PA_VOLUME_NORM)
|
||||
volume = pa_volume_multiply(s->volume, info[0].volume);
|
||||
|
||||
if (volume != VOLUME_NORM)
|
||||
volume_memchunk(target, &s->sample_spec, volume);
|
||||
if (volume != PA_VOLUME_NORM)
|
||||
pa_volume_memchunk(target, &s->sample_spec, volume);
|
||||
} 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);
|
||||
inputs_drop(s, info, n, l);
|
||||
|
||||
assert(s->monitor_source);
|
||||
source_post(s->monitor_source, target);
|
||||
pa_source_post(s->monitor_source, target);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sink_render_into_full(struct sink *s, struct memchunk *target) {
|
||||
struct memchunk chunk;
|
||||
void pa_sink_render_into_full(struct pa_sink *s, struct pa_memchunk *target) {
|
||||
struct pa_memchunk chunk;
|
||||
size_t l, d;
|
||||
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.length -= d;
|
||||
|
||||
if (sink_render_into(s, &chunk) < 0)
|
||||
if (pa_sink_render_into(s, &chunk) < 0)
|
||||
break;
|
||||
|
||||
d += chunk.length;
|
||||
|
|
@ -230,11 +232,11 @@ void sink_render_into_full(struct sink *s, struct memchunk *target) {
|
|||
chunk = *target;
|
||||
chunk.index += 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);
|
||||
|
||||
if (!s->get_latency)
|
||||
|
|
@ -243,38 +245,38 @@ uint32_t sink_get_latency(struct sink *s) {
|
|||
return s->get_latency(s);
|
||||
}
|
||||
|
||||
struct sink* sink_get_default(struct core *c) {
|
||||
struct sink *sink;
|
||||
struct pa_sink* pa_sink_get_default(struct pa_core *c) {
|
||||
struct pa_sink *sink;
|
||||
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;
|
||||
|
||||
if (!(sink = idxset_first(c->sinks, &c->default_sink_index)))
|
||||
if (!(sink = pa_idxset_first(c->sinks, &c->default_sink_index)))
|
||||
return NULL;
|
||||
|
||||
fprintf(stderr, "core: default sink vanished, setting to %u.\n", sink->index);
|
||||
return sink;
|
||||
}
|
||||
|
||||
char *sink_list_to_string(struct core *c) {
|
||||
struct strbuf *s;
|
||||
struct sink *sink, *default_sink;
|
||||
uint32_t index = IDXSET_INVALID;
|
||||
char *pa_sink_list_to_string(struct pa_core *c) {
|
||||
struct pa_strbuf *s;
|
||||
struct pa_sink *sink, *default_sink;
|
||||
uint32_t index = PA_IDXSET_INVALID;
|
||||
assert(c);
|
||||
|
||||
s = strbuf_new();
|
||||
s = pa_strbuf_new();
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
32
src/sink.h
32
src/sink.h
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef foosinkhfoo
|
||||
#define foosinkhfoo
|
||||
|
||||
struct sink;
|
||||
struct pa_sink;
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
|
|
@ -10,37 +10,37 @@ struct sink;
|
|||
#include "idxset.h"
|
||||
#include "source.h"
|
||||
|
||||
struct sink {
|
||||
struct pa_sink {
|
||||
uint32_t index;
|
||||
|
||||
char *name;
|
||||
struct core *core;
|
||||
struct pa_core *core;
|
||||
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;
|
||||
|
||||
void (*notify)(struct sink*sink);
|
||||
uint32_t (*get_latency)(struct sink *s);
|
||||
void (*notify)(struct pa_sink*sink);
|
||||
uint32_t (*get_latency)(struct pa_sink *s);
|
||||
void *userdata;
|
||||
};
|
||||
|
||||
struct sink* sink_new(struct core *core, const char *name, int fail, const struct pa_sample_spec *spec);
|
||||
void sink_free(struct sink* s);
|
||||
struct pa_sink* pa_sink_new(struct pa_core *core, const char *name, int fail, const struct pa_sample_spec *spec);
|
||||
void pa_sink_free(struct pa_sink* s);
|
||||
|
||||
int sink_render(struct sink*s, size_t length, struct memchunk *result);
|
||||
int sink_render_into(struct sink*s, struct memchunk *target);
|
||||
void sink_render_into_full(struct sink *s, struct memchunk *target);
|
||||
int pa_sink_render(struct pa_sink*s, size_t length, struct pa_memchunk *result);
|
||||
int pa_sink_render_into(struct pa_sink*s, struct pa_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);
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
@ -8,17 +9,18 @@
|
|||
|
||||
#define CONVERT_BUFFER_LENGTH 4096
|
||||
|
||||
struct sink_input* sink_input_new(struct sink *s, const char *name, const struct pa_sample_spec *spec) {
|
||||
struct sink_input *i;
|
||||
struct resampler *resampler = NULL;
|
||||
struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, const struct pa_sample_spec *spec) {
|
||||
struct pa_sink_input *i;
|
||||
struct pa_resampler *resampler = NULL;
|
||||
int r;
|
||||
char st[256];
|
||||
assert(s && 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;
|
||||
|
||||
i = malloc(sizeof(struct sink_input));
|
||||
i = malloc(sizeof(struct pa_sink_input));
|
||||
assert(i);
|
||||
i->name = name ? strdup(name) : NULL;
|
||||
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->userdata = NULL;
|
||||
|
||||
i->volume = VOLUME_NORM;
|
||||
i->volume = PA_VOLUME_NORM;
|
||||
|
||||
i->resampled_chunk.memblock = NULL;
|
||||
i->resampled_chunk.index = i->resampled_chunk.length = 0;
|
||||
i->resampler = resampler;
|
||||
|
||||
assert(s->core);
|
||||
r = idxset_put(s->core->sink_inputs, i, &i->index);
|
||||
assert(r == 0 && i->index != IDXSET_INVALID);
|
||||
r = idxset_put(s->inputs, i, NULL);
|
||||
r = pa_idxset_put(s->core->sink_inputs, i, &i->index);
|
||||
assert(r == 0 && i->index != PA_IDXSET_INVALID);
|
||||
r = pa_idxset_put(s->inputs, i, NULL);
|
||||
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;
|
||||
}
|
||||
|
||||
void sink_input_free(struct sink_input* i) {
|
||||
void pa_sink_input_free(struct pa_sink_input* i) {
|
||||
assert(i);
|
||||
|
||||
assert(i->sink && i->sink->core);
|
||||
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->core->sink_inputs, i, NULL);
|
||||
pa_idxset_remove_by_data(i->sink->inputs, i, NULL);
|
||||
|
||||
if (i->resampled_chunk.memblock)
|
||||
memblock_unref(i->resampled_chunk.memblock);
|
||||
pa_memblock_unref(i->resampled_chunk.memblock);
|
||||
if (i->resampler)
|
||||
resampler_free(i->resampler);
|
||||
pa_resampler_free(i->resampler);
|
||||
|
||||
free(i->name);
|
||||
free(i);
|
||||
}
|
||||
|
||||
void sink_input_kill(struct sink_input*i) {
|
||||
void pa_sink_input_kill(struct pa_sink_input*i) {
|
||||
assert(i);
|
||||
|
||||
if (i->kill)
|
||||
i->kill(i);
|
||||
}
|
||||
|
||||
char *sink_input_list_to_string(struct core *c) {
|
||||
struct strbuf *s;
|
||||
struct sink_input *i;
|
||||
uint32_t index = IDXSET_INVALID;
|
||||
char *pa_sink_input_list_to_string(struct pa_core *c) {
|
||||
struct pa_strbuf *s;
|
||||
struct pa_sink_input *i;
|
||||
uint32_t index = PA_IDXSET_INVALID;
|
||||
assert(c);
|
||||
|
||||
s = strbuf_new();
|
||||
s = pa_strbuf_new();
|
||||
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);
|
||||
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->name,
|
||||
i->sink->index,
|
||||
(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;
|
||||
|
||||
assert(i);
|
||||
|
|
@ -100,43 +105,43 @@ uint32_t sink_input_get_latency(struct sink_input *i) {
|
|||
l += i->get_latency(i);
|
||||
|
||||
assert(i->sink);
|
||||
l += sink_get_latency(i->sink);
|
||||
l += pa_sink_get_latency(i->sink);
|
||||
|
||||
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);
|
||||
|
||||
if (!i->resampler)
|
||||
return i->peek(i, chunk);
|
||||
|
||||
if (!i->resampled_chunk.memblock) {
|
||||
struct memchunk tchunk;
|
||||
struct pa_memchunk tchunk;
|
||||
size_t l;
|
||||
int ret;
|
||||
|
||||
if ((ret = i->peek(i, &tchunk)) < 0)
|
||||
return ret;
|
||||
|
||||
l = resampler_request(i->resampler, CONVERT_BUFFER_LENGTH);
|
||||
l = pa_resampler_request(i->resampler, CONVERT_BUFFER_LENGTH);
|
||||
if (tchunk.length > l)
|
||||
tchunk.length = l;
|
||||
|
||||
i->drop(i, tchunk.length);
|
||||
|
||||
resampler_run(i->resampler, &tchunk, &i->resampled_chunk);
|
||||
memblock_unref(tchunk.memblock);
|
||||
pa_resampler_run(i->resampler, &tchunk, &i->resampled_chunk);
|
||||
pa_memblock_unref(tchunk.memblock);
|
||||
}
|
||||
|
||||
assert(i->resampled_chunk.memblock && i->resampled_chunk.length);
|
||||
*chunk = i->resampled_chunk;
|
||||
memblock_ref(i->resampled_chunk.memblock);
|
||||
pa_memblock_ref(i->resampled_chunk.memblock);
|
||||
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);
|
||||
|
||||
if (!i->resampler) {
|
||||
|
|
@ -150,7 +155,7 @@ void sink_input_drop(struct sink_input *i, size_t length) {
|
|||
i->resampled_chunk.length -= 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.index = i->resampled_chunk.length = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,36 +8,36 @@
|
|||
#include "memblockq.h"
|
||||
#include "resampler.h"
|
||||
|
||||
struct sink_input {
|
||||
struct pa_sink_input {
|
||||
uint32_t index;
|
||||
|
||||
char *name;
|
||||
struct sink *sink;
|
||||
struct pa_sink *sink;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t volume;
|
||||
|
||||
int (*peek) (struct sink_input *i, struct memchunk *chunk);
|
||||
void (*drop) (struct sink_input *i, size_t length);
|
||||
void (*kill) (struct sink_input *i);
|
||||
uint32_t (*get_latency) (struct sink_input *i);
|
||||
int (*peek) (struct pa_sink_input *i, struct pa_memchunk *chunk);
|
||||
void (*drop) (struct pa_sink_input *i, size_t length);
|
||||
void (*kill) (struct pa_sink_input *i);
|
||||
uint32_t (*get_latency) (struct pa_sink_input *i);
|
||||
|
||||
void *userdata;
|
||||
|
||||
struct memchunk resampled_chunk;
|
||||
struct resampler *resampler;
|
||||
struct pa_memchunk resampled_chunk;
|
||||
struct pa_resampler *resampler;
|
||||
};
|
||||
|
||||
struct sink_input* sink_input_new(struct sink *s, const char *name, const struct pa_sample_spec *spec);
|
||||
void sink_input_free(struct sink_input* i);
|
||||
struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, const struct pa_sample_spec *spec);
|
||||
void pa_sink_input_free(struct pa_sink_input* i);
|
||||
|
||||
/* Code that didn't create the input stream should call this function to
|
||||
* 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);
|
||||
char *sink_input_list_to_string(struct core *c);
|
||||
uint32_t pa_sink_input_get_latency(struct pa_sink_input *i);
|
||||
char *pa_sink_input_list_to_string(struct pa_core *c);
|
||||
|
||||
int sink_input_peek(struct sink_input *i, struct memchunk *chunk);
|
||||
void sink_input_drop(struct sink_input *i, size_t length);
|
||||
int pa_sink_input_peek(struct pa_sink_input *i, struct pa_memchunk *chunk);
|
||||
void pa_sink_input_drop(struct pa_sink_input *i, size_t length);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -11,20 +11,20 @@
|
|||
#include "socket-client.h"
|
||||
#include "util.h"
|
||||
|
||||
struct socket_client {
|
||||
struct pa_socket_client {
|
||||
struct pa_mainloop_api *mainloop;
|
||||
int fd;
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
static struct socket_client*socket_client_new(struct pa_mainloop_api *m) {
|
||||
struct socket_client *c;
|
||||
static struct pa_socket_client*pa_socket_client_new(struct pa_mainloop_api *m) {
|
||||
struct pa_socket_client *c;
|
||||
assert(m);
|
||||
|
||||
c = malloc(sizeof(struct socket_client));
|
||||
c = malloc(sizeof(struct pa_socket_client));
|
||||
assert(c);
|
||||
c->mainloop = m;
|
||||
c->fd = -1;
|
||||
|
|
@ -34,8 +34,8 @@ static struct socket_client*socket_client_new(struct pa_mainloop_api *m) {
|
|||
return c;
|
||||
}
|
||||
|
||||
static void do_call(struct socket_client *c) {
|
||||
struct iochannel *io;
|
||||
static void do_call(struct pa_socket_client *c) {
|
||||
struct pa_iochannel *io;
|
||||
int error, lerror;
|
||||
assert(c && c->callback);
|
||||
|
||||
|
|
@ -55,7 +55,7 @@ static void do_call(struct socket_client *c) {
|
|||
goto failed;
|
||||
}
|
||||
|
||||
io = iochannel_new(c->mainloop, c->fd, c->fd);
|
||||
io = pa_iochannel_new(c->mainloop, c->fd, c->fd);
|
||||
assert(io);
|
||||
c->fd = -1;
|
||||
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) {
|
||||
struct socket_client *c = userdata;
|
||||
struct pa_socket_client *c = userdata;
|
||||
assert(m && c && c->fixed_source == id);
|
||||
m->cancel_fixed(m, c->fixed_source);
|
||||
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) {
|
||||
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);
|
||||
m->cancel_io(m, c->io_source);
|
||||
c->io_source = NULL;
|
||||
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;
|
||||
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 != EINPROGRESS) {
|
||||
|
|
@ -107,12 +107,12 @@ static int do_connect(struct socket_client *c, const struct sockaddr *sa, sockle
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct socket_client* socket_client_new_ipv4(struct pa_mainloop_api *m, uint32_t address, uint16_t port) {
|
||||
struct socket_client *c;
|
||||
struct pa_socket_client* pa_socket_client_new_ipv4(struct pa_mainloop_api *m, uint32_t address, uint16_t port) {
|
||||
struct pa_socket_client *c;
|
||||
struct sockaddr_in sa;
|
||||
assert(m && address && port);
|
||||
|
||||
c = socket_client_new(m);
|
||||
c = pa_socket_client_new(m);
|
||||
assert(c);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
make_tcp_socket_low_delay(c->fd);
|
||||
pa_make_tcp_socket_low_delay(c->fd);
|
||||
|
||||
sa.sin_family = AF_INET;
|
||||
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;
|
||||
|
||||
fail:
|
||||
socket_client_free(c);
|
||||
pa_socket_client_free(c);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct socket_client* socket_client_new_unix(struct pa_mainloop_api *m, const char *filename) {
|
||||
struct socket_client *c;
|
||||
struct pa_socket_client* pa_socket_client_new_unix(struct pa_mainloop_api *m, const char *filename) {
|
||||
struct pa_socket_client *c;
|
||||
struct sockaddr_un sa;
|
||||
assert(m && filename);
|
||||
|
||||
c = socket_client_new(m);
|
||||
c = pa_socket_client_new(m);
|
||||
assert(c);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
make_socket_low_delay(c->fd);
|
||||
pa_make_socket_low_delay(c->fd);
|
||||
|
||||
sa.sun_family = AF_LOCAL;
|
||||
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;
|
||||
|
||||
fail:
|
||||
socket_client_free(c);
|
||||
pa_socket_client_free(c);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void socket_client_free(struct socket_client *c) {
|
||||
void pa_socket_client_free(struct pa_socket_client *c) {
|
||||
assert(c && c->mainloop);
|
||||
if (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);
|
||||
}
|
||||
|
||||
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);
|
||||
c->callback = on_connection;
|
||||
c->userdata = userdata;
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@
|
|||
#include "mainloop-api.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 socket_client* socket_client_new_unix(struct pa_mainloop_api *m, const char *filename);
|
||||
struct pa_socket_client* pa_socket_client_new_ipv4(struct pa_mainloop_api *m, uint32_t address, uint16_t port);
|
||||
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
|
||||
|
|
|
|||
|
|
@ -13,20 +13,21 @@
|
|||
#include "socket-server.h"
|
||||
#include "util.h"
|
||||
|
||||
struct socket_server {
|
||||
struct pa_socket_server {
|
||||
int fd;
|
||||
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 *mainloop_source;
|
||||
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) {
|
||||
struct socket_server *s = userdata;
|
||||
struct iochannel *io;
|
||||
struct pa_socket_server *s = userdata;
|
||||
struct pa_iochannel *io;
|
||||
int nfd;
|
||||
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 */
|
||||
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);
|
||||
s->on_connection(s, io, s->userdata);
|
||||
}
|
||||
|
||||
struct socket_server* socket_server_new(struct pa_mainloop_api *m, int fd) {
|
||||
struct socket_server *s;
|
||||
struct pa_socket_server* pa_socket_server_new(struct pa_mainloop_api *m, int fd) {
|
||||
struct pa_socket_server *s;
|
||||
assert(m && fd >= 0);
|
||||
|
||||
s = malloc(sizeof(struct socket_server));
|
||||
s = malloc(sizeof(struct pa_socket_server));
|
||||
assert(s);
|
||||
s->fd = fd;
|
||||
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);
|
||||
assert(s->mainloop_source);
|
||||
|
||||
s->type = SOCKET_SERVER_GENERIC;
|
||||
|
||||
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;
|
||||
struct sockaddr_un sa;
|
||||
struct socket_server *s;
|
||||
struct pa_socket_server *s;
|
||||
|
||||
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);
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
s = socket_server_new(m, fd);
|
||||
s = pa_socket_server_new(m, fd);
|
||||
assert(s);
|
||||
|
||||
s->filename = strdup(filename);
|
||||
assert(s->filename);
|
||||
|
||||
s->type = SOCKET_SERVER_UNIX;
|
||||
|
||||
return s;
|
||||
|
||||
fail:
|
||||
|
|
@ -109,7 +117,8 @@ fail:
|
|||
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;
|
||||
struct sockaddr_in sa;
|
||||
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)
|
||||
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_port = htons(port);
|
||||
|
|
@ -140,7 +149,10 @@ struct socket_server* socket_server_new_ipv4(struct pa_mainloop_api *m, uint32_t
|
|||
goto fail;
|
||||
}
|
||||
|
||||
return socket_server_new(m, fd);
|
||||
if ((ss = pa_socket_server_new(m, fd)))
|
||||
ss->type = SOCKET_SERVER_IPV4;
|
||||
|
||||
return ss;
|
||||
|
||||
fail:
|
||||
if (fd >= 0)
|
||||
|
|
@ -149,7 +161,7 @@ fail:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void socket_server_free(struct socket_server*s) {
|
||||
void pa_socket_server_free(struct pa_socket_server*s) {
|
||||
assert(s);
|
||||
close(s->fd);
|
||||
|
||||
|
|
@ -164,7 +176,7 @@ void socket_server_free(struct socket_server*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);
|
||||
|
||||
s->on_connection = on_connection;
|
||||
|
|
|
|||
|
|
@ -5,14 +5,14 @@
|
|||
#include "mainloop-api.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 socket_server* 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(struct pa_mainloop_api *m, int fd);
|
||||
struct pa_socket_server* pa_socket_server_new_unix(struct pa_mainloop_api *m, const char *filename);
|
||||
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
|
||||
|
|
|
|||
72
src/source.c
72
src/source.c
|
|
@ -8,15 +8,16 @@
|
|||
#include "strbuf.h"
|
||||
#include "namereg.h"
|
||||
|
||||
struct source* source_new(struct core *core, const char *name, int fail, const struct pa_sample_spec *spec) {
|
||||
struct source *s;
|
||||
struct pa_source* pa_source_new(struct pa_core *core, const char *name, int fail, const struct pa_sample_spec *spec) {
|
||||
struct pa_source *s;
|
||||
char st[256];
|
||||
int r;
|
||||
assert(core && spec);
|
||||
|
||||
s = malloc(sizeof(struct source));
|
||||
s = malloc(sizeof(struct pa_source));
|
||||
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);
|
||||
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->core = core;
|
||||
s->sample_spec = *spec;
|
||||
s->outputs = idxset_new(NULL, NULL);
|
||||
s->outputs = pa_idxset_new(NULL, NULL);
|
||||
|
||||
s->notify = NULL;
|
||||
s->userdata = NULL;
|
||||
|
||||
r = idxset_put(core->sources, s, &s->index);
|
||||
assert(s->index != IDXSET_INVALID && r >= 0);
|
||||
r = pa_idxset_put(core->sources, s, &s->index);
|
||||
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;
|
||||
}
|
||||
|
||||
void source_free(struct source *s) {
|
||||
struct source_output *o, *j = NULL;
|
||||
void pa_source_free(struct pa_source *s) {
|
||||
struct pa_source_output *o, *j = NULL;
|
||||
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);
|
||||
source_output_kill(o);
|
||||
pa_source_output_kill(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);
|
||||
|
||||
|
|
@ -58,7 +60,7 @@ void source_free(struct source *s) {
|
|||
free(s);
|
||||
}
|
||||
|
||||
void source_notify(struct source*s) {
|
||||
void pa_source_notify(struct pa_source*s) {
|
||||
assert(s);
|
||||
|
||||
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) {
|
||||
struct memchunk *chunk = userdata;
|
||||
struct source_output *o = p;
|
||||
struct pa_memchunk *chunk = userdata;
|
||||
struct pa_source_output *o = p;
|
||||
assert(o && o->push && del && chunk);
|
||||
|
||||
source_output_push(o, chunk);
|
||||
pa_source_output_push(o, chunk);
|
||||
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);
|
||||
|
||||
idxset_foreach(s->outputs, do_post, chunk);
|
||||
pa_idxset_foreach(s->outputs, do_post, chunk);
|
||||
}
|
||||
|
||||
struct source* source_get_default(struct core *c) {
|
||||
struct source *source;
|
||||
struct pa_source* pa_source_get_default(struct pa_core *c) {
|
||||
struct pa_source *source;
|
||||
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;
|
||||
|
||||
if (!(source = idxset_first(c->sources, &c->default_source_index)))
|
||||
if (!(source = pa_idxset_first(c->sources, &c->default_source_index)))
|
||||
return NULL;
|
||||
|
||||
fprintf(stderr, "core: default source vanished, setting to %u.\n", source->index);
|
||||
return source;
|
||||
}
|
||||
|
||||
char *source_list_to_string(struct core *c) {
|
||||
struct strbuf *s;
|
||||
struct source *source, *default_source;
|
||||
uint32_t index = IDXSET_INVALID;
|
||||
char *pa_source_list_to_string(struct pa_core *c) {
|
||||
struct pa_strbuf *s;
|
||||
struct pa_source *source, *default_source;
|
||||
uint32_t index = PA_IDXSET_INVALID;
|
||||
assert(c);
|
||||
|
||||
s = strbuf_new();
|
||||
s = pa_strbuf_new();
|
||||
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))
|
||||
strbuf_printf(s, " %c index: %u, name: <%s>\n", source == default_source ? '*' : ' ', source->index, source->name);
|
||||
for (source = pa_idxset_first(c->sources, &index); source; source = pa_idxset_next(c->sources, &index))
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
22
src/source.h
22
src/source.h
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef foosourcehfoo
|
||||
#define foosourcehfoo
|
||||
|
||||
struct source;
|
||||
struct pa_source;
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "core.h"
|
||||
|
|
@ -10,28 +10,28 @@ struct source;
|
|||
#include "memblock.h"
|
||||
#include "memchunk.h"
|
||||
|
||||
struct source {
|
||||
struct pa_source {
|
||||
uint32_t index;
|
||||
|
||||
char *name;
|
||||
struct core *core;
|
||||
struct pa_core *core;
|
||||
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;
|
||||
};
|
||||
|
||||
struct source* source_new(struct core *core, const char *name, int fail, const struct pa_sample_spec *spec);
|
||||
void source_free(struct source *s);
|
||||
struct pa_source* pa_source_new(struct pa_core *core, const char *name, int fail, const struct pa_sample_spec *spec);
|
||||
void pa_source_free(struct pa_source *s);
|
||||
|
||||
/* 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
|
||||
|
|
|
|||
|
|
@ -5,17 +5,17 @@
|
|||
#include "sourceoutput.h"
|
||||
#include "strbuf.h"
|
||||
|
||||
struct source_output* source_output_new(struct source *s, const char *name, const struct pa_sample_spec *spec) {
|
||||
struct source_output *o;
|
||||
struct resampler *resampler = NULL;
|
||||
struct pa_source_output* pa_source_output_new(struct pa_source *s, const char *name, const struct pa_sample_spec *spec) {
|
||||
struct pa_source_output *o;
|
||||
struct pa_resampler *resampler = NULL;
|
||||
int r;
|
||||
assert(s && 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;
|
||||
|
||||
o = malloc(sizeof(struct source_output));
|
||||
o = malloc(sizeof(struct pa_source_output));
|
||||
assert(o);
|
||||
o->name = name ? strdup(name) : NULL;
|
||||
o->source = s;
|
||||
|
|
@ -27,59 +27,59 @@ struct source_output* source_output_new(struct source *s, const char *name, cons
|
|||
o->resampler = resampler;
|
||||
|
||||
assert(s->core);
|
||||
r = idxset_put(s->core->source_outputs, o, &o->index);
|
||||
assert(r == 0 && o->index != IDXSET_INVALID);
|
||||
r = idxset_put(s->outputs, o, NULL);
|
||||
r = pa_idxset_put(s->core->source_outputs, o, &o->index);
|
||||
assert(r == 0 && o->index != PA_IDXSET_INVALID);
|
||||
r = pa_idxset_put(s->outputs, o, NULL);
|
||||
assert(r == 0);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
void source_output_free(struct source_output* o) {
|
||||
void pa_source_output_free(struct pa_source_output* o) {
|
||||
assert(o);
|
||||
|
||||
assert(o->source && o->source->core);
|
||||
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->core->source_outputs, o, NULL);
|
||||
pa_idxset_remove_by_data(o->source->outputs, o, NULL);
|
||||
|
||||
if (o->resampler)
|
||||
resampler_free(o->resampler);
|
||||
pa_resampler_free(o->resampler);
|
||||
|
||||
free(o->name);
|
||||
free(o);
|
||||
}
|
||||
|
||||
void source_output_kill(struct source_output*i) {
|
||||
void pa_source_output_kill(struct pa_source_output*i) {
|
||||
assert(i);
|
||||
|
||||
if (i->kill)
|
||||
i->kill(i);
|
||||
}
|
||||
|
||||
char *source_output_list_to_string(struct core *c) {
|
||||
struct strbuf *s;
|
||||
struct source_output *o;
|
||||
uint32_t index = IDXSET_INVALID;
|
||||
char *pa_source_output_list_to_string(struct pa_core *c) {
|
||||
struct pa_strbuf *s;
|
||||
struct pa_source_output *o;
|
||||
uint32_t index = PA_IDXSET_INVALID;
|
||||
assert(c);
|
||||
|
||||
s = strbuf_new();
|
||||
s = pa_strbuf_new();
|
||||
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);
|
||||
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->name,
|
||||
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) {
|
||||
struct memchunk rchunk;
|
||||
void pa_source_output_push(struct pa_source_output *o, const struct pa_memchunk *chunk) {
|
||||
struct pa_memchunk rchunk;
|
||||
assert(o && chunk && chunk->length && o->push);
|
||||
|
||||
if (!o->resampler) {
|
||||
|
|
@ -87,11 +87,11 @@ void source_output_push(struct source_output *o, const struct memchunk *chunk) {
|
|||
return;
|
||||
}
|
||||
|
||||
resampler_run(o->resampler, chunk, &rchunk);
|
||||
pa_resampler_run(o->resampler, chunk, &rchunk);
|
||||
if (!rchunk.length)
|
||||
return;
|
||||
|
||||
assert(rchunk.memblock);
|
||||
o->push(o, &rchunk);
|
||||
memblock_unref(rchunk.memblock);
|
||||
pa_memblock_unref(rchunk.memblock);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,28 +8,28 @@
|
|||
#include "memblockq.h"
|
||||
#include "resampler.h"
|
||||
|
||||
struct source_output {
|
||||
struct pa_source_output {
|
||||
uint32_t index;
|
||||
|
||||
char *name;
|
||||
struct source *source;
|
||||
struct pa_source *source;
|
||||
struct pa_sample_spec sample_spec;
|
||||
|
||||
void (*push)(struct source_output *o, const struct memchunk *chunk);
|
||||
void (*kill)(struct source_output* o);
|
||||
void (*push)(struct pa_source_output *o, const struct pa_memchunk *chunk);
|
||||
void (*kill)(struct pa_source_output* o);
|
||||
|
||||
struct resampler* resampler;
|
||||
struct pa_resampler* resampler;
|
||||
|
||||
void *userdata;
|
||||
};
|
||||
|
||||
struct source_output* source_output_new(struct source *s, const char *name, const struct pa_sample_spec *spec);
|
||||
void source_output_free(struct source_output* o);
|
||||
struct pa_source_output* pa_source_output_new(struct pa_source *s, const char *name, const struct pa_sample_spec *spec);
|
||||
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
|
||||
|
|
|
|||
20
src/strbuf.c
20
src/strbuf.c
|
|
@ -11,20 +11,20 @@ struct chunk {
|
|||
char text[];
|
||||
};
|
||||
|
||||
struct strbuf {
|
||||
struct pa_strbuf {
|
||||
size_t length;
|
||||
struct chunk *head, *tail;
|
||||
};
|
||||
|
||||
struct strbuf *strbuf_new(void) {
|
||||
struct strbuf *sb = malloc(sizeof(struct strbuf));
|
||||
struct pa_strbuf *pa_strbuf_new(void) {
|
||||
struct pa_strbuf *sb = malloc(sizeof(struct pa_strbuf));
|
||||
assert(sb);
|
||||
sb->length = 0;
|
||||
sb->head = sb->tail = NULL;
|
||||
return sb;
|
||||
}
|
||||
|
||||
void strbuf_free(struct strbuf *sb) {
|
||||
void pa_strbuf_free(struct pa_strbuf *sb) {
|
||||
assert(sb);
|
||||
while (sb->head) {
|
||||
struct chunk *c = sb->head;
|
||||
|
|
@ -35,7 +35,7 @@ void strbuf_free(struct strbuf *sb) {
|
|||
free(sb);
|
||||
}
|
||||
|
||||
char *strbuf_tostring(struct strbuf *sb) {
|
||||
char *pa_strbuf_tostring(struct pa_strbuf *sb) {
|
||||
char *t, *e;
|
||||
struct chunk *c;
|
||||
assert(sb);
|
||||
|
|
@ -54,15 +54,15 @@ char *strbuf_tostring(struct strbuf *sb) {
|
|||
return t;
|
||||
}
|
||||
|
||||
char *strbuf_tostring_free(struct strbuf *sb) {
|
||||
char *pa_strbuf_tostring_free(struct pa_strbuf *sb) {
|
||||
char *t;
|
||||
assert(sb);
|
||||
t = strbuf_tostring(sb);
|
||||
strbuf_free(sb);
|
||||
t = pa_strbuf_tostring(sb);
|
||||
pa_strbuf_free(sb);
|
||||
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;
|
||||
size_t l;
|
||||
assert(sb && t);
|
||||
|
|
@ -87,7 +87,7 @@ void strbuf_puts(struct strbuf *sb, const char *t) {
|
|||
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;
|
||||
struct chunk *c = NULL;
|
||||
|
||||
|
|
|
|||
14
src/strbuf.h
14
src/strbuf.h
|
|
@ -1,14 +1,14 @@
|
|||
#ifndef foostrbufhfoo
|
||||
#define foostrbufhfoo
|
||||
|
||||
struct strbuf;
|
||||
struct pa_strbuf;
|
||||
|
||||
struct strbuf *strbuf_new(void);
|
||||
void strbuf_free(struct strbuf *sb);
|
||||
char *strbuf_tostring(struct strbuf *sb);
|
||||
char *strbuf_tostring_free(struct strbuf *sb);
|
||||
struct pa_strbuf *pa_strbuf_new(void);
|
||||
void pa_strbuf_free(struct pa_strbuf *sb);
|
||||
char *pa_strbuf_tostring(struct pa_strbuf *sb);
|
||||
char *pa_strbuf_tostring_free(struct pa_strbuf *sb);
|
||||
|
||||
int strbuf_printf(struct strbuf *sb, const char *format, ...);
|
||||
void strbuf_puts(struct strbuf *sb, const char *t);
|
||||
int pa_strbuf_printf(struct pa_strbuf *sb, const char *format, ...);
|
||||
void pa_strbuf_puts(struct pa_strbuf *sb, const char *t);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ enum tags {
|
|||
TAG_SAMPLE_SPEC = 'a'
|
||||
};
|
||||
|
||||
struct tagstruct {
|
||||
struct pa_tagstruct {
|
||||
uint8_t *data;
|
||||
size_t length, allocated;
|
||||
size_t rindex;
|
||||
|
|
@ -24,12 +24,12 @@ struct tagstruct {
|
|||
int dynamic;
|
||||
};
|
||||
|
||||
struct tagstruct *tagstruct_new(const uint8_t* data, size_t length) {
|
||||
struct tagstruct*t;
|
||||
struct pa_tagstruct *pa_tagstruct_new(const uint8_t* data, size_t length) {
|
||||
struct pa_tagstruct*t;
|
||||
|
||||
assert(!data || (data && length));
|
||||
|
||||
t = malloc(sizeof(struct tagstruct));
|
||||
t = malloc(sizeof(struct pa_tagstruct));
|
||||
assert(t);
|
||||
t->data = (uint8_t*) data;
|
||||
t->allocated = t->length = data ? length : 0;
|
||||
|
|
@ -38,14 +38,14 @@ struct tagstruct *tagstruct_new(const uint8_t* data, size_t length) {
|
|||
return t;
|
||||
}
|
||||
|
||||
void tagstruct_free(struct tagstruct*t) {
|
||||
void pa_tagstruct_free(struct pa_tagstruct*t) {
|
||||
assert(t);
|
||||
if (t->dynamic)
|
||||
free(t->data);
|
||||
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;
|
||||
assert(t && t->dynamic && l);
|
||||
p = t->data;
|
||||
|
|
@ -54,7 +54,7 @@ uint8_t* tagstruct_free_data(struct tagstruct*t, size_t *l) {
|
|||
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);
|
||||
|
||||
if (l <= t->allocated)
|
||||
|
|
@ -64,7 +64,7 @@ static void extend(struct tagstruct*t, size_t l) {
|
|||
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;
|
||||
assert(t && s);
|
||||
l = strlen(s)+2;
|
||||
|
|
@ -74,7 +74,7 @@ void tagstruct_puts(struct tagstruct*t, const char *s) {
|
|||
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);
|
||||
extend(t, 5);
|
||||
t->data[t->length] = TAG_U32;
|
||||
|
|
@ -82,7 +82,7 @@ void tagstruct_putu32(struct tagstruct*t, uint32_t i) {
|
|||
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);
|
||||
extend(t, 2);
|
||||
t->data[t->length] = TAG_U8;
|
||||
|
|
@ -90,7 +90,7 @@ void tagstruct_putu8(struct tagstruct*t, uint8_t c) {
|
|||
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);
|
||||
extend(t, 7);
|
||||
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;
|
||||
}
|
||||
|
||||
int tagstruct_gets(struct tagstruct*t, const char **s) {
|
||||
int pa_tagstruct_gets(struct pa_tagstruct*t, const char **s) {
|
||||
int error = 0;
|
||||
size_t n;
|
||||
char *c;
|
||||
|
|
@ -128,7 +128,7 @@ int tagstruct_gets(struct tagstruct*t, const char **s) {
|
|||
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);
|
||||
|
||||
if (t->rindex+5 > t->length)
|
||||
|
|
@ -142,7 +142,7 @@ int tagstruct_getu32(struct tagstruct*t, uint32_t *i) {
|
|||
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);
|
||||
|
||||
if (t->rindex+2 > t->length)
|
||||
|
|
@ -156,7 +156,7 @@ int tagstruct_getu8(struct tagstruct*t, uint8_t *c) {
|
|||
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);
|
||||
|
||||
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);
|
||||
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);
|
||||
*l = t->length;
|
||||
return t->data;
|
||||
|
|
|
|||
|
|
@ -6,24 +6,24 @@
|
|||
|
||||
#include "sample.h"
|
||||
|
||||
struct tagstruct;
|
||||
struct pa_tagstruct;
|
||||
|
||||
struct tagstruct *tagstruct_new(const uint8_t* data, size_t length);
|
||||
void tagstruct_free(struct tagstruct*t);
|
||||
uint8_t* tagstruct_free_data(struct tagstruct*t, size_t *l);
|
||||
struct pa_tagstruct *pa_tagstruct_new(const uint8_t* data, size_t length);
|
||||
void pa_tagstruct_free(struct pa_tagstruct*t);
|
||||
uint8_t* pa_tagstruct_free_data(struct pa_tagstruct*t, size_t *l);
|
||||
|
||||
void tagstruct_puts(struct tagstruct*t, const char *s);
|
||||
void tagstruct_putu32(struct tagstruct*t, uint32_t i);
|
||||
void tagstruct_putu8(struct tagstruct*t, uint8_t c);
|
||||
void tagstruct_put_sample_spec(struct tagstruct *t, const struct pa_sample_spec *ss);
|
||||
void pa_tagstruct_puts(struct pa_tagstruct*t, const char *s);
|
||||
void pa_tagstruct_putu32(struct pa_tagstruct*t, uint32_t i);
|
||||
void pa_tagstruct_putu8(struct pa_tagstruct*t, uint8_t c);
|
||||
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 tagstruct_getu32(struct tagstruct*t, uint32_t *i);
|
||||
int tagstruct_getu8(struct tagstruct*t, uint8_t *c);
|
||||
int tagstruct_get_sample_spec(struct tagstruct *t, struct pa_sample_spec *ss);
|
||||
int pa_tagstruct_gets(struct pa_tagstruct*t, const char **s);
|
||||
int pa_tagstruct_getu32(struct pa_tagstruct*t, uint32_t *i);
|
||||
int pa_tagstruct_getu8(struct pa_tagstruct*t, uint8_t *c);
|
||||
int pa_tagstruct_get_sample_spec(struct pa_tagstruct *t, struct pa_sample_spec *ss);
|
||||
|
||||
int tagstruct_eof(struct tagstruct*t);
|
||||
const uint8_t* tagstruct_data(struct tagstruct*t, size_t *l);
|
||||
int pa_tagstruct_eof(struct pa_tagstruct*t);
|
||||
const uint8_t* pa_tagstruct_data(struct pa_tagstruct*t, size_t *l);
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
3
src/todo
3
src/todo
|
|
@ -1,5 +1,4 @@
|
|||
- recording (general, simple, esound, native)
|
||||
- make it embedable (add pa_ prefix too all identifiers)
|
||||
- native library/protocol:
|
||||
sync() function
|
||||
more functions
|
||||
|
|
@ -7,8 +6,10 @@
|
|||
- kill() routines in all modules
|
||||
- command line protocol:
|
||||
kill client/input/output
|
||||
default_sink/source
|
||||
- config parser/cmdline
|
||||
- move more stuff from module-oss[-dma] to liboss-util
|
||||
- stdin_inuse/stdout_inuse
|
||||
- svn-id and license in every file
|
||||
|
||||
-- post 0.1
|
||||
|
|
|
|||
|
|
@ -5,15 +5,15 @@
|
|||
#include "tokenizer.h"
|
||||
#include "dynarray.h"
|
||||
|
||||
struct tokenizer {
|
||||
struct dynarray *dynarray;
|
||||
struct pa_tokenizer {
|
||||
struct pa_dynarray *dynarray;
|
||||
};
|
||||
|
||||
static void token_free(void *p, void *userdata) {
|
||||
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;
|
||||
const char delimiter[] = " \t\n\r";
|
||||
const char *p;
|
||||
|
|
@ -27,7 +27,7 @@ static void parse(struct dynarray*a, const char *s, unsigned args) {
|
|||
size_t l = strcspn(p, delimiter);
|
||||
char *n = strndup(p, l);
|
||||
assert(n);
|
||||
dynarray_append(a, n);
|
||||
pa_dynarray_append(a, n);
|
||||
p += l;
|
||||
p += strspn(p, delimiter);
|
||||
args--;
|
||||
|
|
@ -36,29 +36,29 @@ static void parse(struct dynarray*a, const char *s, unsigned args) {
|
|||
if (args && *p) {
|
||||
char *n = strdup(p);
|
||||
assert(n);
|
||||
dynarray_append(a, n);
|
||||
pa_dynarray_append(a, n);
|
||||
}
|
||||
}
|
||||
|
||||
struct tokenizer* tokenizer_new(const char *s, unsigned args) {
|
||||
struct tokenizer *t;
|
||||
struct pa_tokenizer* pa_tokenizer_new(const char *s, unsigned args) {
|
||||
struct pa_tokenizer *t;
|
||||
|
||||
t = malloc(sizeof(struct tokenizer));
|
||||
t = malloc(sizeof(struct pa_tokenizer));
|
||||
assert(t);
|
||||
t->dynarray = dynarray_new();
|
||||
t->dynarray = pa_dynarray_new();
|
||||
assert(t->dynarray);
|
||||
|
||||
parse(t->dynarray, s, args);
|
||||
return t;
|
||||
}
|
||||
|
||||
void tokenizer_free(struct tokenizer *t) {
|
||||
void pa_tokenizer_free(struct pa_tokenizer *t) {
|
||||
assert(t);
|
||||
dynarray_free(t->dynarray, token_free, NULL);
|
||||
pa_dynarray_free(t->dynarray, token_free, NULL);
|
||||
free(t);
|
||||
}
|
||||
|
||||
const char *tokenizer_get(struct tokenizer *t, unsigned i) {
|
||||
const char *pa_tokenizer_get(struct pa_tokenizer *t, unsigned i) {
|
||||
assert(t);
|
||||
return dynarray_get(t->dynarray, i);
|
||||
return pa_dynarray_get(t->dynarray, i);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
#ifndef footokenizerhfoo
|
||||
#define footokenizerhfoo
|
||||
|
||||
struct tokenizer;
|
||||
struct pa_tokenizer;
|
||||
|
||||
struct tokenizer* tokenizer_new(const char *s, unsigned args);
|
||||
void tokenizer_free(struct tokenizer *t);
|
||||
struct pa_tokenizer* pa_tokenizer_new(const char *s, unsigned args);
|
||||
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
|
||||
|
|
|
|||
12
src/util.c
12
src/util.c
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "util.h"
|
||||
|
||||
void make_nonblock_fd(int fd) {
|
||||
void pa_make_nonblock_fd(int fd) {
|
||||
int v;
|
||||
|
||||
if ((v = fcntl(fd, F_GETFL)) >= 0)
|
||||
|
|
@ -20,7 +20,7 @@ void make_nonblock_fd(int fd) {
|
|||
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;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
int make_secure_dir(const char* dir) {
|
||||
int pa_make_secure_dir(const char* dir) {
|
||||
struct stat st;
|
||||
|
||||
if (mkdir(dir, 0700) < 0)
|
||||
|
|
@ -86,7 +86,7 @@ fail:
|
|||
return -1;
|
||||
}
|
||||
|
||||
int make_socket_low_delay(int fd) {
|
||||
int pa_make_socket_low_delay(int fd) {
|
||||
int ret = 0, buf_size, priority;
|
||||
|
||||
assert(fd >= 0);
|
||||
|
|
@ -106,12 +106,12 @@ int make_socket_low_delay(int fd) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
int make_tcp_socket_low_delay(int fd) {
|
||||
int pa_make_tcp_socket_low_delay(int fd) {
|
||||
int ret, tos, on;
|
||||
|
||||
assert(fd >= 0);
|
||||
|
||||
ret = make_socket_low_delay(fd);
|
||||
ret = pa_make_socket_low_delay(fd);
|
||||
|
||||
on = 1;
|
||||
if (setsockopt(fd, SOL_TCP, TCP_NODELAY, &on, sizeof(on)) < 0)
|
||||
|
|
|
|||
12
src/util.h
12
src/util.h
|
|
@ -1,13 +1,15 @@
|
|||
#ifndef 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 make_tcp_socket_low_delay(int fd);
|
||||
int pa_make_secure_dir(const char* dir);
|
||||
|
||||
int pa_make_socket_low_delay(int fd);
|
||||
int pa_make_tcp_socket_low_delay(int fd);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue