summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cli.c2
-rw-r--r--src/iochannel.c24
-rw-r--r--src/iochannel.h5
-rw-r--r--src/main.c3
-rw-r--r--src/mainloop-api.h3
-rw-r--r--src/mainloop.c3
-rw-r--r--src/memblock.h2
-rw-r--r--src/module-oss-mmap.c4
-rw-r--r--src/pacat.c3
-rw-r--r--src/polyp.c3
-rw-r--r--src/protocol-esound.c323
-rw-r--r--src/protocol-simple.c162
-rw-r--r--src/sample-util.c3
-rw-r--r--src/simple.c27
-rw-r--r--src/sink.c1
-rw-r--r--src/sinkinput.c3
-rw-r--r--src/socket-client.c4
-rw-r--r--src/socket-server.c8
-rw-r--r--src/sourceoutput.c3
-rw-r--r--src/todo14
-rw-r--r--src/util.c49
-rw-r--r--src/util.h7
22 files changed, 480 insertions, 176 deletions
diff --git a/src/cli.c b/src/cli.c
index ecde5763..429aebf3 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -97,7 +97,7 @@ struct pa_cli* pa_cli_new(struct pa_core *core, struct pa_iochannel *io) {
c->userdata = NULL;
c->eof_callback = NULL;
- pa_iochannel_peer_to_string(io, cname, sizeof(cname));
+ pa_iochannel_socket_peer_to_string(io, cname, sizeof(cname));
c->client = pa_client_new(core, "CLI", cname);
assert(c->client);
c->client->kill = client_kill;
diff --git a/src/iochannel.c b/src/iochannel.c
index afa94cff..775c6139 100644
--- a/src/iochannel.c
+++ b/src/iochannel.c
@@ -15,6 +15,7 @@ struct pa_iochannel {
int readable;
int writable;
+ int hungup;
int no_close;
@@ -47,6 +48,11 @@ static void callback(struct pa_mainloop_api* m, void *id, int fd, enum pa_mainlo
int changed = 0;
assert(m && fd >= 0 && events && userdata);
+ if ((events & PA_MAINLOOP_API_IO_EVENT_HUP) && !io->hungup) {
+ io->hungup = 1;
+ changed = 1;
+ }
+
if ((events & PA_MAINLOOP_API_IO_EVENT_INPUT) && !io->readable) {
io->readable = 1;
changed = 1;
@@ -80,6 +86,7 @@ struct pa_iochannel* pa_iochannel_new(struct pa_mainloop_api*m, int ifd, int ofd
io->callback = NULL;
io->readable = 0;
io->writable = 0;
+ io->hungup = 0;
io->no_close = 0;
if (ifd == ofd) {
@@ -132,6 +139,11 @@ int pa_iochannel_is_writable(struct pa_iochannel*io) {
return io->writable;
}
+int pa_iochannel_is_hungup(struct pa_iochannel*io) {
+ assert(io);
+ return io->hungup;
+}
+
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);
@@ -168,7 +180,17 @@ void pa_iochannel_set_noclose(struct pa_iochannel*io, int b) {
io->no_close = b;
}
-void pa_iochannel_peer_to_string(struct pa_iochannel*io, char*s, size_t l) {
+void pa_iochannel_socket_peer_to_string(struct pa_iochannel*io, char*s, size_t l) {
assert(io && s && l);
pa_peer_to_string(s, l, io->ifd);
}
+
+int pa_iochannel_socket_set_rcvbuf(struct pa_iochannel *io, size_t l) {
+ assert(io);
+ return pa_socket_set_rcvbuf(io->ifd, l);
+}
+
+int pa_iochannel_socket_set_sndbuf(struct pa_iochannel *io, size_t l) {
+ assert(io);
+ return pa_socket_set_sndbuf(io->ofd, l);
+}
diff --git a/src/iochannel.h b/src/iochannel.h
index 1a5057d6..7e31b6ca 100644
--- a/src/iochannel.h
+++ b/src/iochannel.h
@@ -16,11 +16,14 @@ ssize_t pa_iochannel_read(struct pa_iochannel*io, void*data, size_t l);
int pa_iochannel_is_readable(struct pa_iochannel*io);
int pa_iochannel_is_writable(struct pa_iochannel*io);
+int pa_iochannel_is_hungup(struct pa_iochannel*io);
void pa_iochannel_set_noclose(struct pa_iochannel*io, int b);
void pa_iochannel_set_callback(struct pa_iochannel*io, void (*callback)(struct pa_iochannel*io, void *userdata), void *userdata);
-void pa_iochannel_peer_to_string(struct pa_iochannel*io, char*s, size_t l);
+void pa_iochannel_socket_peer_to_string(struct pa_iochannel*io, char*s, size_t l);
+int pa_iochannel_socket_set_rcvbuf(struct pa_iochannel*io, size_t l);
+int pa_iochannel_socket_set_sndbuf(struct pa_iochannel*io, size_t l);
#endif
diff --git a/src/main.c b/src/main.c
index c7a83fec..e2d86b48 100644
--- a/src/main.c
+++ b/src/main.c
@@ -42,7 +42,8 @@ int main(int argc, char *argv[]) {
c = pa_core_new(pa_mainloop_get_api(mainloop));
assert(c);
- pa_module_load(c, "module-oss", "/dev/dsp");
+ pa_module_load(c, "module-oss-mmap", "/dev/dsp");
+/* pa_module_load(c, "module-oss-mmap", "/dev/dsp1");*/
/* 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);
diff --git a/src/mainloop-api.h b/src/mainloop-api.h
index 96dacc22..961a1a46 100644
--- a/src/mainloop-api.h
+++ b/src/mainloop-api.h
@@ -8,7 +8,8 @@ enum pa_mainloop_api_io_events {
PA_MAINLOOP_API_IO_EVENT_NULL = 0,
PA_MAINLOOP_API_IO_EVENT_INPUT = 1,
PA_MAINLOOP_API_IO_EVENT_OUTPUT = 2,
- PA_MAINLOOP_API_IO_EVENT_BOTH = 3
+ PA_MAINLOOP_API_IO_EVENT_BOTH = 3,
+ PA_MAINLOOP_API_IO_EVENT_HUP = 4
};
struct pa_mainloop_api {
diff --git a/src/mainloop.c b/src/mainloop.c
index 4755cc8f..a485a963 100644
--- a/src/mainloop.c
+++ b/src/mainloop.c
@@ -167,7 +167,8 @@ static void dispatch_pollfds(struct pa_mainloop *m) {
assert(s->pollfd->fd == s->fd && s->callback);
s->callback(&m->api, s, s->fd,
- ((s->pollfd->revents & (POLLIN|POLLHUP|POLLERR)) ? PA_MAINLOOP_API_IO_EVENT_INPUT : 0) |
+ ((s->pollfd->revents & POLLHUP) ? PA_MAINLOOP_API_IO_EVENT_HUP : 0) |
+ ((s->pollfd->revents & POLLIN) ? PA_MAINLOOP_API_IO_EVENT_INPUT : 0) |
((s->pollfd->revents & POLLOUT) ? PA_MAINLOOP_API_IO_EVENT_OUTPUT : 0), s->userdata);
s->pollfd->revents = 0;
}
diff --git a/src/memblock.h b/src/memblock.h
index acdae047..2635f023 100644
--- a/src/memblock.h
+++ b/src/memblock.h
@@ -22,8 +22,6 @@ struct pa_memblock* pa_memblock_ref(struct pa_memblock*b);
void pa_memblock_unref_fixed(struct pa_memblock*b);
-#define pa_memblock_assert_exclusive(b) assert((b)->ref == 1)
-
extern unsigned pa_memblock_count, pa_memblock_total;
#endif
diff --git a/src/module-oss-mmap.c b/src/module-oss-mmap.c
index 62c2cc2a..a9cf84f3 100644
--- a/src/module-oss-mmap.c
+++ b/src/module-oss-mmap.c
@@ -68,10 +68,10 @@ static void out_fill_memblocks(struct userdata *u, unsigned n) {
if (!u->out_memblocks[u->out_current]) {
- 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.memblock = u->out_memblocks[u->out_current] = 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;
-
+
pa_sink_render_into_full(u->sink, &chunk);
}
diff --git a/src/pacat.c b/src/pacat.c
index 59ccc462..4fdf3f69 100644
--- a/src/pacat.c
+++ b/src/pacat.c
@@ -132,7 +132,7 @@ static void stream_drain_complete(struct pa_stream*s, void *userdata) {
static void stdin_callback(struct pa_mainloop_api*a, void *id, int fd, enum pa_mainloop_api_io_events events, void *userdata) {
size_t l, w = 0;
ssize_t r;
- assert(a == mainloop_api && id && fd == STDIN_FILENO && events == PA_MAINLOOP_API_IO_EVENT_INPUT && stdin_source == id);
+ assert(a == mainloop_api && id && fd == STDIN_FILENO && stdin_source == id);
if (buffer) {
mainloop_api->enable_io(mainloop_api, stdin_source, PA_MAINLOOP_API_IO_EVENT_NULL);
@@ -169,6 +169,7 @@ static void stdin_callback(struct pa_mainloop_api*a, void *id, int fd, enum pa_m
static void exit_signal_callback(void *id, int sig, void *userdata) {
fprintf(stderr, "Got SIGINT, exiting.\n");
quit(0);
+
}
int main(int argc, char *argv[]) {
diff --git a/src/polyp.c b/src/polyp.c
index 0f2a9181..6bc7ab33 100644
--- a/src/polyp.c
+++ b/src/polyp.c
@@ -541,7 +541,8 @@ struct pa_stream* pa_stream_new(
void pa_stream_free(struct pa_stream *s) {
assert(s && s->context);
- pa_pdispatch_unregister_reply(s->context->pdispatch, s);
+ if (s->context->pdispatch)
+ pa_pdispatch_unregister_reply(s->context->pdispatch, s);
free(s->name);
diff --git a/src/protocol-esound.c b/src/protocol-esound.c
index 04006d5d..3dd9655b 100644
--- a/src/protocol-esound.c
+++ b/src/protocol-esound.c
@@ -11,13 +11,18 @@
#include "client.h"
#include "sinkinput.h"
#include "sink.h"
+#include "sourceoutput.h"
+#include "source.h"
#include "sample.h"
#include "authkey.h"
#define COOKIE_FILE ".esd_auth"
-#define BUFFER_SECONDS (0.5)
+#define PLAYBACK_BUFFER_SECONDS (.5)
+#define PLAYBACK_BUFFER_FRAGMENTS (10)
+#define RECORD_BUFFER_SECONDS (5)
+#define RECORD_BUFFER_FRAGMENTS (100)
/* This is heavily based on esound's code */
@@ -27,14 +32,20 @@ struct connection {
struct pa_iochannel *io;
struct pa_client *client;
int authorized, swap_byte_order;
- void *read_data;
- size_t read_data_alloc, read_data_length;
void *write_data;
size_t write_data_alloc, write_data_index, write_data_length;
+ void *read_data;
+ size_t read_data_alloc, read_data_length;
esd_proto_t request;
esd_client_state_t state;
struct pa_sink_input *sink_input;
- struct pa_memblockq *input_memblockq;
+ struct pa_source_output *source_output;
+ struct pa_memblockq *input_memblockq, *output_memblockq;
+ void *fixed_source;
+ struct {
+ struct pa_memblock *current_memblock;
+ size_t memblock_index, fragment_size;
+ } playback;
};
struct pa_protocol_esound {
@@ -42,14 +53,14 @@ struct pa_protocol_esound {
struct pa_core *core;
struct pa_socket_server *server;
struct pa_idxset *connections;
- uint32_t sink_index;
+ uint32_t sink_index, source_index;
unsigned n_player;
uint8_t esd_key[ESD_KEY_LEN];
};
typedef struct proto_handler {
size_t data_length;
- int (*proc)(struct connection *c, const void *data, size_t length);
+ int (*proc)(struct connection *c, esd_proto_t request, const void *data, size_t length);
const char *description;
} esd_proto_handler_info_t;
@@ -58,15 +69,16 @@ 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);
-static int esd_proto_stream_record(struct connection *c, const void *data, size_t length);
-static int esd_proto_get_latency(struct connection *c, const void *data, size_t length);
-static int esd_proto_server_info(struct connection *c, const void *data, size_t length);
-static int esd_proto_all_info(struct connection *c, const void *data, size_t length);
-static int esd_proto_stream_pan(struct connection *c, const void *data, size_t length);
+static void source_output_push_cb(struct pa_source_output *o, const struct pa_memchunk *chunk);
+static void source_output_kill_cb(struct pa_source_output *o);
-static int do_write(struct connection *c);
+static int esd_proto_connect(struct connection *c, esd_proto_t request, const void *data, size_t length);
+static int esd_proto_stream_play(struct connection *c, esd_proto_t request, const void *data, size_t length);
+static int esd_proto_stream_record(struct connection *c, esd_proto_t request, const void *data, size_t length);
+static int esd_proto_get_latency(struct connection *c, esd_proto_t request, const void *data, size_t length);
+static int esd_proto_server_info(struct connection *c, esd_proto_t request, const void *data, size_t length);
+static int esd_proto_all_info(struct connection *c, esd_proto_t request, const void *data, size_t length);
+static int esd_proto_stream_pan(struct connection *c, esd_proto_t request, const void *data, size_t length);
/* the big map of protocol handler info */
static struct proto_handler proto_map[ESD_PROTO_MAX] = {
@@ -76,7 +88,7 @@ static struct proto_handler proto_map[ESD_PROTO_MAX] = {
{ ESD_NAME_MAX + 2 * sizeof(int), esd_proto_stream_play, "stream play" },
{ ESD_NAME_MAX + 2 * sizeof(int), esd_proto_stream_record, "stream rec" },
- { ESD_NAME_MAX + 2 * sizeof(int), NULL, "stream mon" },
+ { ESD_NAME_MAX + 2 * sizeof(int), esd_proto_stream_record, "stream mon" },
{ ESD_NAME_MAX + 3 * sizeof(int), NULL, "sample cache" },
{ sizeof(int), NULL, "sample free" },
@@ -112,16 +124,27 @@ static void connection_free(struct connection *c) {
c->protocol->n_player--;
pa_client_free(c->client);
-
+
if (c->sink_input)
pa_sink_input_free(c->sink_input);
+ if (c->source_output)
+ pa_source_output_free(c->source_output);
if (c->input_memblockq)
pa_memblockq_free(c->input_memblockq);
+ if (c->output_memblockq)
+ pa_memblockq_free(c->output_memblockq);
+
+ if (c->playback.current_memblock)
+ pa_memblock_unref(c->playback.current_memblock);
free(c->read_data);
free(c->write_data);
pa_iochannel_free(c->io);
+
+ if (c->fixed_source)
+ c->protocol->core->mainloop->cancel_fixed(c->protocol->core->mainloop, c->fixed_source);
+
free(c);
}
@@ -132,11 +155,18 @@ static struct pa_sink* get_output_sink(struct pa_protocol_esound *p) {
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 = PA_IDXSET_INVALID;
+ p->sink_index = s ? s->index : PA_IDXSET_INVALID;
+ return s;
+}
+
+static struct pa_source* get_input_source(struct pa_protocol_esound *p) {
+ struct pa_source *s;
+ assert(p);
+
+ if (!(s = pa_idxset_get_by_index(p->core->sources, p->sink_index)))
+ s = pa_source_get_default(p->core);
+ p->source_index = s ? s->index : PA_IDXSET_INVALID;
return s;
}
@@ -144,6 +174,9 @@ static void* connection_write(struct connection *c, size_t length) {
size_t t, i;
assert(c);
+ assert(c->protocol && c->protocol->core && c->protocol->core->mainloop && c->protocol->core->mainloop->enable_fixed);
+ c->protocol->core->mainloop->enable_fixed(c->protocol->core->mainloop, c->fixed_source, 1);
+
t = c->write_data_length+length;
if (c->write_data_alloc < t)
@@ -159,14 +192,14 @@ static void* connection_write(struct connection *c, size_t length) {
/*** esound commands ***/
-static int esd_proto_connect(struct connection *c, const void *data, size_t length) {
+static int esd_proto_connect(struct connection *c, esd_proto_t request, const void *data, size_t length) {
uint32_t ekey;
int *ok;
assert(length == (ESD_KEY_LEN + sizeof(uint32_t)));
if (!c->authorized) {
if (memcmp(data, c->protocol->esd_key, ESD_KEY_LEN) != 0) {
- fprintf(stderr, "protocol-esound.c: Kicked client with invalid authorization key.\n");
+ fprintf(stderr, __FILE__": kicked client with invalid authorization key.\n");
return -1;
}
@@ -179,7 +212,7 @@ static int esd_proto_connect(struct connection *c, const void *data, size_t leng
else if (ekey == ESD_SWAP_ENDIAN_KEY)
c->swap_byte_order = 1;
else {
- fprintf(stderr, "protocol-esound.c: client sent invalid endian key\n");
+ fprintf(stderr, __FILE__": client sent invalid endian key\n");
return -1;
}
@@ -189,13 +222,13 @@ static int esd_proto_connect(struct connection *c, const void *data, size_t leng
return 0;
}
-static int esd_proto_stream_play(struct connection *c, const void *data, size_t length) {
+static int esd_proto_stream_play(struct connection *c, esd_proto_t request, const void *data, size_t length) {
char name[ESD_NAME_MAX];
int format, rate;
struct pa_sink *sink;
struct pa_sample_spec ss;
size_t l;
- assert(length == (sizeof(int)*2+ESD_NAME_MAX));
+ assert(c && length == (sizeof(int)*2+ESD_NAME_MAX));
format = maybe_swap_endian_32(c->swap_byte_order, *(int*)data);
rate = maybe_swap_endian_32(c->swap_byte_order, *((int*)data + 1));
@@ -217,10 +250,12 @@ static int esd_proto_stream_play(struct connection *c, const void *data, size_t
assert(!c->input_memblockq);
- l = (size_t) (pa_bytes_per_second(&ss)*BUFFER_SECONDS);
- c->input_memblockq = pa_memblockq_new(l, 0, pa_sample_size(&ss), l/2, l/10);
+ l = (size_t) (pa_bytes_per_second(&ss)*PLAYBACK_BUFFER_SECONDS);
+ c->input_memblockq = pa_memblockq_new(l, 0, pa_sample_size(&ss), l/2, l/PLAYBACK_BUFFER_FRAGMENTS);
assert(c->input_memblockq);
-
+ pa_iochannel_socket_set_rcvbuf(c->io, l/PLAYBACK_BUFFER_FRAGMENTS*5);
+ c->playback.fragment_size = l/10;
+
assert(!c->sink_input);
c->sink_input = pa_sink_input_new(sink, name, &ss);
assert(c->sink_input);
@@ -238,13 +273,67 @@ static int esd_proto_stream_play(struct connection *c, const void *data, size_t
return 0;
}
-static int esd_proto_stream_record(struct connection *c, const void *data, size_t length) {
- assert(c && data && length == (sizeof(int)*2+ESD_NAME_MAX));
+static int esd_proto_stream_record(struct connection *c, esd_proto_t request, const void *data, size_t length) {
+ char name[ESD_NAME_MAX];
+ int format, rate;
+ struct pa_source *source;
+ struct pa_sample_spec ss;
+ size_t l;
+ assert(c && length == (sizeof(int)*2+ESD_NAME_MAX));
+
+ format = maybe_swap_endian_32(c->swap_byte_order, *(int*)data);
+ rate = maybe_swap_endian_32(c->swap_byte_order, *((int*)data + 1));
+
+ ss.rate = rate;
+ ss.channels = ((format & ESD_MASK_CHAN) == ESD_STEREO) ? 2 : 1;
+ ss.format = ((format & ESD_MASK_BITS) == ESD_BITS16) ? PA_SAMPLE_S16NE : PA_SAMPLE_U8;
+
+ if (!pa_sample_spec_valid(&ss))
+ return -1;
+
+ if (request == ESD_PROTO_STREAM_MON) {
+ struct pa_sink* sink;
+
+ if (!(sink = get_output_sink(c->protocol)))
+ return -1;
+
+ if (!(source = sink->monitor_source))
+ return -1;
+ } else {
+ assert(request == ESD_PROTO_STREAM_REC);
+
+ if (!(source = get_input_source(c->protocol)))
+ return -1;
+ }
+
+ strncpy(name, data + sizeof(int)*2, sizeof(name));
+ name[sizeof(name)-1] = 0;
+
+ pa_client_rename(c->client, name);
+
+ assert(!c->output_memblockq);
+
+ l = (size_t) (pa_bytes_per_second(&ss)*RECORD_BUFFER_SECONDS);
+ c->output_memblockq = pa_memblockq_new(l, 0, pa_sample_size(&ss), 0, 0);
+ assert(c->output_memblockq);
+ pa_iochannel_socket_set_sndbuf(c->io, l/RECORD_BUFFER_FRAGMENTS*2);
+
+ assert(!c->source_output);
+ c->source_output = pa_source_output_new(source, name, &ss);
+ 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;
+
+ c->state = ESD_STREAMING_DATA;
- assert(0);
+ c->protocol->n_player++;
+
+ return 0;
}
-static int esd_proto_get_latency(struct connection *c, const void *data, size_t length) {
+static int esd_proto_get_latency(struct connection *c, esd_proto_t request, const void *data, size_t length) {
struct pa_sink *sink;
int latency, *lag;
assert(c && !data && length == 0);
@@ -253,7 +342,7 @@ static int esd_proto_get_latency(struct connection *c, const void *data, size_t
latency = 0;
else {
float usec = pa_sink_get_latency(sink);
- usec += BUFFER_SECONDS*1000000*.9; /* A better estimation would be a good idea! */
+ usec += PLAYBACK_BUFFER_SECONDS*1000000*.9; /* A better estimation would be a good idea! */
latency = (int) ((usec*44100)/1000000);
}
@@ -263,7 +352,7 @@ static int esd_proto_get_latency(struct connection *c, const void *data, size_t
return 0;
}
-static int esd_proto_server_info(struct connection *c, const void *data, size_t length) {
+static int esd_proto_server_info(struct connection *c, esd_proto_t request, const void *data, size_t length) {
int rate = 44100, format = ESD_STEREO|ESD_BITS16;
int *response;
struct pa_sink *sink;
@@ -283,14 +372,14 @@ static int esd_proto_server_info(struct connection *c, const void *data, size_t
return 0;
}
-static int esd_proto_all_info(struct connection *c, const void *data, size_t length) {
+static int esd_proto_all_info(struct connection *c, esd_proto_t request, const void *data, size_t length) {
void *response;
size_t t, k, s;
struct connection *conn;
size_t index = PA_IDXSET_INVALID;
assert(c && data && length == sizeof(int));
- if (esd_proto_server_info(c, data, length) < 0)
+ if (esd_proto_server_info(c, request, data, length) < 0)
return -1;
k = sizeof(int)*5+ESD_NAME_MAX;
@@ -346,7 +435,7 @@ static int esd_proto_all_info(struct connection *c, const void *data, size_t len
return 0;
}
-static int esd_proto_stream_pan(struct connection *c, const void *data, size_t length) {
+static int esd_proto_stream_pan(struct connection *c, esd_proto_t request, const void *data, size_t length) {
int *ok;
uint32_t index, volume;
struct connection *conn;
@@ -381,9 +470,6 @@ static void client_kill_cb(struct pa_client *c) {
static int do_read(struct connection *c) {
assert(c && 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));
@@ -414,7 +500,7 @@ static int do_read(struct connection *c) {
if (handler->data_length == 0) {
c->read_data_length = 0;
- if (handler->proc(c, NULL, 0) < 0)
+ if (handler->proc(c, c->request, NULL, 0) < 0)
return -1;
} else {
@@ -447,10 +533,10 @@ static int do_read(struct connection *c) {
c->state = ESD_NEXT_REQUEST;
c->read_data_length = 0;
- if (handler->proc(c, c->read_data, l) < 0)
+ if (handler->proc(c, c->request, c->read_data, l) < 0)
return -1;
}
- } else if (c->state == ESD_STREAMING_DATA) {
+ } else if (c->state == ESD_STREAMING_DATA && c->sink_input) {
struct pa_memchunk chunk;
ssize_t r;
size_t l;
@@ -460,21 +546,37 @@ static int do_read(struct connection *c) {
if (!(l = pa_memblockq_missing(c->input_memblockq)))
return 0;
- chunk.memblock = pa_memblock_new(l);
- assert(chunk.memblock && chunk.memblock->data);
+ if (l > c->playback.fragment_size)
+ l = c->playback.fragment_size;
- if ((r = pa_iochannel_read(c->io, chunk.memblock->data, l)) <= 0) {
- fprintf(stderr, "protocol-esound.c: read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
- pa_memblock_unref(chunk.memblock);
- return -1;
+ if (c->playback.current_memblock)
+ if (c->playback.current_memblock->length - c->playback.memblock_index < l) {
+ pa_memblock_unref(c->playback.current_memblock);
+ c->playback.current_memblock = NULL;
+ c->playback.memblock_index = 0;
+ }
+
+
+ if (!c->playback.current_memblock) {
+ c->playback.current_memblock = pa_memblock_new(c->playback.fragment_size*2);
+ assert(c->playback.current_memblock && c->playback.current_memblock->length >= l);
+ c->playback.memblock_index = 0;
}
- chunk.memblock->length = chunk.length = r;
- chunk.index = 0;
+ if ((r = pa_iochannel_read(c->io, c->playback.current_memblock->data+c->playback.memblock_index, l)) <= 0) {
+ fprintf(stderr, __FILE__": read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
+ return -1;
+ }
+
+ chunk.memblock = c->playback.current_memblock;
+ chunk.index = c->playback.memblock_index;
+ chunk.length = r;
+ assert(chunk.memblock);
+ c->playback.memblock_index += r;
+
assert(c->input_memblockq);
pa_memblockq_push_align(c->input_memblockq, &chunk, 0);
- pa_memblock_unref(chunk.memblock);
assert(c->sink_input);
pa_sink_notify(c->sink_input->sink);
@@ -485,33 +587,80 @@ static int do_read(struct connection *c) {
}
static int do_write(struct connection *c) {
- ssize_t r;
assert(c && c->io);
- if (!pa_iochannel_is_writable(c->io))
- return 0;
-
- if (!c->write_data_length)
- return 0;
+ if (c->write_data_length) {
+ ssize_t r;
+
+ assert(c->write_data_index < c->write_data_length);
+ 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, __FILE__": write() failed: %s\n", strerror(errno));
+ return -1;
+ }
+
+ if ((c->write_data_index +=r) >= c->write_data_length)
+ c->write_data_length = c->write_data_index = 0;
+
+ } else if (c->state == ESD_STREAMING_DATA && c->source_output) {
+ struct pa_memchunk chunk;
+ ssize_t r;
- assert(c->write_data_index < c->write_data_length);
- 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;
+ assert(c->output_memblockq);
+ if (pa_memblockq_peek(c->output_memblockq, &chunk) < 0)
+ return 0;
+
+ assert(chunk.memblock && chunk.length);
+
+ if ((r = pa_iochannel_write(c->io, chunk.memblock->data+chunk.index, chunk.length)) < 0) {
+ pa_memblock_unref(chunk.memblock);
+ fprintf(stderr, __FILE__": write(): %s\n", strerror(errno));
+ return -1;
+ }
+
+ pa_memblockq_drop(c->output_memblockq, r);
+ pa_memblock_unref(chunk.memblock);
}
-
- if ((c->write_data_index +=r) >= c->write_data_length)
- c->write_data_length = c->write_data_index = 0;
return 0;
}
+static void do_work(struct connection *c) {
+ assert(c);
+
+ assert(c->protocol && c->protocol->core && c->protocol->core->mainloop && c->protocol->core->mainloop->enable_fixed);
+ c->protocol->core->mainloop->enable_fixed(c->protocol->core->mainloop, c->fixed_source, 0);
+
+ if (pa_iochannel_is_hungup(c->io))
+ goto fail;
+
+ if (pa_iochannel_is_writable(c->io))
+ if (do_write(c) < 0)
+ goto fail;
+
+ if (pa_iochannel_is_readable(c->io))
+ if (do_read(c) < 0)
+ goto fail;
+
+ return;
+
+fail:
+ connection_free(c);
+}
+
static void io_callback(struct pa_iochannel*io, void *userdata) {
struct connection *c = userdata;
assert(io && c && c->io == io);
- if (do_read(c) < 0 || do_write(c) < 0)
- connection_free(c);
+ do_work(c);
+}
+
+/*** fixed callback ***/
+
+void fixed_callback(struct pa_mainloop_api*a, void *id, void *userdata) {
+ struct connection *c = userdata;
+ assert(a && c && c->fixed_source == id);
+
+ do_work(c);
}
/*** sink_input callbacks ***/
@@ -532,9 +681,10 @@ static void sink_input_drop_cb(struct pa_sink_input *i, size_t length) {
assert(i && c && length);
pa_memblockq_drop(c->input_memblockq, length);
-
- if (do_read(c) < 0)
- connection_free(c);
+
+ /* do something */
+ assert(c->protocol && c->protocol->core && c->protocol->core->mainloop && c->protocol->core->mainloop->enable_fixed);
+ c->protocol->core->mainloop->enable_fixed(c->protocol->core->mainloop, c->fixed_source, 1);
}
static void sink_input_kill_cb(struct pa_sink_input *i) {
@@ -549,6 +699,24 @@ static uint32_t sink_input_get_latency_cb(struct pa_sink_input *i) {
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 pa_source_output *o, const struct pa_memchunk *chunk) {
+ struct connection *c = o->userdata;
+ assert(o && c && chunk);
+
+ pa_memblockq_push(c->output_memblockq, chunk, 0);
+
+ /* do something */
+ assert(c->protocol && c->protocol->core && c->protocol->core->mainloop && c->protocol->core->mainloop->enable_fixed);
+ c->protocol->core->mainloop->enable_fixed(c->protocol->core->mainloop, c->fixed_source, 1);
+}
+
+static void source_output_kill_cb(struct pa_source_output *o) {
+ assert(o && o->userdata);
+ connection_free((struct connection *) o->userdata);
+}
+
/*** socket server callback ***/
static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, void *userdata) {
@@ -562,7 +730,7 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
c->io = io;
pa_iochannel_set_callback(c->io, io_callback, c);
- pa_iochannel_peer_to_string(io, cname, sizeof(cname));
+ pa_iochannel_socket_peer_to_string(io, cname, sizeof(cname));
assert(c->protocol->core);
c->client = pa_client_new(c->protocol->core, "ESOUND", cname);
assert(c->client);
@@ -585,6 +753,17 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
c->sink_input = NULL;
c->input_memblockq = NULL;
+ c->source_output = NULL;
+ c->output_memblockq = NULL;
+
+ c->playback.current_memblock = NULL;
+ c->playback.memblock_index = 0;
+ c->playback.fragment_size = 0;
+
+ c->fixed_source = c->protocol->core->mainloop->source_fixed(c->protocol->core->mainloop, fixed_callback, c);
+ assert(c->fixed_source);
+ c->protocol->core->mainloop->enable_fixed(c->protocol->core->mainloop, c->fixed_source, 0);
+
pa_idxset_put(c->protocol->connections, c, &c->index);
}
@@ -608,7 +787,7 @@ struct pa_protocol_esound* pa_protocol_esound_new(struct pa_core*core, struct pa
p->core = core;
p->connections = pa_idxset_new(NULL, NULL);
assert(p->connections);
- p->sink_index = PA_IDXSET_INVALID;
+ p->sink_index = p->source_index = PA_IDXSET_INVALID;
p->n_player = 0;
return p;
diff --git a/src/protocol-simple.c b/src/protocol-simple.c
index 91eab59a..3e2e7fda 100644
--- a/src/protocol-simple.c
+++ b/src/protocol-simple.c
@@ -18,6 +18,12 @@ struct connection {
struct pa_source_output *source_output;
struct pa_client *client;
struct pa_memblockq *input_memblockq, *output_memblockq;
+ void *fixed_source;
+
+ struct {
+ struct pa_memblock *current_memblock;
+ size_t memblock_index, fragment_size;
+ } playback;
};
struct pa_protocol_simple {
@@ -29,13 +35,17 @@ struct pa_protocol_simple {
};
#define PLAYBACK_BUFFER_SECONDS (.5)
+#define PLAYBACK_BUFFER_FRAGMENTS (10)
#define RECORD_BUFFER_SECONDS (5)
+#define RECORD_BUFFER_FRAGMENTS (100)
static void connection_free(struct connection *c) {
assert(c);
pa_idxset_remove_by_data(c->protocol->connections, c, NULL);
+ if (c->playback.current_memblock)
+ pa_memblock_unref(c->playback.current_memblock);
if (c->sink_input)
pa_sink_input_free(c->sink_input);
if (c->source_output)
@@ -48,34 +58,49 @@ static void connection_free(struct connection *c) {
pa_memblockq_free(c->input_memblockq);
if (c->output_memblockq)
pa_memblockq_free(c->output_memblockq);
+ if (c->fixed_source)
+ c->protocol->core->mainloop->cancel_fixed(c->protocol->core->mainloop, c->fixed_source);
free(c);
}
+
static int do_read(struct connection *c) {
struct pa_memchunk chunk;
ssize_t r;
size_t l;
- if (!pa_iochannel_is_readable(c->io))
- return 0;
-
if (!c->sink_input || !(l = pa_memblockq_missing(c->input_memblockq)))
return 0;
- chunk.memblock = pa_memblock_new(l);
- assert(chunk.memblock);
+ if (l > c->playback.fragment_size)
+ l = c->playback.fragment_size;
- if ((r = pa_iochannel_read(c->io, chunk.memblock->data, l)) <= 0) {
- fprintf(stderr, "read(): %s\n", r == 0 ? "EOF" : strerror(errno));
- pa_memblock_unref(chunk.memblock);
+ if (c->playback.current_memblock)
+ if (c->playback.current_memblock->length - c->playback.memblock_index < l) {
+ pa_memblock_unref(c->playback.current_memblock);
+ c->playback.current_memblock = NULL;
+ c->playback.memblock_index = 0;
+ }
+
+ if (!c->playback.current_memblock) {
+ c->playback.current_memblock = pa_memblock_new(c->playback.fragment_size*2);
+ assert(c->playback.current_memblock && c->playback.current_memblock->length >= l);
+ c->playback.memblock_index = 0;
+ }
+
+ if ((r = pa_iochannel_read(c->io, c->playback.current_memblock->data+c->playback.memblock_index, l)) <= 0) {
+ fprintf(stderr, __FILE__": read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
return -1;
}
- chunk.memblock->length = chunk.length = r;
- chunk.index = 0;
+ chunk.memblock = c->playback.current_memblock;
+ chunk.index = c->playback.memblock_index;
+ chunk.length = r;
+ assert(chunk.memblock);
+ c->playback.memblock_index += r;
+
assert(c->input_memblockq);
pa_memblockq_push_align(c->input_memblockq, &chunk, 0);
- pa_memblock_unref(chunk.memblock);
assert(c->sink_input);
pa_sink_notify(c->sink_input->sink);
@@ -86,29 +111,51 @@ static int do_write(struct connection *c) {
struct pa_memchunk chunk;
ssize_t r;
- if (!pa_iochannel_is_writable(c->io))
- return 0;
-
if (!c->source_output)
return 0;
assert(c->output_memblockq);
if (pa_memblockq_peek(c->output_memblockq, &chunk) < 0)
return 0;
-
+
assert(chunk.memblock && chunk.length);
if ((r = pa_iochannel_write(c->io, chunk.memblock->data+chunk.index, chunk.length)) < 0) {
- fprintf(stderr, "write(): %s\n", strerror(errno));
pa_memblock_unref(chunk.memblock);
+ fprintf(stderr, "write(): %s\n", strerror(errno));
return -1;
}
pa_memblockq_drop(c->output_memblockq, r);
pa_memblock_unref(chunk.memblock);
+
return 0;
}
+
+static void do_work(struct connection *c) {
+ assert(c);
+
+ assert(c->protocol && c->protocol->core && c->protocol->core->mainloop && c->protocol->core->mainloop->enable_fixed);
+ c->protocol->core->mainloop->enable_fixed(c->protocol->core->mainloop, c->fixed_source, 0);
+
+ if (pa_iochannel_is_hungup(c->io))
+ goto fail;
+
+ if (pa_iochannel_is_writable(c->io))
+ if (do_write(c) < 0)
+ goto fail;
+
+ if (pa_iochannel_is_readable(c->io))
+ if (do_read(c) < 0)
+ goto fail;
+
+ return;
+
+fail:
+ connection_free(c);
+}
+
/*** sink_input callbacks ***/
static int sink_input_peek_cb(struct pa_sink_input *i, struct pa_memchunk *chunk) {
@@ -127,9 +174,10 @@ static void sink_input_drop_cb(struct pa_sink_input *i, size_t length) {
assert(i && c && length);
pa_memblockq_drop(c->input_memblockq, length);
-
- if (do_read(c) < 0)
- connection_free(c);
+
+ /* do something */
+ assert(c->protocol && c->protocol->core && c->protocol->core->mainloop && c->protocol->core->mainloop->enable_fixed);
+ c->protocol->core->mainloop->enable_fixed(c->protocol->core->mainloop, c->fixed_source, 1);
}
static void sink_input_kill_cb(struct pa_sink_input *i) {
@@ -152,8 +200,9 @@ static void source_output_push_cb(struct pa_source_output *o, const struct pa_me
pa_memblockq_push(c->output_memblockq, chunk, 0);
- if (do_write(c) < 0)
- connection_free(c);
+ /* do something */
+ assert(c->protocol && c->protocol->core && c->protocol->core->mainloop && c->protocol->core->mainloop->enable_fixed);
+ c->protocol->core->mainloop->enable_fixed(c->protocol->core->mainloop, c->fixed_source, 1);
}
static void source_output_kill_cb(struct pa_source_output *o) {
@@ -174,11 +223,19 @@ static void io_callback(struct pa_iochannel*io, void *userdata) {
struct connection *c = userdata;
assert(io && c && c->io == io);
- if (do_read(c) < 0 || do_write(c) < 0)
- connection_free(c);
+ do_work(c);
}
-/*** socket_server callbacks */
+/*** fixed callback ***/
+
+void fixed_callback(struct pa_mainloop_api*a, void *id, void *userdata) {
+ struct connection *c = userdata;
+ assert(a && c && c->fixed_source == id);
+
+ do_work(c);
+}
+
+/*** socket_server callbacks ***/
static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, void *userdata) {
struct pa_protocol_simple *p = userdata;
@@ -191,34 +248,19 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
c->io = io;
c->sink_input = NULL;
c->source_output = NULL;
+ c->fixed_source = NULL;
c->input_memblockq = c->output_memblockq = NULL;
c->protocol = p;
-
- pa_iochannel_peer_to_string(io, cname, sizeof(cname));
+ c->playback.current_memblock = NULL;
+ c->playback.memblock_index = 0;
+ c->playback.fragment_size = 0;
+
+ pa_iochannel_socket_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 & PA_PROTOCOL_SIMPLE_RECORD) {
- struct pa_source *source;
- size_t l;
-
- if (!(source = pa_source_get_default(p->core))) {
- fprintf(stderr, "Failed to get default source.\n");
- goto fail;
- }
-
- 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 = (size_t) (pa_bytes_per_second(&p->sample_spec)*RECORD_BUFFER_SECONDS);
- c->output_memblockq = pa_memblockq_new(l, 0, pa_sample_size(&p->sample_spec), l/2, 0);
- }
-
if (p->mode & PA_PROTOCOL_SIMPLE_PLAYBACK) {
struct pa_sink *sink;
size_t l;
@@ -237,12 +279,40 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
c->sink_input->userdata = c;
l = (size_t) (pa_bytes_per_second(&p->sample_spec)*PLAYBACK_BUFFER_SECONDS);
- c->input_memblockq = pa_memblockq_new(l, 0, pa_sample_size(&p->sample_spec), l/2, l/10);
+ c->input_memblockq = pa_memblockq_new(l, 0, pa_sample_size(&p->sample_spec), l/2, l/PLAYBACK_BUFFER_FRAGMENTS);
+ assert(c->input_memblockq);
+ pa_iochannel_socket_set_rcvbuf(io, l/PLAYBACK_BUFFER_FRAGMENTS*5);
+ c->playback.fragment_size = l/10;
}
+ if (p->mode & PA_PROTOCOL_SIMPLE_RECORD) {
+ struct pa_source *source;
+ size_t l;
+
+ if (!(source = pa_source_get_default(p->core))) {
+ fprintf(stderr, "Failed to get default source.\n");
+ goto fail;
+ }
+
+ 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 = (size_t) (pa_bytes_per_second(&p->sample_spec)*RECORD_BUFFER_SECONDS);
+ c->output_memblockq = pa_memblockq_new(l, 0, pa_sample_size(&p->sample_spec), 0, 0);
+ pa_iochannel_socket_set_sndbuf(io, l/RECORD_BUFFER_FRAGMENTS*2);
+ }
+
pa_iochannel_set_callback(c->io, io_callback, c);
pa_idxset_put(p->connections, c, NULL);
+
+ c->fixed_source = p->core->mainloop->source_fixed(p->core->mainloop, fixed_callback, c);
+ assert(c->fixed_source);
+ p->core->mainloop->enable_fixed(p->core->mainloop, c->fixed_source, 0);
+
return;
fail:
diff --git a/src/sample-util.c b/src/sample-util.c
index f37ac78b..5344ecfa 100644
--- a/src/sample-util.c
+++ b/src/sample-util.c
@@ -12,14 +12,12 @@ struct pa_sample_spec pa_default_sample_spec = {
struct pa_memblock *pa_silence_memblock(struct pa_memblock* b, const struct pa_sample_spec *spec) {
assert(b && b->data && spec);
- pa_memblock_assert_exclusive(b);
pa_silence_memory(b->data, b->length, spec);
return b;
}
void pa_silence_memchunk(struct pa_memchunk *c, const struct pa_sample_spec *spec) {
assert(c && c->memblock && c->memblock->data && spec && c->length);
- pa_memblock_assert_exclusive(c->memblock);
pa_silence_memory(c->memblock->data+c->index, c->length, spec);
}
@@ -96,7 +94,6 @@ void pa_volume_memchunk(struct pa_memchunk*c, const struct pa_sample_spec *spec,
size_t n;
assert(c && spec && (c->length % pa_sample_size(spec) == 0));
assert(spec->format == PA_SAMPLE_S16NE);
- pa_memblock_assert_exclusive(c->memblock);
if (volume == PA_VOLUME_NORM)
return;
diff --git a/src/simple.c b/src/simple.c
index 50bfea43..ba0a8f0c 100644
--- a/src/simple.c
+++ b/src/simple.c
@@ -14,24 +14,37 @@ struct pa_simple {
int dead, drained;
};
+static int check_error(struct pa_simple *p, int *perror) {
+ assert(p);
+
+ if (pa_context_is_dead(p->context) || (p->stream && pa_stream_is_dead(p->stream))) {
+ if (perror)
+ *perror = pa_context_errno(p->context);
+ return -1;
+ }
+
+ return 0;
+}
+
static int iterate(struct pa_simple *p, int block, int *perror) {
assert(p && p->context && p->mainloop);
+ if (check_error(p, perror) < 0)
+ return -1;
+
if (!block && !pa_context_is_pending(p->context))
return 0;
-
+
do {
- if (pa_context_is_dead(p->context) || (p->stream && pa_stream_is_dead(p->stream))) {
- if (perror)
- *perror = pa_context_errno(p->context);
- return -1;
- }
-
if (pa_mainloop_iterate(p->mainloop, 1, NULL) < 0) {
if (perror)
*perror = PA_ERROR_INTERNAL;
return -1;
}
+
+ if (check_error(p, perror) < 0)
+ return -1;
+
} while (pa_context_is_pending(p->context));
return 0;
diff --git a/src/sink.c b/src/sink.c
index 4852edcc..80560724 100644
--- a/src/sink.c
+++ b/src/sink.c
@@ -174,7 +174,6 @@ int pa_sink_render_into(struct pa_sink*s, struct pa_memchunk *target) {
unsigned n;
size_t l;
assert(s && target && target->length && target->memblock && target->memblock->data);
- pa_memblock_assert_exclusive(target->memblock);
n = fill_mix_info(s, info, MAX_MIX_CHANNELS);
diff --git a/src/sinkinput.c b/src/sinkinput.c
index 20ab25ea..f3e474bc 100644
--- a/src/sinkinput.c
+++ b/src/sinkinput.c
@@ -89,8 +89,7 @@ char *pa_sink_input_list_to_string(struct pa_core *c) {
pa_sample_snprint(ss, sizeof(ss), &i->sample_spec);
assert(i->sink);
pa_strbuf_printf(
- s,
- " index: %u\n\tname: <%s>\n\tsink: <%u>\n\tvolume: <0x%04x>\n\tlatency: <%u usec>\n\tsample_spec: <%s>\n",
+ s, " index: %u\n\tname: <%s>\n\tsink: <%u>\n\tvolume: <0x%04x>\n\tlatency: <%u usec>\n\tsample_spec: <%s>\n",
i->index,
i->name,
i->sink->index,
diff --git a/src/socket-client.c b/src/socket-client.c
index 6ff11980..9a8c5607 100644
--- a/src/socket-client.c
+++ b/src/socket-client.c
@@ -120,7 +120,7 @@ struct pa_socket_client* pa_socket_client_new_ipv4(struct pa_mainloop_api *m, ui
goto fail;
}
- pa_make_tcp_socket_low_delay(c->fd);
+ pa_socket_tcp_low_delay(c->fd);
sa.sin_family = AF_INET;
sa.sin_port = htons(port);
@@ -149,7 +149,7 @@ struct pa_socket_client* pa_socket_client_new_unix(struct pa_mainloop_api *m, co
goto fail;
}
- pa_make_socket_low_delay(c->fd);
+ pa_socket_low_delay(c->fd);
sa.sun_family = AF_LOCAL;
strncpy(sa.sun_path, filename, sizeof(sa.sun_path)-1);
diff --git a/src/socket-server.c b/src/socket-server.c
index 6a7d9415..23d8f7e7 100644
--- a/src/socket-server.c
+++ b/src/socket-server.c
@@ -43,9 +43,9 @@ static void callback(struct pa_mainloop_api *mainloop, void *id, int fd, enum pa
/* There should be a check for socket type here */
if (s->type == SOCKET_SERVER_IPV4)
- pa_make_tcp_socket_low_delay(fd);
+ pa_socket_tcp_low_delay(fd);
else
- pa_make_socket_low_delay(fd);
+ pa_socket_low_delay(fd);
io = pa_iochannel_new(s->mainloop, nfd, nfd);
assert(io);
@@ -88,7 +88,7 @@ struct pa_socket_server* pa_socket_server_new_unix(struct pa_mainloop_api *m, co
strncpy(sa.sun_path, filename, sizeof(sa.sun_path)-1);
sa.sun_path[sizeof(sa.sun_path) - 1] = 0;
- pa_make_socket_low_delay(fd);
+ pa_socket_low_delay(fd);
if (bind(fd, (struct sockaddr*) &sa, SUN_LEN(&sa)) < 0) {
fprintf(stderr, "bind(): %s\n", strerror(errno));
@@ -133,7 +133,7 @@ struct pa_socket_server* pa_socket_server_new_ipv4(struct pa_mainloop_api *m, ui
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
fprintf(stderr, "setsockopt(): %s\n", strerror(errno));
- pa_make_tcp_socket_low_delay(fd);
+ pa_socket_tcp_low_delay(fd);
sa.sin_family = AF_INET;
sa.sin_port = htons(port);
diff --git a/src/sourceoutput.c b/src/sourceoutput.c
index 388f1225..442dc7f4 100644
--- a/src/sourceoutput.c
+++ b/src/sourceoutput.c
@@ -72,11 +72,10 @@ char *pa_source_output_list_to_string(struct pa_core *c) {
pa_sample_snprint(ss, sizeof(ss), &o->sample_spec);
assert(o->source);
pa_strbuf_printf(
- s, " %c index: %u\n\tname: <%s>\n\tsource: <%u>\n\tsample_spec: <%u>\n",
+ s, " index: %u\n\tname: <%s>\n\tsource: <%u>\n\tsample_spec: <%s>\n",
o->index,
o->name,
o->source->index,
- ss,
ss);
}
diff --git a/src/todo b/src/todo
index 93ba2821..18da09d8 100644
--- a/src/todo
+++ b/src/todo
@@ -1,14 +1,20 @@
-- recording (general, simple, esound, native)
+- recording (esound, native)
- native library/protocol:
more functions (esp. latency)
-- simple library
- config parser/cmdline
+- description field for all entities
+- client field for sinkinput/sourceoutput
+- module field for all entities
+
- move more stuff from module-oss[-dma] to liboss-util
- in module-oss: create source first, than sink
-- client field for sinkinput/sourceoutput
+- merge memchunks in memblockq
+
+- create libstatustext, libsocketutil
+- prefix modules/libraries with pa_
- xmms+esound latency testing
@@ -16,6 +22,8 @@
- svn-id and license in every file
- documentation
+
+
-- post 0.1
- future cancellation
- client-ui
diff --git a/src/util.c b/src/util.c
index 3111bd5d..6fe4bbee 100644
--- a/src/util.c
+++ b/src/util.c
@@ -87,36 +87,27 @@ fail:
return -1;
}
-int pa_make_socket_low_delay(int fd) {
- int ret = 0, buf_size, priority;
-
+int pa_socket_low_delay(int fd) {
+ int priority;
assert(fd >= 0);
- buf_size = 1024;
- if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &buf_size, sizeof(buf_size)) < 0)
- ret = -1;
-
- buf_size = 1024;
- if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &buf_size, sizeof(buf_size)) < 0)
- ret = -1;
-
priority = 7;
if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &priority, sizeof(priority)) < 0)
- ret = -1;
+ return -1;
- return ret;
+ return 0;
}
-int pa_make_tcp_socket_low_delay(int fd) {
- int ret, tos, on;
-
+int pa_socket_tcp_low_delay(int fd) {
+ int ret, tos;
+
assert(fd >= 0);
- ret = pa_make_socket_low_delay(fd);
+ ret = pa_socket_low_delay(fd);
- on = 1;
- if (setsockopt(fd, SOL_TCP, TCP_NODELAY, &on, sizeof(on)) < 0)
- ret = -1;
+/* on = 1; */
+/* if (setsockopt(fd, SOL_TCP, TCP_NODELAY, &on, sizeof(on)) < 0) */
+/* ret = -1; */
tos = IPTOS_LOWDELAY;
if (setsockopt(fd, SOL_IP, IP_TOS, &tos, sizeof(tos)) < 0)
@@ -126,6 +117,24 @@ int pa_make_tcp_socket_low_delay(int fd) {
}
+int pa_socket_set_rcvbuf(int fd, size_t l) {
+ assert(fd >= 0);
+
+ if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &l, sizeof(l)) < 0)
+ return -1;
+
+ return 0;
+}
+
+int pa_socket_set_sndbuf(int fd, size_t l) {
+ assert(fd >= 0);
+
+ if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &l, sizeof(l)) < 0)
+ return -1;
+
+ return 0;
+}
+
ssize_t pa_loop_read(int fd, void*data, size_t size) {
ssize_t ret = 0;
assert(fd >= 0 && data && size);
diff --git a/src/util.h b/src/util.h
index ad9916e7..dba89ee8 100644
--- a/src/util.h
+++ b/src/util.h
@@ -9,8 +9,11 @@ void pa_peer_to_string(char *c, size_t l, 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);
+int pa_socket_low_delay(int fd);
+int pa_socket_tcp_low_delay(int fd);
+
+int pa_socket_set_sndbuf(int fd, size_t l);
+int pa_socket_set_rcvbuf(int fd, size_t l);
ssize_t pa_loop_read(int fd, void*data, size_t size);
ssize_t pa_loop_write(int fd, const void*data, size_t size);