]> code.delx.au - pulseaudio/blobdiff - polyp/pstream.c
Make the whole stuff LGPL only
[pulseaudio] / polyp / pstream.c
index 81ee0b439b65ab5a81d7377cad78a4dbb8522649..11ca3963b609d1ab7fe8b2f5059257b5a03596d2 100644 (file)
@@ -4,17 +4,17 @@
   This file is part of polypaudio.
  
   polypaudio is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
-  or (at your option) any later version.
+  it under the terms of the GNU Lesser General Public License as
+  published by the Free Software Foundation; either version 2.1 of the
+  License, or (at your option) any later version.
  
   polypaudio is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  General Public License for more details.
+  Lesser General Public License for more details.
  
-  You should have received a copy of the GNU General Public License
-  along with polypaudio; if not, write to the Free Software
+  You should have received a copy of the GNU Lesser General Public
+  License along with polypaudio; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
   USA.
 ***/
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
+#include <unistd.h>
 #include <netinet/in.h>
 
 #include "pstream.h"
 #include "queue.h"
 #include "xmalloc.h"
+#include "log.h"
 
 enum pa_pstream_descriptor_index {
     PA_PSTREAM_DESCRIPTOR_LENGTH,
@@ -100,6 +102,10 @@ static void do_read(struct pa_pstream *p);
 
 static void do_something(struct pa_pstream *p) {
     assert(p);
+
+    if (p->dead)
+        return;
+    
     p->mainloop->defer_enable(p->defer_event, 0);
 
     pa_pstream_ref(p);
@@ -169,6 +175,9 @@ struct pa_pstream *pa_pstream_new(struct pa_mainloop_api *m, struct pa_iochannel
 
     p->memblock_stat = s;
 
+    pa_iochannel_socket_set_rcvbuf(io, 1024*8); 
+    pa_iochannel_socket_set_sndbuf(io, 1024*8); 
+
     return p;
 }
 
@@ -209,9 +218,12 @@ static void pstream_free(struct pa_pstream *p) {
 
 void pa_pstream_send_packet(struct pa_pstream*p, struct pa_packet *packet) {
     struct item_info *i;
-    assert(p && packet);
+    assert(p && packet && p->ref >= 1);
 
-    /*fprintf(stderr, "push-packet %p\n", packet);*/
+    if (p->dead)
+        return;
+    
+/*     pa_log(__FILE__": push-packet %p\n", packet); */
     
     i = pa_xmalloc(sizeof(struct item_info));
     i->type = PA_PSTREAM_ITEM_PACKET;
@@ -223,7 +235,12 @@ 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, uint32_t delta, const struct pa_memchunk *chunk) {
     struct item_info *i;
-    assert(p && channel != (uint32_t) -1 && chunk);
+    assert(p && channel != (uint32_t) -1 && chunk && p->ref >= 1);
+
+    if (p->dead)
+        return;
+    
+/*     pa_log(__FILE__": push-memblock %p\n", chunk); */
     
     i = pa_xmalloc(sizeof(struct item_info));
     i->type = PA_PSTREAM_ITEM_MEMBLOCK;
@@ -260,7 +277,7 @@ static void prepare_next_write_item(struct pa_pstream *p) {
     p->write.index = 0;
     
     if (p->write.current->type == PA_PSTREAM_ITEM_PACKET) {
-        /*fprintf(stderr, "pop-packet %p\n", p->write.current->packet);*/
+        /*pa_log(__FILE__": pop-packet %p\n", p->write.current->packet);*/
         
         assert(p->write.current->packet);
         p->write.data = p->write.current->packet->data;
@@ -269,7 +286,7 @@ static void prepare_next_write_item(struct pa_pstream *p) {
         p->write.descriptor[PA_PSTREAM_DESCRIPTOR_DELTA] = 0;
     } else {
         assert(p->write.current->type == PA_PSTREAM_ITEM_MEMBLOCK && p->write.current->chunk.memblock);
-        p->write.data = p->write.current->chunk.memblock->data + p->write.current->chunk.index;
+        p->write.data = (uint8_t*) p->write.current->chunk.memblock->data + p->write.current->chunk.index;
         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);
@@ -291,10 +308,10 @@ static void do_write(struct pa_pstream *p) {
     assert(p->write.data);
 
     if (p->write.index < PA_PSTREAM_DESCRIPTOR_SIZE) {
-        d = (void*) p->write.descriptor + p->write.index;
+        d = (uint8_t*) p->write.descriptor + p->write.index;
         l = PA_PSTREAM_DESCRIPTOR_SIZE - p->write.index;
     } else {
-        d = (void*) p->write.data + p->write.index - PA_PSTREAM_DESCRIPTOR_SIZE;
+        d = (uint8_t*) 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);
     }
 
@@ -327,11 +344,11 @@ static void do_read(struct pa_pstream *p) {
     assert(p);
 
     if (p->read.index < PA_PSTREAM_DESCRIPTOR_SIZE) {
-        d = (void*) p->read.descriptor + p->read.index;
+        d = (uint8_t*) p->read.descriptor + p->read.index;
         l = PA_PSTREAM_DESCRIPTOR_SIZE - p->read.index;
     } else {
         assert(p->read.data);
-        d = (void*) p->read.data + p->read.index - PA_PSTREAM_DESCRIPTOR_SIZE;
+        d = (uint8_t*) 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);
     }
 
@@ -345,7 +362,7 @@ static void do_read(struct pa_pstream *p) {
 
         /* Frame size too large */
         if (ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH]) > FRAME_SIZE_MAX) {
-            fprintf(stderr, "frame size too large\n");
+            pa_log(__FILE__": Frame size too large\n");
             goto die;
         }