[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, master, updated. v0.9.13-221-gf67066b

Lennart Poettering gitmailer-noreply at 0pointer.de
Mon Jan 12 10:50:05 PST 2009


This is an automated email from the git hooks/post-receive script. It was
generated because of a push to the "PulseAudio Sound Server" repository.

The master branch has been updated
      from  b6804eefea4697d594210502b19f8370771e2a22 (commit)

- Log -----------------------------------------------------------------
f67066b... Port sine modules to pa_memchunk_sine()
b8e6aae... add new API function pa_memchunk_sine()
949de81... Extend command name lookup tables to cover complete protocol
aff7243... Fix suspending of all sinks/sources
d94d39d... read base volume only in proto 15
b9e96e0... for record streams fill in the latency as the fragsize
947a828... fix version check
-----------------------------------------------------------------------

Summary of changes:
 src/modules/module-sine-source.c |   30 ++----------
 src/modules/module-sine.c        |   54 ++++++++--------------
 src/pulse/introspect.c           |    4 +-
 src/pulsecore/pdispatch.c        |   92 ++++++++++++++++++++++++++++++++++----
 src/pulsecore/protocol-native.c  |   10 +++-
 src/pulsecore/sample-util.c      |   34 ++++++++++++++
 src/pulsecore/sample-util.h      |    2 +
 src/utils/pacat.c                |    1 +
 8 files changed, 154 insertions(+), 73 deletions(-)

-----------------------------------------------------------------------

commit 947a8289432ef6e31f7ddd04b6351334a6ff7a63
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Jan 12 19:33:38 2009 +0100

    fix version check

diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index fa3e3f8..6cf5c46 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -2678,7 +2678,7 @@ static void sink_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_sin
         pa_tagstruct_put_usec(t, pa_sink_get_requested_latency(sink));
     }
 
-    if (c->version >= 14)
+    if (c->version >= 15)
         pa_tagstruct_put_volume(t, sink->base_volume);
 }
 
@@ -2712,7 +2712,7 @@ static void source_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_s
         pa_tagstruct_put_usec(t, pa_source_get_requested_latency(source));
     }
 
-    if (c->version >= 14)
+    if (c->version >= 15)
         pa_tagstruct_put_volume(t, source->base_volume);
 }
 

commit b9e96e00cf56d2bc979b986926c77df04db9f6ff
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Jan 12 19:34:12 2009 +0100

    for record streams fill in the latency as the fragsize

diff --git a/src/utils/pacat.c b/src/utils/pacat.c
index b1e0d1f..2d88e7f 100644
--- a/src/utils/pacat.c
+++ b/src/utils/pacat.c
@@ -278,6 +278,7 @@ static void context_state_callback(pa_context *c, void *userdata) {
                 buffer_attr.minreq = (uint32_t) process_time;
                 buffer_attr.maxlength = (uint32_t) -1;
                 buffer_attr.prebuf = (uint32_t) -1;
+                buffer_attr.fragsize = (uint32_t) latency;
                 flags |= PA_STREAM_ADJUST_LATENCY;
             }
 

commit d94d39d6350c8831925c69b01d752ee438367820
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Jan 12 19:44:08 2009 +0100

    read base volume only in proto 15

