[pulseaudio-commits] r1647 - in /branches/lennart/src/pulsecore: play-memblockq.c play-memblockq.h

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Sat Aug 11 16:45:16 PDT 2007


Author: lennart
Date: Sun Aug 12 01:45:13 2007
New Revision: 1647

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1647&root=3Dpulseaudio&vi=
ew=3Drev
Log:
modernize pa_play_memblockq() and add a new function pa_memblockq_sink_inpu=
t_new() which allows creation of memblockq streams without activating them =
immediately

Modified:
    branches/lennart/src/pulsecore/play-memblockq.c
    branches/lennart/src/pulsecore/play-memblockq.h

Modified: branches/lennart/src/pulsecore/play-memblockq.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
play-memblockq.c?rev=3D1647&root=3Dpulseaudio&r1=3D1646&r2=3D1647&view=3Ddi=
ff
=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/play-memblockq.c (original)
+++ branches/lennart/src/pulsecore/play-memblockq.c Sun Aug 12 01:45:13 2007
@@ -26,7 +26,6 @@
 #endif
 =

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

@@ -34,50 +33,171 @@
 =

 #include <pulsecore/sink-input.h>
 #include <pulsecore/gccmacro.h>
+#include <pulsecore/thread-mq.h>
 =

 #include "play-memblockq.h"
 =

+typedef struct memblockq_stream {
+    pa_msgobject parent;
+    pa_core *core;
+    pa_sink_input *sink_input;
+    pa_memblockq *memblockq;
+} memblockq_stream;
+
+enum {
+    MEMBLOCKQ_STREAM_MESSAGE_UNLINK,
+};
+
+PA_DECLARE_CLASS(memblockq_stream);
+#define MEMBLOCKQ_STREAM(o) (memblockq_stream_cast(o))
+static PA_DEFINE_CHECK_TYPE(memblockq_stream, pa_msgobject);
+
+static void memblockq_stream_unlink(memblockq_stream *u) {
+    pa_assert(u);
+
+    if (!u->sink_input)
+        return;
+
+    pa_sink_input_disconnect(u->sink_input);
+    =

+    pa_sink_input_unref(u->sink_input);
+    u->sink_input =3D NULL;
+    =

+    memblockq_stream_unref(u);
+}
+
+static void memblockq_stream_free(pa_object *o) {
+    memblockq_stream *u =3D MEMBLOCKQ_STREAM(o);
+    pa_assert(u);
+
+    memblockq_stream_unlink(u);
+    =

+    if (u->memblockq)
+        pa_memblockq_free(u->memblockq);
+
+    pa_xfree(u);
+}
+
+static int memblockq_stream_process_msg(pa_msgobject *o, int code, void*us=
erdata, int64_t offset, pa_memchunk *chunk) {
+    memblockq_stream *u =3D MEMBLOCKQ_STREAM(o);
+    memblockq_stream_assert_ref(u);
+    =

+    switch (code) {
+        case MEMBLOCKQ_STREAM_MESSAGE_UNLINK:
+            memblockq_stream_unlink(u);
+            break;
+    }
+
+    return 0;
+}
+
 static void sink_input_kill_cb(pa_sink_input *i) {
-    pa_memblockq *q;
-    assert(i);
-    assert(i->userdata);
-
-    q =3D i->userdata;
-
-    pa_sink_input_disconnect(i);
-    pa_sink_input_unref(i);
-
-    pa_memblockq_free(q);
+    pa_sink_input_assert_ref(i);
+
+    memblockq_stream_unlink(MEMBLOCKQ_STREAM(i->userdata));
 }
 =

 static int sink_input_peek_cb(pa_sink_input *i, pa_memchunk *chunk) {
-    pa_memblockq *q;
-    assert(i);
-    assert(chunk);
-    assert(i->userdata);
-
-    q =3D i->userdata;
-
-    return pa_memblockq_peek(q, chunk);
-}
-
-static void si_kill_cb(PA_GCC_UNUSED pa_mainloop_api *m, void *i) {
-    sink_input_kill_cb(i);
+    memblockq_stream *u;
+
+    pa_assert(i);
+    pa_assert(chunk);
+    u =3D MEMBLOCKQ_STREAM(i->userdata);
+    memblockq_stream_assert_ref(u);
+
+    if (!u->memblockq)
+        return -1;
+
+    if (pa_memblockq_peek(u->memblockq, chunk) < 0) {
+        pa_memblockq_free(u->memblockq);
+        u->memblockq =3D NULL;
+        pa_asyncmsgq_post(pa_thread_mq_get()->outq, PA_MSGOBJECT(u), MEMBL=
OCKQ_STREAM_MESSAGE_UNLINK, NULL, 0, NULL, NULL);
+        return -1;
+    }
+
+    return 0;
 }
 =

 static void sink_input_drop_cb(pa_sink_input *i, size_t length) {
-    pa_memblockq *q;
-
-    assert(i);
-    assert(length > 0);
-    assert( i->userdata);
-
-    q =3D i->userdata;
-
-    pa_memblockq_drop(q, length);
-
-    if (pa_memblockq_get_length(q) <=3D 0)
-        pa_mainloop_api_once(i->sink->core->mainloop, si_kill_cb, i);
+    memblockq_stream *u;
+
+    pa_assert(i);
+    pa_assert(length > 0);
+    u =3D MEMBLOCKQ_STREAM(i->userdata);
+    memblockq_stream_assert_ref(u);
+
+    if (!u->memblockq)
+        return;
+    =

+    pa_memblockq_drop(u->memblockq, length);
+}
+
+pa_sink_input* pa_memblockq_sink_input_new(
+        pa_sink *sink,
+        const char *name,
+        const pa_sample_spec *ss,
+        const pa_channel_map *map,
+        pa_memblockq *q,
+        pa_cvolume *volume) {
+
+    memblockq_stream *u =3D NULL;
+    pa_sink_input_new_data data;
+
+    pa_assert(sink);
+    pa_assert(ss);
+
+    /* We allow creating this stream with no q set, so that it can be
+     * filled in later */
+
+    if (q && pa_memblockq_get_length(q) <=3D 0) {
+        pa_memblockq_free(q);
+        return NULL;
+    }
+
+    if (volume && pa_cvolume_is_muted(volume)) {
+        pa_memblockq_free(q);
+        return NULL;
+    }
+
+    u =3D pa_msgobject_new(memblockq_stream);
+    u->parent.parent.free =3D memblockq_stream_free;
+    u->parent.process_msg =3D memblockq_stream_process_msg;
+    u->core =3D sink->core;
+    u->sink_input =3D NULL;
+    u->memblockq =3D q;
+
+    pa_sink_input_new_data_init(&data);
+    data.sink =3D sink;
+    data.name =3D name;
+    data.driver =3D __FILE__;
+    pa_sink_input_new_data_set_sample_spec(&data, ss);
+    pa_sink_input_new_data_set_channel_map(&data, map);
+    pa_sink_input_new_data_set_volume(&data, volume);
+
+    if (!(u->sink_input =3D pa_sink_input_new(sink->core, &data, 0)))
+        goto fail;
+    =

+    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;
+
+    if (q)
+        pa_memblockq_prebuf_disable(q);
+    =

+    /* The reference to u is dangling here, because we want
+     * to keep this stream around until it is fully played. */
+
+    /* This sink input is not "put" yet, i.e. pa_sink_input_put() has
+     * not been called! */
+    =

+    return pa_sink_input_ref(u->sink_input);
+
+fail:
+    if (u)
+        memblockq_stream_unref(u);
+
+    return NULL;
 }
 =

 int pa_play_memblockq(
@@ -88,39 +208,29 @@
         pa_memblockq *q,
         pa_cvolume *volume) {
 =

-    pa_sink_input *si;
-    pa_sink_input_new_data data;
-
-    assert(sink);
-    assert(ss);
-    assert(q);
-
-    if (pa_memblockq_get_length(q) <=3D 0) {
-        pa_memblockq_free(q);
-        return 0;
-    }
-
-    if (volume && pa_cvolume_is_muted(volume)) {
-        pa_memblockq_free(q);
-        return 0;
-    }
-
-    pa_sink_input_new_data_init(&data);
-    data.sink =3D sink;
-    data.name =3D name;
-    data.driver =3D __FILE__;
-    pa_sink_input_new_data_set_channel_map(&data, map);
-    pa_sink_input_new_data_set_sample_spec(&data, ss);
-    pa_sink_input_new_data_set_volume(&data, volume);
-
-    if (!(si =3D pa_sink_input_new(sink->core, &data, 0)))
+    pa_sink_input *i;
+
+    pa_assert(sink);
+    pa_assert(ss);
+    pa_assert(q);
+
+    if (!(i =3D pa_memblockq_sink_input_new(sink, name, ss, map, q, volume=
)))
         return -1;
 =

-    si->peek =3D sink_input_peek_cb;
-    si->drop =3D sink_input_drop_cb;
-    si->kill =3D sink_input_kill_cb;
-
-    si->userdata =3D q;
+    pa_sink_input_put(i);
+    pa_sink_input_unref(i);
 =

     return 0;
 }
