[pulseaudio-commits] r1572 - in /branches/lennart/src/pulsecore: pstream.c pstream.h

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Sat Aug 4 17:07:59 PDT 2007


Author: lennart
Date: Sun Aug  5 02:07:58 2007
New Revision: 1572

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1572&root=3Dpulseaudio&vi=
ew=3Drev
Log:
Modernize pstream.[ch], reintroduce defer event to make things actually work

Modified:
    branches/lennart/src/pulsecore/pstream.c
    branches/lennart/src/pulsecore/pstream.h

Modified: branches/lennart/src/pulsecore/pstream.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
pstream.c?rev=3D1572&root=3Dpulseaudio&r1=3D1571&r2=3D1572&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/pstream.c (original)
+++ branches/lennart/src/pulsecore/pstream.c Sun Aug  5 02:07:58 2007
@@ -28,7 +28,6 @@
 =

 #include <stdio.h>
 #include <stdlib.h>
-#include <assert.h>
 #include <unistd.h>
 =

 #ifdef HAVE_SYS_SOCKET_H
@@ -168,8 +167,8 @@
 static int do_read(pa_pstream *p);
 =

 static void do_something(pa_pstream *p) {
-    assert(p);
-    assert(PA_REFCNT_VALUE(p) > 0);
+    pa_assert(p);
+    pa_assert(PA_REFCNT_VALUE(p) > 0);
 =

     pa_pstream_ref(p);
 =

@@ -191,20 +190,31 @@
 =

 fail:
 =

-    p->dead =3D 1;
-
     if (p->die_callback)
         p->die_callback(p, p->die_callback_userdata);
 =

+    pa_pstream_unlink(p);
     pa_pstream_unref(p);
 }
 =

 static void io_callback(pa_iochannel*io, void *userdata) {
     pa_pstream *p =3D userdata;
 =

-    assert(p);
-    assert(p->io =3D=3D io);
-
+    pa_assert(p);
+    pa_assert(PA_REFCNT_VALUE(p) > 0);
+    pa_assert(p->io =3D=3D io);
+
+    do_something(p);
+}
+
+static void defer_callback(pa_mainloop_api *m, pa_defer_event *e, void*use=
rdata) {
+    pa_pstream *p =3D userdata;
+    =

+    pa_assert(p);
+    pa_assert(PA_REFCNT_VALUE(p) > 0);
+    pa_assert(p->defer_event =3D=3D e);
+    pa_assert(p->mainloop =3D=3D m);
+    =

     do_something(p);
 }
 =

