summaryrefslogtreecommitdiffstats
path: root/src/pstream.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-07-10 16:50:22 +0000
committerLennart Poettering <lennart@poettering.net>2004-07-10 16:50:22 +0000
commit70bb8165ec0aefef08d524dc72baa29df658b4c0 (patch)
tree59429df733cb7a292c8f8649234d40935d8448c2 /src/pstream.c
parentcffc7768bd5b8d16308c15102b4d03d08d287098 (diff)
implement recording in native API
fix a memory leak in memblock.c git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@55 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src/pstream.c')
-rw-r--r--src/pstream.c54
1 files changed, 31 insertions, 23 deletions
diff --git a/src/pstream.c b/src/pstream.c
index 19f83e30..18d33b0d 100644
--- a/src/pstream.c
+++ b/src/pstream.c
@@ -38,7 +38,7 @@ struct pa_pstream {
int in_use, shall_free;
int dead;
- void (*die_callback) (struct pa_pstream *p, void *userdad);
+ void (*die_callback) (struct pa_pstream *p, void *userdata);
void *die_callback_userdata;
struct {
@@ -59,7 +59,7 @@ struct pa_pstream {
void (*recieve_packet_callback) (struct pa_pstream *p, struct pa_packet *packet, void *userdata);
void *recieve_packet_callback_userdata;
- void (*recieve_memblock_callback) (struct pa_pstream *p, uint32_t channel, int32_t delta, struct pa_memchunk *chunk, void *userdata);
+ void (*recieve_memblock_callback) (struct pa_pstream *p, uint32_t channel, int32_t delta, const struct pa_memchunk *chunk, void *userdata);
void *recieve_memblock_callback_userdata;
void (*drain_callback)(struct pa_pstream *p, void *userdata);
@@ -73,21 +73,36 @@ static void do_something(struct pa_pstream *p) {
assert(p && !p->shall_free);
p->mainloop->enable_fixed(p->mainloop, p->mainloop_source, 0);
- p->in_use = 1;
- do_write(p);
- p->in_use = 0;
+ if (p->dead)
+ return;
+
+ if (pa_iochannel_is_hungup(p->io)) {
+ p->dead = 1;
+ if (p->die_callback)
+ p->die_callback(p, p->die_callback_userdata);
- if (p->shall_free) {
- pa_pstream_free(p);
return;
}
-
- p->in_use = 1;
- do_read(p);
- p->in_use = 0;
- if (p->shall_free) {
- pa_pstream_free(p);
- return;
+
+ if (pa_iochannel_is_writable(p->io)) {
+ p->in_use = 1;
+ do_write(p);
+ p->in_use = 0;
+
+ if (p->shall_free) {
+ pa_pstream_free(p);
+ return;
+ }
+ }
+
+ if (pa_iochannel_is_readable(p->io)) {
+ p->in_use = 1;
+ do_read(p);
+ p->in_use = 0;
+ if (p->shall_free) {
+ pa_pstream_free(p);
+ return;
+ }
}
}
@@ -199,7 +214,7 @@ void pa_pstream_send_packet(struct pa_pstream*p, struct pa_packet *packet) {
p->mainloop->enable_fixed(p->mainloop, p->mainloop_source, 1);
}
-void pa_pstream_send_memblock(struct pa_pstream*p, uint32_t channel, int32_t delta, struct pa_memchunk *chunk) {
+void pa_pstream_send_memblock(struct pa_pstream*p, uint32_t channel, int32_t delta, const struct pa_memchunk *chunk) {
struct item_info *i;
assert(p && channel != (uint32_t) -1 && chunk);
@@ -223,7 +238,7 @@ void pa_pstream_set_recieve_packet_callback(struct pa_pstream *p, void (*callbac
p->recieve_packet_callback_userdata = userdata;
}
-void pa_pstream_set_recieve_memblock_callback(struct pa_pstream *p, void (*callback) (struct pa_pstream *p, uint32_t channel, int32_t delta, struct pa_memchunk *chunk, void *userdata), void *userdata) {
+void pa_pstream_set_recieve_memblock_callback(struct pa_pstream *p, void (*callback) (struct pa_pstream *p, uint32_t channel, int32_t delta, const struct pa_memchunk *chunk, void *userdata), void *userdata) {
assert(p && callback);
p->recieve_memblock_callback = callback;
@@ -259,9 +274,6 @@ static void do_write(struct pa_pstream *p) {
ssize_t r;
assert(p);
- if (p->dead || !pa_iochannel_is_writable(p->io))
- return;
-
if (!p->write.current)
prepare_next_write_item(p);
@@ -306,9 +318,6 @@ static void do_read(struct pa_pstream *p) {
ssize_t r;
assert(p);
- if (p->dead || !pa_iochannel_is_readable(p->io))
- return;
-
if (p->read.index < PA_PSTREAM_DESCRIPTOR_SIZE) {
d = (void*) p->read.descriptor + p->read.index;
l = PA_PSTREAM_DESCRIPTOR_SIZE - p->read.index;
@@ -416,7 +425,6 @@ int pa_pstream_is_pending(struct pa_pstream *p) {
void pa_pstream_set_drain_callback(struct pa_pstream *p, void (*cb)(struct pa_pstream *p, void *userdata), void *userdata) {
assert(p);
- assert(!cb || pa_pstream_is_pending(p));
p->drain_callback = cb;
p->drain_userdata = userdata;