+
+void pa_memblockq_sink_input_set_queue(pa_sink_input *i, pa_memblockq *q) {
+    memblockq_stream *u;
+    =

+    pa_sink_input_assert_ref(i);
+    u =3D MEMBLOCKQ_STREAM(i->userdata);
+    memblockq_stream_assert_ref(u);
+
+    if (u->memblockq)
+        pa_memblockq_free(u->memblockq);
+    u->memblockq =3D q;
+}

Modified: branches/lennart/src/pulsecore/play-memblockq.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
play-memblockq.h?rev=3D1647&root=3Dpulseaudio&r1=3D1646&r2=3D1647&view=3Ddi=
ff
=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/play-memblockq.h (original)
+++ branches/lennart/src/pulsecore/play-memblockq.h Sun Aug 12 01:45:13 2007
@@ -27,6 +27,16 @@
 #include <pulsecore/sink.h>
 #include <pulsecore/memblockq.h>
 =

+pa_sink_input* pa_memblockq_sink_input_new(
+        pa_sink *sink,
+        const char *name,
+        const pa_sample_spec *ss,
+        const pa_channel_map *map,
+        pa_memblockq *q,
+        pa_cvolume *volume);
+
+void pa_memblockq_sink_input_set_queue(pa_sink_input *i, pa_memblockq *q);
+
 int pa_play_memblockq(
     pa_sink *sink,
     const char *name,




More information about the pulseaudio-commits mailing list