[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, master, updated. v0.9.19-484-gc970131
Lennart Poettering
gitmailer-noreply at 0pointer.de
Mon Feb 22 16:23:43 PST 2010
This is an automated email from the git hooks/post-receive script. It was
generated because of a push to the "PulseAudio Sound Server" repository.
The master branch has been updated
from b5e30764c4dc7a764295adb9a75bdb2bba880c5e (commit)
- Log -----------------------------------------------------------------
c970131 esd,simple: use pa_memblockq_pop_missing()
dbdc666 various modernizations
028aa73 iochannel: remove fd from poll() when we don't care from events
-----------------------------------------------------------------------
Summary of changes:
src/pulsecore/iochannel.c | 166 ++++++++++++++++++++++-----------------
src/pulsecore/iochannel.h | 5 -
src/pulsecore/protocol-esound.c | 26 +++---
src/pulsecore/protocol-native.c | 2 +-
src/pulsecore/protocol-simple.c | 2 +-
5 files changed, 109 insertions(+), 92 deletions(-)
-----------------------------------------------------------------------
commit 028aa734f88e9db2376aaf08a90f8986d31353da
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Feb 23 01:20:20 2010 +0100
iochannel: remove fd from poll() when we don't care from events
This should make it unlikely that we loop on SIGHUP indefinitely.
Also, this makes it possible for callbacks not to process all events and
still not busy loop.
diff --git a/src/pulsecore/iochannel.c b/src/pulsecore/iochannel.c
index b40c981..4833007 100644
--- a/src/pulsecore/iochannel.c
+++ b/src/pulsecore/iochannel.c
@@ -28,7 +28,6 @@
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
-
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
@@ -65,24 +64,71 @@ struct pa_iochannel {
pa_io_event* input_event, *output_event;
};
-static void enable_mainloop_sources(pa_iochannel *io) {
+static void callback(pa_mainloop_api* m, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata);
+
+static void delete_events(pa_iochannel *io) {
+ pa_assert(io);
+
+ if (io->input_event)
+ io->mainloop->io_free(io->input_event);
+
+ if (io->output_event && io->output_event != io->input_event)
+ io->mainloop->io_free(io->output_event);
+
+ io->input_event = io->output_event = NULL;
+}
+
+static void enable_events(pa_iochannel *io) {
pa_assert(io);
- if (io->input_event == io->output_event && io->input_event) {
+ if (io->hungup) {
+ delete_events(io);
+ return;
+ }
+
+ if (io->ifd == io->ofd && io->ifd >= 0) {
pa_io_event_flags_t f = PA_IO_EVENT_NULL;
- pa_assert(io->input_event);
if (!io->readable)
f |= PA_IO_EVENT_INPUT;
if (!io->writable)
f |= PA_IO_EVENT_OUTPUT;
- io->mainloop->io_enable(io->input_event, f);
+ pa_assert(io->input_event == io->output_event);
+
+ if (f != PA_IO_EVENT_NULL) {
+ if (io->input_event)
+ io->mainloop->io_enable(io->input_event, f);
+ else
+ io->input_event = io->output_event = io->mainloop->io_new(io->mainloop, io->ifd, f, callback, io);
+ } else
+ delete_events(io);
+
} else {
- if (io->input_event)
- io->mainloop->io_enable(io->input_event, io->readable ? PA_IO_EVENT_NULL : PA_IO_EVENT_INPUT);
- if (io->output_event)
- io->mainloop->io_enable(io->output_event, io->writable ? PA_IO_EVENT_NULL : PA_IO_EVENT_OUTPUT);
+
+ if (io->ifd >= 0) {
+ if (!io->readable) {
+ if (io->input_event)
+ io->mainloop->io_enable(io->input_event, PA_IO_EVENT_INPUT);
+ else
+ io->input_event = io->mainloop->io_new(io->mainloop, io->ifd, PA_IO_EVENT_INPUT, callback, io);
+ } else if (io->input_event) {
+ io->mainloop->io_free(io->input_event);
+ io->input_event = NULL;
+ }
+ }
+
+ if (io->ofd >= 0) {
+ if (!io->writable) {
+ if (io->output_event)
+ io->mainloop->io_enable(io->output_event, PA_IO_EVENT_OUTPUT);
+ else
+ io->output_event = io->mainloop->io_new(io->mainloop, io->ofd, PA_IO_EVENT_OUTPUT, callback, io);
+ } else if (io->input_event) {
+ io->mainloop->io_free(io->output_event);
+ io->output_event = NULL;
+ }
+ }
}
}
@@ -113,7 +159,7 @@ static void callback(pa_mainloop_api* m, pa_io_event *e, int fd, pa_io_event_fla
}
if (changed) {
- enable_mainloop_sources(io);
+ enable_events(io);
if (io->callback)
io->callback(io, io->userdata);
@@ -126,49 +172,25 @@ pa_iochannel* pa_iochannel_new(pa_mainloop_api*m, int ifd, int ofd) {
pa_assert(m);
pa_assert(ifd >= 0 || ofd >= 0);
- io = pa_xnew(pa_iochannel, 1);
+ io = pa_xnew0(pa_iochannel, 1);
io->ifd = ifd;
io->ofd = ofd;
- io->ifd_type = io->ofd_type = 0;
io->mainloop = m;
- io->userdata = NULL;
- io->callback = NULL;
- io->readable = FALSE;
- io->writable = FALSE;
- io->hungup = FALSE;
- io->no_close = FALSE;
-
- io->input_event = io->output_event = NULL;
-
- if (ifd == ofd) {
- pa_assert(ifd >= 0);
+ if (io->ifd >= 0)
pa_make_fd_nonblock(io->ifd);
- io->input_event = io->output_event = m->io_new(m, ifd, PA_IO_EVENT_INPUT|PA_IO_EVENT_OUTPUT, callback, io);
- } else {
-
- if (ifd >= 0) {
- pa_make_fd_nonblock(io->ifd);
- io->input_event = m->io_new(m, ifd, PA_IO_EVENT_INPUT, callback, io);
- }
- if (ofd >= 0) {
- pa_make_fd_nonblock(io->ofd);
- io->output_event = m->io_new(m, ofd, PA_IO_EVENT_OUTPUT, callback, io);
- }
- }
+ if (io->ofd >= 0 && io->ofd != io->ifd)
+ pa_make_fd_nonblock(io->ofd);
+ enable_events(io);
return io;
}
void pa_iochannel_free(pa_iochannel*io) {
pa_assert(io);
- if (io->input_event)
- io->mainloop->io_free(io->input_event);
-
- if (io->output_event && (io->output_event != io->input_event))
- io->mainloop->io_free(io->output_event);
+ delete_events(io);
if (!io->no_close) {
if (io->ifd >= 0)
@@ -207,8 +229,8 @@ ssize_t pa_iochannel_write(pa_iochannel*io, const void*data, size_t l) {
pa_assert(io->ofd >= 0);
if ((r = pa_write(io->ofd, data, l, &io->ofd_type)) >= 0) {
- io->writable = FALSE;
- enable_mainloop_sources(io);
+ io->writable = io->hungup = FALSE;
+ enable_events(io);
}
return r;
@@ -222,8 +244,12 @@ ssize_t pa_iochannel_read(pa_iochannel*io, void*data, size_t l) {
pa_assert(io->ifd >= 0);
if ((r = pa_read(io->ifd, data, l, &io->ifd_type)) >= 0) {
- io->readable = FALSE;
- enable_mainloop_sources(io);
+
+ /* We also reset the hangup flag here to ensure that another
+ * IO callback is triggered so that we will again call into
+ * user code */
+ io->readable = io->hungup = FALSE;
+ enable_events(io);
}
return r;
@@ -296,18 +322,15 @@ ssize_t pa_iochannel_write_with_creds(pa_iochannel*io, const void*data, size_t l
u->gid = getgid();
}
- memset(&mh, 0, sizeof(mh));
- mh.msg_name = NULL;
- mh.msg_namelen = 0;
+ pa_zero(mh);
mh.msg_iov = &iov;
mh.msg_iovlen = 1;
mh.msg_control = &cmsg;
mh.msg_controllen = sizeof(cmsg);
- mh.msg_flags = 0;
if ((r = sendmsg(io->ofd, &mh, MSG_NOSIGNAL)) >= 0) {
- io->writable = FALSE;
- enable_mainloop_sources(io);
+ io->writable = io->hungup = FALSE;
+ enable_events(io);
}
return r;
@@ -363,8 +386,8 @@ ssize_t pa_iochannel_read_with_creds(pa_iochannel*io, void*data, size_t l, pa_cr
}
}
- io->readable = FALSE;
- enable_mainloop_sources(io);
+ io->readable = io->hungup = FALSE;
+ enable_events(io);
}
return r;
diff --git a/src/pulsecore/iochannel.h b/src/pulsecore/iochannel.h
index 9050df9..180245b 100644
--- a/src/pulsecore/iochannel.h
+++ b/src/pulsecore/iochannel.h
@@ -38,11 +38,6 @@
the channel a callback function is called. It is safe to destroy
the calling iochannel object from the callback */
-/* When pa_iochannel_is_readable() returns non-zero, the user has to
- * call this function in a loop until it is no longer set or EOF
- * reached. Otherwise strange things may happen when an EOF is
- * reached. */
-
typedef struct pa_iochannel pa_iochannel;
/* Create a new IO channel for the specified file descriptors for
commit dbdc666fb6cc2719fa21c346300b87705e9fa1f3
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Feb 23 01:23:41 2010 +0100
various modernizations
diff --git a/src/pulsecore/iochannel.c b/src/pulsecore/iochannel.c
index 4833007..f85c989 100644
--- a/src/pulsecore/iochannel.c
+++ b/src/pulsecore/iochannel.c
@@ -55,11 +55,10 @@ struct pa_iochannel {
pa_iochannel_cb_t callback;
void*userdata;
- pa_bool_t readable;
- pa_bool_t writable;
- pa_bool_t hungup;
-
- pa_bool_t no_close;
+ pa_bool_t readable:1;
+ pa_bool_t writable:1;
+ pa_bool_t hungup:1;
+ pa_bool_t no_close:1;
pa_io_event* input_event, *output_event;
};
@@ -258,7 +257,12 @@ ssize_t pa_iochannel_read(pa_iochannel*io, void*data, size_t l) {
#ifdef HAVE_CREDS
pa_bool_t pa_iochannel_creds_supported(pa_iochannel *io) {
- struct sockaddr_un sa;
+ struct {
+ struct sockaddr sa;
+ struct sockaddr_un un;
+ struct sockaddr_storage storage;
+ } sa;
+
socklen_t l;
pa_assert(io);
@@ -266,11 +270,10 @@ pa_bool_t pa_iochannel_creds_supported(pa_iochannel *io) {
pa_assert(io->ofd == io->ifd);
l = sizeof(sa);
+ if (getsockname(io->ifd, &sa.sa, &l) < 0)
+ return FALSE;
- if (getsockname(io->ifd, (struct sockaddr*) &sa, &l) < 0)
- return 0;
-
- return sa.sun_family == AF_UNIX;
+ return sa.sa.sa_family == AF_UNIX;
}
int pa_iochannel_creds_enable(pa_iochannel *io) {
@@ -302,11 +305,11 @@ ssize_t pa_iochannel_write_with_creds(pa_iochannel*io, const void*data, size_t l
pa_assert(l);
pa_assert(io->ofd >= 0);
- memset(&iov, 0, sizeof(iov));
+ pa_zero(iov);
iov.iov_base = (void*) data;
iov.iov_len = l;
- memset(&cmsg, 0, sizeof(cmsg));
+ pa_zero(cmsg);
cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(struct ucred));
cmsg.hdr.cmsg_level = SOL_SOCKET;
cmsg.hdr.cmsg_type = SCM_CREDENTIALS;
@@ -352,25 +355,21 @@ ssize_t pa_iochannel_read_with_creds(pa_iochannel*io, void*data, size_t l, pa_cr
pa_assert(creds);
pa_assert(creds_valid);
- memset(&iov, 0, sizeof(iov));
+ pa_zero(iov);
iov.iov_base = data;
iov.iov_len = l;
- memset(&cmsg, 0, sizeof(cmsg));
-
- memset(&mh, 0, sizeof(mh));
- mh.msg_name = NULL;
- mh.msg_namelen = 0;
+ pa_zero(cmsg);
+ pa_zero(mh);
mh.msg_iov = &iov;
mh.msg_iovlen = 1;
mh.msg_control = &cmsg;
mh.msg_controllen = sizeof(cmsg);
- mh.msg_flags = 0;
if ((r = recvmsg(io->ifd, &mh, 0)) >= 0) {
struct cmsghdr *cmh;
- *creds_valid = 0;
+ *creds_valid = FALSE;
for (cmh = CMSG_FIRSTHDR(&mh); cmh; cmh = CMSG_NXTHDR(&mh, cmh)) {
diff --git a/src/pulsecore/protocol-esound.c b/src/pulsecore/protocol-esound.c
index a89f327..be205c2 100644
--- a/src/pulsecore/protocol-esound.c
+++ b/src/pulsecore/protocol-esound.c
@@ -328,12 +328,12 @@ static int format_native2esd(pa_sample_spec *ss) {
return format;
}
-#define CHECK_VALIDITY(expression, ...) do { \
- if (!(expression)) { \
- pa_log_warn(__FILE__ ": " __VA_ARGS__); \
- return -1; \
- } \
-} while(0);
+#define CHECK_VALIDITY(expression, ...) do { \
+ if (PA_UNLIKELY(!(expression))) { \
+ pa_log_warn(__FILE__ ": " __VA_ARGS__); \
+ return -1; \
+ } \
+ } while(0);
/*** esound commands ***/
@@ -631,7 +631,7 @@ static int esd_proto_all_info(connection *c, esd_proto_t request, const void *da
memset(terminator, 0, sizeof(terminator));
- for (conn = pa_idxset_first(c->protocol->connections, &idx); conn; conn = pa_idxset_next(c->protocol->connections, &idx)) {
+ PA_IDXSET_FOREACH(conn, c->protocol->connections, idx) {
int32_t id, format = ESD_BITS16 | ESD_STEREO, rate = 44100, lvolume = ESD_VOLUME_BASE, rvolume = ESD_VOLUME_BASE;
char name[ESD_NAME_MAX];
@@ -689,7 +689,8 @@ static int esd_proto_all_info(connection *c, esd_proto_t request, const void *da
pa_scache_entry *ce;
idx = PA_IDXSET_INVALID;
- for (ce = pa_idxset_first(c->protocol->core->scache, &idx); ce; ce = pa_idxset_next(c->protocol->core->scache, &idx)) {
+
+ PA_IDXSET_FOREACH(ce, c->protocol->core->scache, idx) {
int32_t id, rate, lvolume, rvolume, format, len;
char name[ESD_NAME_MAX];
pa_channel_map stereo = { .channels = 2, .map = { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT } };
@@ -1130,7 +1131,7 @@ static int do_read(connection *c) {
/* pa_log("STREAMING_DATA"); */
- if (!(l = (size_t) pa_atomic_load(&c->playback.missing)))
+ if ((l = (size_t) pa_atomic_load(&c->playback.missing)) <= 0)
return 0;
if (c->playback.current_memblock) {
@@ -1172,8 +1173,8 @@ static int do_read(connection *c) {
c->playback.memblock_index += (size_t) r;
- pa_asyncmsgq_post(c->sink_input->sink->asyncmsgq, PA_MSGOBJECT(c->sink_input), SINK_INPUT_MESSAGE_POST_DATA, NULL, 0, &chunk, NULL);
pa_atomic_sub(&c->playback.missing, (int) r);
+ pa_asyncmsgq_post(c->sink_input->sink->asyncmsgq, PA_MSGOBJECT(c->sink_input), SINK_INPUT_MESSAGE_POST_DATA, NULL, 0, &chunk, NULL);
}
return 0;
@@ -1381,10 +1382,9 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk
} else {
size_t m;
- chunk->length = PA_MIN(length, chunk->length);
-
c->playback.underrun = FALSE;
+ chunk->length = PA_MIN(length, chunk->length);
pa_memblockq_drop(c->input_memblockq, chunk->length);
m = pa_memblockq_pop_missing(c->input_memblockq);
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index 2721dbe..f3d240b 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -1037,7 +1037,7 @@ static playback_stream* playback_stream_new(
pa_assert(ret);
/* Find syncid group */
- for (ssync = pa_idxset_first(c->output_streams, &idx); ssync; ssync = pa_idxset_next(c->output_streams, &idx)) {
+ PA_IDXSET_FOREACH(ssync, c->output_streams, idx) {
if (!playback_stream_isinstance(ssync))
continue;
commit c97013109494f9bc977db38d6ae4e972e59574f4
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Feb 23 00:48:35 2010 +0100
esd,simple: use pa_memblockq_pop_missing()
We need to use pa_memblockq_pop_missing() for all request handling,
including the initial request, because otherwise the counters will be
stay off during the entire runtime.
This should fix:
https://bugzilla.redhat.com/show_bug.cgi?id=559467
diff --git a/src/pulsecore/protocol-esound.c b/src/pulsecore/protocol-esound.c
index be205c2..045c5c9 100644
--- a/src/pulsecore/protocol-esound.c
+++ b/src/pulsecore/protocol-esound.c
@@ -462,7 +462,7 @@ static int esd_proto_stream_play(connection *c, esd_proto_t request, const void
c->protocol->n_player++;
- pa_atomic_store(&c->playback.missing, (int) pa_memblockq_missing(c->input_memblockq));
+ pa_atomic_store(&c->playback.missing, (int) pa_memblockq_pop_missing(c->input_memblockq));
pa_sink_input_put(c->sink_input);
diff --git a/src/pulsecore/protocol-simple.c b/src/pulsecore/protocol-simple.c
index fb2e564..77277e1 100644
--- a/src/pulsecore/protocol-simple.c
+++ b/src/pulsecore/protocol-simple.c
@@ -574,7 +574,7 @@ void pa_simple_protocol_connect(pa_simple_protocol *p, pa_iochannel *io, pa_simp
pa_iochannel_socket_set_rcvbuf(io, l);
- pa_atomic_store(&c->playback.missing, (int) pa_memblockq_missing(c->input_memblockq));
+ pa_atomic_store(&c->playback.missing, (int) pa_memblockq_pop_missing(c->input_memblockq));
pa_sink_input_put(c->sink_input);
}
--
hooks/post-receive
PulseAudio Sound Server
More information about the pulseaudio-commits
mailing list