[pulseaudio-commits] r1517 - /branches/lennart/src/modules/module-sine.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Fri Jul 13 05:14:31 PDT 2007


Author: lennart
Date: Fri Jul 13 14:14:30 2007
New Revision: 1517

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1517&root=3Dpulseaudio&vi=
ew=3Drev
Log:
Port module-sine to the new lock-free core

Modified:
    branches/lennart/src/modules/module-sine.c

Modified: branches/lennart/src/modules/module-sine.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/modules/mo=
dule-sine.c?rev=3D1517&root=3Dpulseaudio&r1=3D1516&r2=3D1517&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/modules/module-sine.c (original)
+++ branches/lennart/src/modules/module-sine.c Fri Jul 13 14:14:30 2007
@@ -58,34 +58,42 @@
     NULL,
 };
 =

-static int sink_input_peek(pa_sink_input *i, pa_memchunk *chunk) {
-    struct userdata *u;
-    assert(i && chunk && i->userdata);
+static int sink_input_peek_cb(pa_sink_input *i, pa_memchunk *chunk) {
+    struct userdata *u;
+    =

+    pa_assert(i);
     u =3D i->userdata;
+    pa_assert(u);
+    pa_assert(chunk);
 =

     chunk->memblock =3D pa_memblock_ref(u->memblock);
     chunk->index =3D u->peek_index;
     chunk->length =3D pa_memblock_get_length(u->memblock) - u->peek_index;
+    =

     return 0;
 }
 =

-static void sink_input_drop(pa_sink_input *i, const pa_memchunk *chunk, si=
ze_t length) {
-    struct userdata *u;
-    assert(i && chunk && length && i->userdata);
+static void sink_input_drop_cb(pa_sink_input *i, const pa_memchunk *chunk,=
 size_t length) {
+    struct userdata *u;
+    size_t l;
+    =

+    pa_assert(i);
     u =3D i->userdata;
-
-    assert(chunk->memblock =3D=3D u->memblock);
-    assert(length <=3D pa_memblock_get_length(u->memblock)-u->peek_index);
+    pa_assert(u);
+    pa_assert(chunk);
+    pa_assert(length > 0);
 =

     u->peek_index +=3D length;
 =

-    if (u->peek_index >=3D pa_memblock_get_length(u->memblock))
-        u->peek_index =3D 0;
-}
-
-static void sink_input_kill(pa_sink_input *i) {
-    struct userdata *u;
-    assert(i && i->userdata);
+    l =3D pa_memblock_get_length(u->memblock);
+    =

+    while (u->peek_index >=3D l)
+        u->peek_index -=3D l;
+}
+
+static void sink_input_kill_cb(pa_sink_input *i) {
+    struct userdata *u;
+    pa_assert(i && i->userdata);
     u =3D i->userdata;
 =

     pa_sink_input_disconnect(u->sink_input);
@@ -108,7 +116,6 @@
     pa_modargs *ma =3D NULL;
     struct userdata *u;
     pa_sink *sink;
-    const char *sink_name;
     pa_sample_spec ss;
     uint32_t frequency;
     char t[256];
@@ -120,15 +127,14 @@
         goto fail;
     }
 =

-    m->userdata =3D u =3D pa_xmalloc(sizeof(struct userdata));
+    m->userdata =3D u =3D pa_xnew0(struct userdata, 1);
     u->core =3D c;
     u->module =3D m;
     u->sink_input =3D NULL;
     u->memblock =3D NULL;
-
-    sink_name =3D pa_modargs_get_value(ma, "sink", NULL);
-
-    if (!(sink =3D pa_namereg_get(c, sink_name, PA_NAMEREG_SINK, 1))) {
+    u->peek_index =3D 0;
+
+    if (!(sink =3D pa_namereg_get(c, pa_modargs_get_value(ma, "sink", NULL=
), PA_NAMEREG_SINK, 1))) {
         pa_log("No such sink.");
         goto fail;
     }
@@ -160,13 +166,13 @@
     if (!(u->sink_input =3D pa_sink_input_new(c, &data, 0)))
         goto fail;
 =

-    u->sink_input->peek =3D sink_input_peek;
-    u->sink_input->drop =3D sink_input_drop;
-    u->sink_input->kill =3D sink_input_kill;
+    u->sink_input->peek =3D sink_input_peek_cb;
+    u->sink_input->drop =3D sink_input_drop_cb;
+    u->sink_input->kill =3D sink_input_kill_cb;
     u->sink_input->userdata =3D u;
 =

-    u->peek_index =3D 0;
-
+    pa_sink_input_put(u->sink_input);
+    =

     pa_modargs_free(ma);
     return 0;
 =

@@ -179,10 +185,12 @@
 }
 =

 void pa__done(pa_core *c, pa_module*m) {
-    struct userdata *u =3D m->userdata;
-    assert(c && m);
-
-    if (!u)
+    struct userdata *u;
+    =

+    pa_assert(c);
+    pa_assert(m);
+
+    if (!(u =3D m->userdata))
         return;
 =

     if (u->sink_input) {
@@ -192,6 +200,7 @@
 =

     if (u->memblock)
         pa_memblock_unref(u->memblock);
+    =

     pa_xfree(u);
 }
 =





More information about the pulseaudio-commits mailing list