@@ -213,9 +223,9 @@
 pa_pstream *pa_pstream_new(pa_mainloop_api *m, pa_iochannel *io, pa_mempoo=
l *pool) {
     pa_pstream *p;
 =

-    assert(m);
-    assert(io);
-    assert(pool);
+    pa_assert(m);
+    pa_assert(io);
+    pa_assert(pool);
 =

     p =3D pa_xnew(pa_pstream, 1);
     PA_REFCNT_INIT(p);
@@ -224,9 +234,11 @@
     p->dead =3D 0;
 =

     p->mainloop =3D m;
-
+    p->defer_event =3D m->defer_new(m, defer_callback, p);
+    m->defer_enable(p->defer_event, 0);
+    =

     p->send_queue =3D pa_queue_new();
-    assert(p->send_queue);
+    pa_assert(p->send_queue);
 =

     p->write.current =3D NULL;
     p->write.index =3D 0;
@@ -264,13 +276,13 @@
 =

 static void item_free(void *item, PA_GCC_UNUSED void *p) {
     struct item_info *i =3D item;
-    assert(i);
+    pa_assert(i);
 =

     if (i->type =3D=3D PA_PSTREAM_ITEM_MEMBLOCK) {
-        assert(i->chunk.memblock);
+        pa_assert(i->chunk.memblock);
         pa_memblock_unref(i->chunk.memblock);
     } else if (i->type =3D=3D PA_PSTREAM_ITEM_PACKET) {
-        assert(i->packet);
+        pa_assert(i->packet);
         pa_packet_unref(i->packet);
     }
 =

@@ -278,9 +290,9 @@
 }
 =

 static void pstream_free(pa_pstream *p) {
-    assert(p);
-
-    pa_pstream_close(p);
+    pa_assert(p);
+
+    pa_pstream_unlink(p);
 =

     pa_queue_free(p->send_queue, item_free, NULL);
 =

@@ -302,9 +314,9 @@
 void pa_pstream_send_packet(pa_pstream*p, pa_packet *packet, const pa_cred=
s *creds) {
     struct item_info *i;
 =

-    assert(p);
-    assert(PA_REFCNT_VALUE(p) > 0);
-    assert(packet);
+    pa_assert(p);
+    pa_assert(PA_REFCNT_VALUE(p) > 0);
+    pa_assert(packet);
 =

     if (p->dead)
         return;
@@ -319,15 +331,17 @@
 #endif
 =

     pa_queue_push(p->send_queue, i);
+
+    p->mainloop->defer_enable(p->defer_event, 1);
 }
 =

 void pa_pstream_send_memblock(pa_pstream*p, uint32_t channel, int64_t offs=
et, pa_seek_mode_t seek_mode, const pa_memchunk *chunk) {
     size_t length, idx;
 =

-    assert(p);
-    assert(PA_REFCNT_VALUE(p) > 0);
-    assert(channel !=3D (uint32_t) -1);
-    assert(chunk);
+    pa_assert(p);
+    pa_assert(PA_REFCNT_VALUE(p) > 0);
+    pa_assert(channel !=3D (uint32_t) -1);
+    pa_assert(chunk);
 =

     if (p->dead)
         return;
@@ -366,8 +380,8 @@
     struct item_info *item;
     pa_pstream *p =3D userdata;
 =

-    assert(p);
-    assert(PA_REFCNT_VALUE(p) > 0);
+    pa_assert(p);
+    pa_assert(PA_REFCNT_VALUE(p) > 0);
 =

     if (p->dead)
         return;
@@ -382,14 +396,15 @@
 #endif
 =

     pa_queue_push(p->send_queue, item);
+    p->mainloop->defer_enable(p->defer_event, 1);
 }
 =

 static void memexport_revoke_cb(pa_memexport *e, uint32_t block_id, void *=
userdata) {
     struct item_info *item;
     pa_pstream *p =3D userdata;
 =

-    assert(p);
-    assert(PA_REFCNT_VALUE(p) > 0);
+    pa_assert(p);
+    pa_assert(PA_REFCNT_VALUE(p) > 0);
 =

     if (p->dead)
         return;
@@ -403,11 +418,12 @@
 #endif
 =

     pa_queue_push(p->send_queue, item);
+    p->mainloop->defer_enable(p->defer_event, 1);
 }
 =

 static void prepare_next_write_item(pa_pstream *p) {
-    assert(p);
-    assert(PA_REFCNT_VALUE(p) > 0);
+    pa_assert(p);
+    pa_assert(PA_REFCNT_VALUE(p) > 0);
 =

     p->write.current =3D pa_queue_pop(p->send_queue);
 =

@@ -426,7 +442,7 @@
 =

     if (p->write.current->type =3D=3D PA_PSTREAM_ITEM_PACKET) {
 =

-        assert(p->write.current->packet);
+        pa_assert(p->write.current->packet);
         p->write.data =3D p->write.current->packet->data;
         p->write.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH] =3D htonl(p->wri=
te.current->packet->length);
 =

@@ -444,8 +460,8 @@
         uint32_t flags;
         int send_payload =3D 1;
 =

-        assert(p->write.current->type =3D=3D PA_PSTREAM_ITEM_MEMBLOCK);
-        assert(p->write.current->chunk.memblock);
+        pa_assert(p->write.current->type =3D=3D PA_PSTREAM_ITEM_MEMBLOCK);
+        pa_assert(p->write.current->chunk.memblock);
 =

         p->write.descriptor[PA_PSTREAM_DESCRIPTOR_CHANNEL] =3D htonl(p->wr=
ite.current->channel);
         p->write.descriptor[PA_PSTREAM_DESCRIPTOR_OFFSET_HI] =3D htonl((ui=
nt32_t) (((uint64_t) p->write.current->offset) >> 32));
@@ -457,7 +473,7 @@
             uint32_t block_id, shm_id;
             size_t offset, length;
 =

-            assert(p->export);
+            pa_assert(p->export);
 =

             if (pa_memexport_put(p->export,
                                  p->write.current->chunk.memblock,
@@ -503,8 +519,8 @@
     ssize_t r;
     pa_memblock *release_memblock =3D NULL;
 =

-    assert(p);
-    assert(PA_REFCNT_VALUE(p) > 0);
+    pa_assert(p);
+    pa_assert(PA_REFCNT_VALUE(p) > 0);
 =

     if (!p->write.current)
         prepare_next_write_item(p);
@@ -516,7 +532,7 @@
         d =3D (uint8_t*) p->write.descriptor + p->write.index;
         l =3D PA_PSTREAM_DESCRIPTOR_SIZE - p->write.index;
     } else {
-        assert(p->write.data || p->write.memchunk.memblock);
+        pa_assert(p->write.data || p->write.memchunk.memblock);
 =

         if (p->write.data)
             d =3D p->write.data;
@@ -529,7 +545,7 @@
         l =3D ntohl(p->write.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH]) - (=
p->write.index - PA_PSTREAM_DESCRIPTOR_SIZE);
     }
 =

-    assert(l > 0);
+    pa_assert(l > 0);
 =

 #ifdef HAVE_CREDS
     if (p->send_creds_now) {
@@ -550,7 +566,7 @@
     p->write.index +=3D r;
 =

     if (p->write.index >=3D PA_PSTREAM_DESCRIPTOR_SIZE + ntohl(p->write.de=
scriptor[PA_PSTREAM_DESCRIPTOR_LENGTH])) {
-        assert(p->write.current);
+        pa_assert(p->write.current);
         item_free(p->write.current, (void *) 1);
         p->write.current =3D NULL;
 =

@@ -573,14 +589,14 @@
     size_t l;
     ssize_t r;
     pa_memblock *release_memblock =3D NULL;
-    assert(p);
-    assert(PA_REFCNT_VALUE(p) > 0);
+    pa_assert(p);
+    pa_assert(PA_REFCNT_VALUE(p) > 0);
 =

     if (p->read.index < PA_PSTREAM_DESCRIPTOR_SIZE) {
         d =3D (uint8_t*) p->read.descriptor + p->read.index;
         l =3D PA_PSTREAM_DESCRIPTOR_SIZE - p->read.index;
     } else {
-        assert(p->read.data || p->read.memblock);
+        pa_assert(p->read.data || p->read.memblock);
 =

         if (p->read.data)
             d =3D p->read.data;
@@ -629,7 +645,7 @@
 =

 /*             pa_log("Got release frame for %u", ntohl(p->read.descriptor=
[PA_PSTREAM_DESCRIPTOR_OFFSET_HI])); */
 =

-            assert(p->export);
+            pa_assert(p->export);
             pa_memexport_process_release(p->export, ntohl(p->read.descript=
or[PA_PSTREAM_DESCRIPTOR_OFFSET_HI]));
 =

             goto frame_done;
@@ -640,7 +656,7 @@
 =

 /*             pa_log("Got revoke frame for %u", ntohl(p->read.descriptor[=
PA_PSTREAM_DESCRIPTOR_OFFSET_HI])); */
 =

-            assert(p->import);
+            pa_assert(p->import);
             pa_memimport_process_revoke(p->import, ntohl(p->read.descripto=
r[PA_PSTREAM_DESCRIPTOR_OFFSET_HI]));
 =

             goto frame_done;
@@ -653,7 +669,7 @@
             return -1;
         }
 =

-        assert(!p->read.packet && !p->read.memblock);
+        pa_assert(!p->read.packet && !p->read.memblock);
 =

         channel =3D ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_CHANNEL=
]);
 =

@@ -757,9 +773,9 @@
             } else {
                 pa_memblock *b;
 =

-                assert((ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_FLA=
GS]) & PA_FLAG_SHMMASK) =3D=3D PA_FLAG_SHMDATA);
-
-                assert(p->import);
+                pa_assert((ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_=
FLAGS]) & PA_FLAG_SHMMASK) =3D=3D PA_FLAG_SHMDATA);
+
+                pa_assert(p->import);
 =

                 if (!(b =3D pa_memimport_get(p->import,
                                           ntohl(p->read.shm_info[PA_PSTREA=
M_SHM_BLOCKID]),
@@ -821,32 +837,32 @@
 }
 =

 void pa_pstream_set_die_callback(pa_pstream *p, pa_pstream_notify_cb_t cb,=
 void *userdata) {
-    assert(p);
-    assert(PA_REFCNT_VALUE(p) > 0);
+    pa_assert(p);
+    pa_assert(PA_REFCNT_VALUE(p) > 0);
 =

     p->die_callback =3D cb;
     p->die_callback_userdata =3D userdata;
 }
 =

 void pa_pstream_set_drain_callback(pa_pstream *p, pa_pstream_notify_cb_t c=
b, void *userdata) {
-    assert(p);
-    assert(PA_REFCNT_VALUE(p) > 0);
+    pa_assert(p);
+    pa_assert(PA_REFCNT_VALUE(p) > 0);
 =

     p->drain_callback =3D cb;
     p->drain_callback_userdata =3D userdata;
 }
 =

 void pa_pstream_set_recieve_packet_callback(pa_pstream *p, pa_pstream_pack=
et_cb_t cb, void *userdata) {
-    assert(p);
-    assert(PA_REFCNT_VALUE(p) > 0);
+    pa_assert(p);
+    pa_assert(PA_REFCNT_VALUE(p) > 0);
 =

     p->recieve_packet_callback =3D cb;
     p->recieve_packet_callback_userdata =3D userdata;
 }
 =

 void pa_pstream_set_recieve_memblock_callback(pa_pstream *p, pa_pstream_me=
mblock_cb_t cb, void *userdata) {
-    assert(p);
-    assert(PA_REFCNT_VALUE(p) > 0);
+    pa_assert(p);
+    pa_assert(PA_REFCNT_VALUE(p) > 0);
 =

     p->recieve_memblock_callback =3D cb;
     p->recieve_memblock_callback_userdata =3D userdata;
@@ -855,8 +871,8 @@
 int pa_pstream_is_pending(pa_pstream *p) {
     int b;
 =

-    assert(p);
-    assert(PA_REFCNT_VALUE(p) > 0);
+    pa_assert(p);
+    pa_assert(PA_REFCNT_VALUE(p) > 0);
 =

     if (p->dead)
         b =3D 0;
@@ -867,24 +883,27 @@
 }
 =

 void pa_pstream_unref(pa_pstream*p) {
-    assert(p);
-    assert(PA_REFCNT_VALUE(p) > 0);
+    pa_assert(p);
+    pa_assert(PA_REFCNT_VALUE(p) > 0);
 =

     if (PA_REFCNT_DEC(p) <=3D 0)
         pstream_free(p);
 }
 =

 pa_pstream* pa_pstream_ref(pa_pstream*p) {
-    assert(p);
-    assert(PA_REFCNT_VALUE(p) > 0);
+    pa_assert(p);
+    pa_assert(PA_REFCNT_VALUE(p) > 0);
 =

     PA_REFCNT_INC(p);
     return p;
 }
 =

-void pa_pstream_close(pa_pstream *p) {
-    assert(p);
-
+void pa_pstream_unlink(pa_pstream *p) {
+    pa_assert(p);
+
+    if (p->dead)
+        return;
+    =

     p->dead =3D 1;
 =

     if (p->import) {
@@ -901,6 +920,11 @@
         pa_iochannel_free(p->io);
         p->io =3D NULL;
     }
+
+    if (p->defer_event) {
+        p->mainloop->defer_free(p->defer_event);
+        p->defer_event =3D NULL;
+    }    =

 =

     p->die_callback =3D NULL;
     p->drain_callback =3D NULL;
@@ -909,8 +933,8 @@
 }
 =

 void pa_pstream_use_shm(pa_pstream *p, int enable) {
-    assert(p);
-    assert(PA_REFCNT_VALUE(p) > 0);
+    pa_assert(p);
+    pa_assert(PA_REFCNT_VALUE(p) > 0);
 =

     p->use_shm =3D enable;
 =


Modified: branches/lennart/src/pulsecore/pstream.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
pstream.h?rev=3D1572&root=3Dpulseaudio&r1=3D1571&r2=3D1572&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/pstream.h (original)
+++ branches/lennart/src/pulsecore/pstream.h Sun Aug  5 02:07:58 2007
@@ -59,6 +59,6 @@
 =

 void pa_pstream_use_shm(pa_pstream *p, int enable);
 =

-void pa_pstream_close(pa_pstream *p);
+void pa_pstream_unlink(pa_pstream *p);
 =

 #endif




More information about the pulseaudio-commits mailing list