diff --git a/src/pulse/introspect.c b/src/pulse/introspect.c
index 5b905b7..8056a5a 100644
--- a/src/pulse/introspect.c
+++ b/src/pulse/introspect.c
@@ -172,7 +172,7 @@ static void context_get_sink_info_callback(pa_pdispatch *pd, uint32_t command, u
                 (o->context->version >= 13 &&
                  (pa_tagstruct_get_proplist(t, i.proplist) < 0 ||
                   pa_tagstruct_get_usec(t, &i.configured_latency) < 0)) ||
-                (o->context->version >= 14 &&
+                (o->context->version >= 15 &&
                  pa_tagstruct_get_volume(t, &i.base_volume) < 0)) {
 
                 pa_context_fail(o->context, PA_ERR_PROTOCOL);
@@ -296,7 +296,7 @@ static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command,
                 (o->context->version >= 13 &&
                  (pa_tagstruct_get_proplist(t, i.proplist) < 0 ||
                   pa_tagstruct_get_usec(t, &i.configured_latency) < 0)) ||
-                (o->context->version >= 14 &&
+                (o->context->version >= 15 &&
                  pa_tagstruct_get_volume(t, &i.base_volume) < 0)) {
 
                 pa_context_fail(o->context, PA_ERR_PROTOCOL);

commit aff72437a6d56739e8ea7a34c746999b8f852529
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Jan 12 19:44:21 2009 +0100

    Fix suspending of all sinks/sources
    
    pasuspender issues a SUSPEND_ALL requests for suspending all
    sinks/sources at once. This has been broken due to an ill-placed sanity
    checked.

diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index 6cf5c46..3c1e576 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -3968,7 +3968,7 @@ static void command_suspend(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa
     }
 
     CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
-    CHECK_VALIDITY(c->pstream, !name || pa_namereg_is_valid_name(name), tag, PA_ERR_INVALID);
+    CHECK_VALIDITY(c->pstream, !name || pa_namereg_is_valid_name(name) || *name == 0, tag, PA_ERR_INVALID);
     CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX || name, tag, PA_ERR_INVALID);
     CHECK_VALIDITY(c->pstream, idx == PA_INVALID_INDEX || !name, tag, PA_ERR_INVALID);
     CHECK_VALIDITY(c->pstream, !name || idx == PA_INVALID_INDEX, tag, PA_ERR_INVALID);
@@ -3977,6 +3977,8 @@ static void command_suspend(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa
 
         if (idx == PA_INVALID_INDEX && name && !*name) {
 
+            pa_log_debug("%s all sinks", b ? "Suspending" : "Resuming");
+
             if (pa_sink_suspend_all(c->protocol->core, b) < 0) {
                 pa_pstream_send_error(c->pstream, tag, PA_ERR_INVALID);
                 return;
@@ -4002,6 +4004,8 @@ static void command_suspend(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa
 
         if (idx == PA_INVALID_INDEX && name && !*name) {
 
+            pa_log_debug("%s all sources", b ? "Suspending" : "Resuming");
+
             if (pa_source_suspend_all(c->protocol->core, b) < 0) {
                 pa_pstream_send_error(c->pstream, tag, PA_ERR_INVALID);
                 return;

commit 949de8156efbab1a2fb103ec414eaf983d7fa1c0
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Jan 12 19:46:17 2009 +0100

    Extend command name lookup tables to cover complete protocol
    
    Makes it easier to debug things.

diff --git a/src/pulsecore/pdispatch.c b/src/pulsecore/pdispatch.c
index 00df0f7..a5b33d6 100644
--- a/src/pulsecore/pdispatch.c
+++ b/src/pulsecore/pdispatch.c
@@ -40,34 +40,35 @@
 
 #include "pdispatch.h"
 
-/*#define DEBUG_OPCODES */
+/* #define DEBUG_OPCODES */
 
 #ifdef DEBUG_OPCODES
 
 static const char *command_names[PA_COMMAND_MAX] = {
+    /* Generic commands */
     [PA_COMMAND_ERROR] = "ERROR",
     [PA_COMMAND_TIMEOUT] = "TIMEOUT",
     [PA_COMMAND_REPLY] = "REPLY",
+
+    /* CLIENT->SERVER */
     [PA_COMMAND_CREATE_PLAYBACK_STREAM] = "CREATE_PLAYBACK_STREAM",
     [PA_COMMAND_DELETE_PLAYBACK_STREAM] = "DELETE_PLAYBACK_STREAM",
     [PA_COMMAND_CREATE_RECORD_STREAM] = "CREATE_RECORD_STREAM",
     [PA_COMMAND_DELETE_RECORD_STREAM] = "DELETE_RECORD_STREAM",
     [PA_COMMAND_AUTH] = "AUTH",
-    [PA_COMMAND_REQUEST] = "REQUEST",
     [PA_COMMAND_EXIT] = "EXIT",
     [PA_COMMAND_SET_CLIENT_NAME] = "SET_CLIENT_NAME",
     [PA_COMMAND_LOOKUP_SINK] = "LOOKUP_SINK",
     [PA_COMMAND_LOOKUP_SOURCE] = "LOOKUP_SOURCE",
     [PA_COMMAND_DRAIN_PLAYBACK_STREAM] = "DRAIN_PLAYBACK_STREAM",
-    [PA_COMMAND_PLAYBACK_STREAM_KILLED] = "PLAYBACK_STREAM_KILLED",
-    [PA_COMMAND_RECORD_STREAM_KILLED] = "RECORD_STREAM_KILLED",
     [PA_COMMAND_STAT] = "STAT",
-    [PA_COMMAND_GET_PLAYBACK_LATENCY] = "PLAYBACK_LATENCY",
+    [PA_COMMAND_GET_PLAYBACK_LATENCY] = "GET_PLAYBACK_LATENCY",
     [PA_COMMAND_CREATE_UPLOAD_STREAM] = "CREATE_UPLOAD_STREAM",
     [PA_COMMAND_DELETE_UPLOAD_STREAM] = "DELETE_UPLOAD_STREAM",
     [PA_COMMAND_FINISH_UPLOAD_STREAM] = "FINISH_UPLOAD_STREAM",
     [PA_COMMAND_PLAY_SAMPLE] = "PLAY_SAMPLE",
     [PA_COMMAND_REMOVE_SAMPLE] = "REMOVE_SAMPLE",
+
     [PA_COMMAND_GET_SERVER_INFO] = "GET_SERVER_INFO",
     [PA_COMMAND_GET_SINK_INFO] = "GET_SINK_INFO",
     [PA_COMMAND_GET_SINK_INFO_LIST] = "GET_SINK_INFO_LIST",
@@ -84,15 +85,87 @@ static const char *command_names[PA_COMMAND_MAX] = {
     [PA_COMMAND_GET_SOURCE_OUTPUT_INFO] = "GET_SOURCE_OUTPUT_INFO",
     [PA_COMMAND_GET_SOURCE_OUTPUT_INFO_LIST] = "GET_SOURCE_OUTPUT_INFO_LIST",
     [PA_COMMAND_SUBSCRIBE] = "SUBSCRIBE",
-    [PA_COMMAND_SUBSCRIBE_EVENT] = "SUBSCRIBE_EVENT",
+
     [PA_COMMAND_SET_SINK_VOLUME] = "SET_SINK_VOLUME",
     [PA_COMMAND_SET_SINK_INPUT_VOLUME] = "SET_SINK_INPUT_VOLUME",
     [PA_COMMAND_SET_SOURCE_VOLUME] = "SET_SOURCE_VOLME",
+
+    [PA_COMMAND_SET_SINK_MUTE] = "SET_SINK_MUTE",
+    [PA_COMMAND_SET_SOURCE_MUTE] = "SET_SOURCE_MUTE",
+
     [PA_COMMAND_TRIGGER_PLAYBACK_STREAM] = "TRIGGER_PLAYBACK_STREAM",
     [PA_COMMAND_FLUSH_PLAYBACK_STREAM] = "FLUSH_PLAYBACK_STREAM",
     [PA_COMMAND_CORK_PLAYBACK_STREAM] = "CORK_PLAYBACK_STREAM",
+
+    [PA_COMMAND_SET_DEFAULT_SINK] = "SET_DEFAULT_SINK",
+    [PA_COMMAND_SET_DEFAULT_SOURCE] = "SET_DEFAULT_SOURCE",
+
+    [PA_COMMAND_SET_PLAYBACK_STREAM_NAME] = "SET_PLAYBACK_STREAM_NAME",
+    [PA_COMMAND_SET_RECORD_STREAM_NAME] = "SET_RECORD_STREAM_NAME",
+
+    [PA_COMMAND_KILL_CLIENT] = "KILL_CLIENT",
+    [PA_COMMAND_KILL_SINK_INPUT] = "KILL_SINK_INPUT",
+    [PA_COMMAND_KILL_SOURCE_OUTPUT] = "SOURCE_OUTPUT",
+
+    [PA_COMMAND_LOAD_MODULE] = "LOAD_MODULE",
+    [PA_COMMAND_UNLOAD_MODULE] = "UNLOAD_MODULE",
+
+    [PA_COMMAND_ADD_AUTOLOAD] = "ADD_AUTOLOAD",
+    [PA_COMMAND_REMOVE_AUTOLOAD] = "REMOVE_AUTOLOAD",
     [PA_COMMAND_GET_AUTOLOAD_INFO] = "GET_AUTOLOAD_INFO",
     [PA_COMMAND_GET_AUTOLOAD_INFO_LIST] = "GET_AUTOLOAD_INFO_LIST",
+
+    [PA_COMMAND_GET_RECORD_LATENCY] = "GET_RECORD_LATENCY",
+    [PA_COMMAND_CORK_RECORD_STREAM] = "CORK_RECORD_STREAM",
+    [PA_COMMAND_FLUSH_RECORD_STREAM] = "FLUSH_RECORD_STREAM",
+    [PA_COMMAND_PREBUF_PLAYBACK_STREAM] = "PREBUF_PLAYBACK_STREAM",
+
+    /* SERVER->CLIENT */
+    [PA_COMMAND_REQUEST] = "REQUEST",
+    [PA_COMMAND_OVERFLOW] = "OVERFLOW",
+    [PA_COMMAND_UNDERFLOW] = "UNDERFLOW",
+    [PA_COMMAND_PLAYBACK_STREAM_KILLED] = "PLAYBACK_STREAM_KILLED",
+    [PA_COMMAND_RECORD_STREAM_KILLED] = "RECORD_STREAM_KILLED",
+    [PA_COMMAND_SUBSCRIBE_EVENT] = "SUBSCRIBE_EVENT",
+
+    /* A few more client->server commands */
+
+    /* Supported since protocol v10 (0.9.5) */
+    [PA_COMMAND_MOVE_SINK_INPUT] = "MOVE_SINK_INPUT",
+    [PA_COMMAND_MOVE_SOURCE_OUTPUT] = "MOVE_SOURCE_OUTPUT",
+
+    /* Supported since protocol v11 (0.9.7) */
+    [PA_COMMAND_SET_SINK_INPUT_MUTE] = "SET_SINK_INPUT_MUTE",
+
+    [PA_COMMAND_SUSPEND_SINK] = "SUSPEND_SINK",
+    [PA_COMMAND_SUSPEND_SOURCE] = "SUSPEND_SOURCE",
+
+    /* Supported since protocol v12 (0.9.8) */
+    [PA_COMMAND_SET_PLAYBACK_STREAM_BUFFER_ATTR] = "SET_PLAYBACK_STREAM_BUFFER_ATTR",
+    [PA_COMMAND_SET_RECORD_STREAM_BUFFER_ATTR] = "SET_RECORD_STREAM_BUFFER_ATTR",
+
+    [PA_COMMAND_UPDATE_PLAYBACK_STREAM_SAMPLE_RATE] = "UPDATE_PLAYBACK_STREAM_SAMPLE_RATE",
+    [PA_COMMAND_UPDATE_RECORD_STREAM_SAMPLE_RATE] = "UPDATE_RECORD_STREAM_SAMPLE_RATE",
+
+    /* SERVER->CLIENT */
+    [PA_COMMAND_PLAYBACK_STREAM_SUSPENDED] = "PLAYBACK_STREAM_SUSPENDED",
+    [PA_COMMAND_RECORD_STREAM_SUSPENDED] = "RECORD_STREAM_SUSPENDED",
+    [PA_COMMAND_PLAYBACK_STREAM_MOVED] = "PLAYBACK_STREAM_MOVED",
+    [PA_COMMAND_RECORD_STREAM_MOVED] = "RECORD_STREAM_MOVED",
+
+    /* Supported since protocol v13 (0.9.11) */
+    [PA_COMMAND_UPDATE_RECORD_STREAM_PROPLIST] = "UPDATE_RECORD_STREAM_PROPLIST",
+    [PA_COMMAND_UPDATE_PLAYBACK_STREAM_PROPLIST] = "UPDATE_RECORD_STREAM_PROPLIST",
+    [PA_COMMAND_UPDATE_CLIENT_PROPLIST] = "UPDATE_CLIENT_PROPLIST",
+    [PA_COMMAND_REMOVE_RECORD_STREAM_PROPLIST] = "REMOVE_RECORD_STREAM_PROPLIST",
+    [PA_COMMAND_REMOVE_PLAYBACK_STREAM_PROPLIST] = "REMOVE_PLAYBACK_STREAM_PROPLIST",
+    [PA_COMMAND_REMOVE_CLIENT_PROPLIST] = "REMOVE_CLIENT_PROPLIST",
+
+    /* SERVER->CLIENT */
+    [PA_COMMAND_STARTED] = "STARTED",
+
+    /* Supported since protocol v14 (0.9.12) */
+    [PA_COMMAND_EXTENSION] = "EXTENSION"
 };
 
 #endif
@@ -213,11 +286,12 @@ int pa_pdispatch_run(pa_pdispatch *pd, pa_packet*packet, const pa_creds *creds,
 #ifdef DEBUG_OPCODES
 {
     char t[256];
-    char const *p;
-    if (!(p = command_names[command]))
+    char const *p = NULL;
+
+    if (command >= PA_COMMAND_MAX || !(p = command_names[command]))
         pa_snprintf((char*) (p = t), sizeof(t), "%u", command);
 
-    pa_log("Recieved opcode <%s>", p);
+    pa_log("[%p] Recieved opcode <%s>", pd, p);
 }
 #endif
 

commit b8e6aae08ee21d839ce8ebac6505a78c5ddcd8f5
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Jan 12 19:48:44 2009 +0100

    add new API function pa_memchunk_sine()
    
    Ease generation of sine signals. Try to make the repeatable sine
    memblock fit into a single mempool slot.

diff --git a/src/pulsecore/sample-util.c b/src/pulsecore/sample-util.c
index bce3092..3be08ef 100644
--- a/src/pulsecore/sample-util.c
+++ b/src/pulsecore/sample-util.c
@@ -39,6 +39,7 @@
 #include <pulsecore/core-error.h>
 #include <pulsecore/macro.h>
 #include <pulsecore/g711.h>
+#include <pulsecore/core-util.h>
 
 #include "sample-util.h"
 #include "endianmacros.h"
@@ -1015,3 +1016,36 @@ void pa_memchunk_dump_to_file(pa_memchunk *c, const char *fn) {
 
     fclose(f);
 }
+
+static void calc_sine(float *f, size_t l, double freq) {
+    size_t i;
+
+    l /= sizeof(float);
+
+    for (i = 0; i < l; i++)
+        *(f++) = (float) 0.5f * sin((double) i*M_PI*2*freq / (double) l);
+}
+
+void pa_memchunk_sine(pa_memchunk *c, pa_mempool *pool, unsigned rate, unsigned freq) {
+    size_t l;
+    unsigned gcd, n;
+    void *p;
+
+    pa_memchunk_reset(c);
+
+    gcd = pa_gcd(rate, freq);
+    n = rate / gcd;
+
+    l = pa_mempool_block_size_max(pool) / sizeof(float);
+
+    l /= n;
+    if (l <= 0) l = 1;
+    l *= n;
+
+    c->length = l * sizeof(float);
+    c->memblock = pa_memblock_new(pool, c->length);
+
+    p = pa_memblock_acquire(c->memblock);
+    calc_sine(p, c->length, freq * l / rate);
+    pa_memblock_release(c->memblock);
+}
diff --git a/src/pulsecore/sample-util.h b/src/pulsecore/sample-util.h
index 36d19e4..2230aaf 100644
--- a/src/pulsecore/sample-util.h
+++ b/src/pulsecore/sample-util.h
@@ -83,4 +83,6 @@ size_t pa_usec_to_bytes_round_up(pa_usec_t t, const pa_sample_spec *spec);
 
 void pa_memchunk_dump_to_file(pa_memchunk *c, const char *fn);
 
+void pa_memchunk_sine(pa_memchunk *c, pa_mempool *pool, unsigned rate, unsigned freq);
+
 #endif

commit f67066b36237f0095d9fbdaf6111b7428465f7a4
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Jan 12 19:49:50 2009 +0100

    Port sine modules to pa_memchunk_sine()

diff --git a/src/modules/module-sine-source.c b/src/modules/module-sine-source.c
index 358514a..be95cc3 100644
--- a/src/modules/module-sine-source.c
+++ b/src/modules/module-sine-source.c
@@ -141,11 +141,11 @@ static void process_render(struct userdata *u, pa_usec_t now) {
 
         k = pa_usec_to_bytes_round_up(now + u->block_usec - u->timestamp, &u->source->sample_spec);
 
-        chunk.memblock = u->memchunk.memblock;
-        chunk.index = u->peek_index;
-        chunk.length = PA_MIN(u->memchunk.length - u->peek_index, k);
+        chunk = u->memchunk;
+        chunk.index += u->peek_index;
+        chunk.length = PA_MIN(chunk.length - u->peek_index, k);
 
-        pa_log_debug("posting %lu", (unsigned long) chunk.length);
+/*         pa_log_debug("posting %lu", (unsigned long) chunk.length); */
         pa_source_post(u->source, &chunk);
 
         u->peek_index += chunk.length;
@@ -216,9 +216,6 @@ int pa__init(pa_module*m) {
     pa_source_new_data data;
     uint32_t frequency;
     pa_sample_spec ss;
-    void *p;
-    unsigned n, d;
-    size_t l;
 
     pa_assert(m);
 
@@ -249,24 +246,7 @@ int pa__init(pa_module*m) {
     pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll);
 
     u->peek_index = 0;
-    pa_memchunk_reset(&u->memchunk);
-
-    n = ss.rate;
-    d = frequency;
-    pa_reduce(&n, &d);
-
-    l = pa_mempool_block_size_max(m->core->mempool) / pa_frame_size(&ss);
-
-    l /= n;
-    if (l <= 0) l = 1;
-    l *= n;
-
-    u->memchunk.length = l * pa_frame_size(&ss);
-    u->memchunk.memblock = pa_memblock_new(m->core->mempool, u->memchunk.length);
-
-    p = pa_memblock_acquire(u->memchunk.memblock);
-    calc_sine(p, u->memchunk.length, pa_bytes_to_usec(u->memchunk.length, &ss) * frequency / PA_USEC_PER_SEC);
-    pa_memblock_release(u->memchunk.memblock);
+    pa_memchunk_sine(&u->memchunk, m->core->mempool, ss.rate, frequency);
 
     pa_source_new_data_init(&data);
     data.driver = __FILE__;
diff --git a/src/modules/module-sine.c b/src/modules/module-sine.c
index 4ee4688..3b0dc35 100644
--- a/src/modules/module-sine.c
+++ b/src/modules/module-sine.c
@@ -49,7 +49,7 @@ struct userdata {
     pa_core *core;
     pa_module *module;
     pa_sink_input *sink_input;
-    pa_memblock *memblock;
+    pa_memchunk memchunk;
     size_t peek_index;
 };
 
@@ -66,9 +66,11 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk
     pa_assert_se(u = i->userdata);
     pa_assert(chunk);
 
-    chunk->memblock = pa_memblock_ref(u->memblock);
-    chunk->length = pa_memblock_get_length(u->memblock) - u->peek_index;
-    chunk->index = u->peek_index;
+    *chunk = u->memchunk;
+    pa_memblock_ref(chunk->memblock);
+
+    chunk->index += u->peek_index;
+    chunk->length -= u->peek_index;
 
     u->peek_index = 0;
 
@@ -76,19 +78,17 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk
 }
 
 static void sink_input_process_rewind_cb(pa_sink_input *i, size_t nbytes) {
-    size_t l;
     struct userdata *u;
 
     pa_sink_input_assert_ref(i);
     pa_assert_se(u = i->userdata);
 
-    l = pa_memblock_get_length(u->memblock);
-    nbytes %= l;
+    nbytes %= u->memchunk.length;
 
     if (u->peek_index >= nbytes)
         u->peek_index -= nbytes;
     else
-        u->peek_index = l + u->peek_index - nbytes;
+        u->peek_index = u->memchunk.length + u->peek_index - nbytes;
 }
 
 static void sink_input_kill_cb(pa_sink_input *i) {
@@ -118,22 +118,12 @@ static void sink_input_state_change_cb(pa_sink_input *i, pa_sink_input_state_t s
         pa_sink_input_request_rewind(i, 0, FALSE, TRUE);
 }
 
-static void calc_sine(float *f, size_t l, double freq) {
-    size_t i;
-
-    l /= sizeof(float);
-
-    for (i = 0; i < l; i++)
-        f[i] = (float) sin((double) i/(double)l*M_PI*2*freq)/2;
-}
-
 int pa__init(pa_module*m) {
     pa_modargs *ma = NULL;
     struct userdata *u;
     pa_sink *sink;
     pa_sample_spec ss;
     uint32_t frequency;
-    void *p;
     pa_sink_input_new_data data;
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
@@ -141,14 +131,7 @@ int pa__init(pa_module*m) {
         goto fail;
     }
 
-    m->userdata = u = pa_xnew0(struct userdata, 1);
-    u->core = m->core;
-    u->module = m;
-    u->sink_input = NULL;
-    u->memblock = NULL;
-    u->peek_index = 0;
-
-    if (!(sink = pa_namereg_get(m->core, pa_modargs_get_value(ma, "sink", NULL), PA_NAMEREG_SINK, 1))) {
+    if (!(sink = pa_namereg_get(m->core, pa_modargs_get_value(ma, "sink", NULL), PA_NAMEREG_SINK, TRUE))) {
         pa_log("No such sink.");
         goto fail;
     }
@@ -163,19 +146,22 @@ int pa__init(pa_module*m) {
         goto fail;
     }
 
-    u->memblock = pa_memblock_new(m->core->mempool, pa_bytes_per_second(&ss));
-    p = pa_memblock_acquire(u->memblock);
-    calc_sine(p, pa_memblock_get_length(u->memblock), (double) frequency);
-    pa_memblock_release(u->memblock);
+    m->userdata = u = pa_xnew0(struct userdata, 1);
+    u->core = m->core;
+    u->module = m;
+    u->sink_input = NULL;
+
+    u->peek_index = 0;
+    pa_memchunk_sine(&u->memchunk, m->core->mempool, ss.rate, frequency);
 
     pa_sink_input_new_data_init(&data);
-    data.sink = sink;
     data.driver = __FILE__;
+    data.module = m;
+    data.sink = sink;
     pa_proplist_setf(data.proplist, PA_PROP_MEDIA_NAME, "%u Hz Sine", frequency);
     pa_proplist_sets(data.proplist, PA_PROP_MEDIA_ROLE, "abstract");
     pa_proplist_setf(data.proplist, "sine.hz", "%u", frequency);
     pa_sink_input_new_data_set_sample_spec(&data, &ss);
-    data.module = m;
 
     u->sink_input = pa_sink_input_new(m->core, &data, 0);
     pa_sink_input_new_data_done(&data);
@@ -215,8 +201,8 @@ void pa__done(pa_module*m) {
         pa_sink_input_unref(u->sink_input);
     }
 
-    if (u->memblock)
-        pa_memblock_unref(u->memblock);
+    if (u->memchunk.memblock)
+        pa_memblock_unref(u->memchunk.memblock);
 
     pa_xfree(u);
 }

-- 
hooks/post-receive
PulseAudio Sound Server



More information about the pulseaudio-commits mailing list