[pulseaudio-commits] r1833 - in /branches/lennart/src: modules/ pulsecore/

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Sun Sep 16 15:00:39 PDT 2007


Author: lennart
Date: Mon Sep 17 00:00:38 2007
New Revision: 1833

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1833&root=pulseaudio&view=rev
Log:
add a "length" argument to the seek functions, as an optimization to request a certain block size if any data needs to be generated. this is merely a hint.

Modified:
    branches/lennart/src/modules/module-combine.c
    branches/lennart/src/modules/module-sine.c
    branches/lennart/src/pulsecore/play-memblockq.c
    branches/lennart/src/pulsecore/play-memchunk.c
    branches/lennart/src/pulsecore/protocol-esound.c
    branches/lennart/src/pulsecore/protocol-native.c
    branches/lennart/src/pulsecore/protocol-simple.c
    branches/lennart/src/pulsecore/sink-input.c
    branches/lennart/src/pulsecore/sink-input.h
    branches/lennart/src/pulsecore/sink.c
    branches/lennart/src/pulsecore/sound-file-stream.c

Modified: branches/lennart/src/modules/module-combine.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/modules/module-combine.c?rev=1833&root=pulseaudio&r1=1832&r2=1833&view=diff
==============================================================================
--- branches/lennart/src/modules/module-combine.c (original)
+++ branches/lennart/src/modules/module-combine.c Mon Sep 17 00:00:38 2007
@@ -275,7 +275,7 @@
     pa_log_debug("Thread shutting down");
 }
 
-static void request_memblock(struct output *o) {
+static void request_memblock(struct output *o, size_t length) {
     pa_memchunk chunk;
     
     pa_assert(o);
@@ -306,7 +306,7 @@
             struct output *j;
             
             /* Do it! */
-            pa_sink_render(o->userdata->sink, o->userdata->block_size, &chunk);
+            pa_sink_render(o->userdata->sink, length, &chunk);
             
             /* OK, let's send this data to the other threads */
             for (j = o->userdata->thread_info.outputs; j; j = j->next)
@@ -323,7 +323,7 @@
 }
 
 /* Called from I/O thread context */
-static int sink_input_peek_cb(pa_sink_input *i, pa_memchunk *chunk) {
+static int sink_input_peek_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk) {
     struct output *o;
 
     pa_sink_input_assert_ref(i);
@@ -331,7 +331,7 @@
     pa_assert(o);
 
     /* If necessary, get some new data */
-    request_memblock(o);
+    request_memblock(o, length);
 
     return  pa_memblockq_peek(o->memblockq, chunk);
 }

Modified: branches/lennart/src/modules/module-sine.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/modules/module-sine.c?rev=1833&root=pulseaudio&r1=1832&r2=1833&view=diff
==============================================================================
--- branches/lennart/src/modules/module-sine.c (original)
+++ branches/lennart/src/modules/module-sine.c Mon Sep 17 00:00:38 2007
@@ -58,7 +58,7 @@
     NULL,
 };
 
-static int sink_input_peek_cb(pa_sink_input *i, pa_memchunk *chunk) {
+static int sink_input_peek_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk) {
     struct userdata *u;
     
     pa_assert(i);

Modified: branches/lennart/src/pulsecore/play-memblockq.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/play-memblockq.c?rev=1833&root=pulseaudio&r1=1832&r2=1833&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/play-memblockq.c (original)
+++ branches/lennart/src/pulsecore/play-memblockq.c Mon Sep 17 00:00:38 2007
@@ -97,7 +97,7 @@
     memblockq_stream_unlink(MEMBLOCKQ_STREAM(i->userdata));
 }
 
-static int sink_input_peek_cb(pa_sink_input *i, pa_memchunk *chunk) {
+static int sink_input_peek_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk) {
     memblockq_stream *u;
 
     pa_assert(i);

Modified: branches/lennart/src/pulsecore/play-memchunk.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/play-memchunk.c?rev=1833&root=pulseaudio&r1=1832&r2=1833&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/play-memchunk.c (original)
+++ branches/lennart/src/pulsecore/play-memchunk.c Mon Sep 17 00:00:38 2007
@@ -97,7 +97,7 @@
     memchunk_stream_unlink(MEMCHUNK_STREAM(i->userdata));
 }
 
-static int sink_input_peek_cb(pa_sink_input *i, pa_memchunk *chunk) {
+static int sink_input_peek_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk) {
     memchunk_stream *u;
 
     pa_assert(i);

Modified: branches/lennart/src/pulsecore/protocol-esound.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/protocol-esound.c?rev=1833&root=pulseaudio&r1=1832&r2=1833&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/protocol-esound.c (original)
+++ branches/lennart/src/pulsecore/protocol-esound.c Mon Sep 17 00:00:38 2007
@@ -150,7 +150,7 @@
 } esd_proto_handler_info_t;
 
 static void sink_input_drop_cb(pa_sink_input *i, size_t length);
-static int sink_input_peek_cb(pa_sink_input *i, pa_memchunk *chunk);
+static int sink_input_peek_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk);
 static void sink_input_kill_cb(pa_sink_input *i);
 static int sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offset, pa_memchunk *chunk);
 static pa_usec_t source_output_get_latency_cb(pa_source_output *o);
@@ -1237,7 +1237,7 @@
 }
 
 /* Called from thread context */
-static int sink_input_peek_cb(pa_sink_input *i, pa_memchunk *chunk) {
+static int sink_input_peek_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk) {
     connection*c;
     int r;
     

Modified: branches/lennart/src/pulsecore/protocol-native.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/protocol-native.c?rev=1833&root=pulseaudio&r1=1832&r2=1833&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/protocol-native.c (original)
+++ branches/lennart/src/pulsecore/protocol-native.c Mon Sep 17 00:00:38 2007
@@ -199,7 +199,7 @@
     CONNECTION_MESSAGE_REVOKE
 };
 
-static int sink_input_peek_cb(pa_sink_input *i, pa_memchunk *chunk);
+static int sink_input_peek_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk);
 static void sink_input_drop_cb(pa_sink_input *i, size_t length);
 static void sink_input_kill_cb(pa_sink_input *i);
 
@@ -973,7 +973,7 @@
 }
 
 /* Called from thread context */
-static int sink_input_peek_cb(pa_sink_input *i, pa_memchunk *chunk) {
+static int sink_input_peek_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk) {
     playback_stream *s;
 
     pa_sink_input_assert_ref(i);

Modified: branches/lennart/src/pulsecore/protocol-simple.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/protocol-simple.c?rev=1833&root=pulseaudio&r1=1832&r2=1833&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/protocol-simple.c (original)
+++ branches/lennart/src/pulsecore/protocol-simple.c Mon Sep 17 00:00:38 2007
@@ -343,7 +343,7 @@
 }
 
 /* Called from thread context */
-static int sink_input_peek_cb(pa_sink_input *i, pa_memchunk *chunk) {
+static int sink_input_peek_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk) {
     connection *c;
     int r;
 

Modified: branches/lennart/src/pulsecore/sink-input.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/sink-input.c?rev=1833&root=pulseaudio&r1=1832&r2=1833&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/sink-input.c (original)
+++ branches/lennart/src/pulsecore/sink-input.c Mon Sep 17 00:00:38 2007
@@ -41,9 +41,9 @@
 
 #include "sink-input.h"
 
-#define CONVERT_BUFFER_LENGTH 4096
-#define MOVE_BUFFER_LENGTH (1024*1024)
-#define SILENCE_BUFFER_LENGTH (64*1024)
+#define CONVERT_BUFFER_LENGTH (PA_PAGE_SIZE)
+#define SILENCE_BUFFER_LENGTH (PA_PAGE_SIZE*12)
+#define MOVE_BUFFER_LENGTH (PA_PAGE_SIZE*256)
 
 static PA_DEFINE_CHECK_TYPE(pa_sink_input, pa_msgobject);
 
@@ -368,13 +368,15 @@
 }
 
 /* Called from thread context */
-int pa_sink_input_peek(pa_sink_input *i, pa_memchunk *chunk, pa_cvolume *volume) {
+int pa_sink_input_peek(pa_sink_input *i, size_t length, pa_memchunk *chunk, pa_cvolume *volume) {
     int ret = -1;
     int do_volume_adj_here;
     int volume_is_norm;
+    size_t block_size_max;
 
     pa_sink_input_assert_ref(i);
     pa_assert(PA_SINK_INPUT_LINKED(i->thread_info.state));
+    pa_assert(pa_frame_aligned(length, &i->sink->sample_spec));
     pa_assert(chunk);
     pa_assert(volume);
 
@@ -383,6 +385,15 @@
 
     pa_assert(i->thread_info.state == PA_SINK_INPUT_RUNNING || i->thread_info.state == PA_SINK_INPUT_DRAINED);
 
+    /* Default buffer size */
+    if (length <= 0)
+        length = pa_frame_align(CONVERT_BUFFER_LENGTH, &i->sink->sample_spec);
+
+    /* Make sure the buffer fits in the mempool tile */
+    block_size_max = pa_mempool_block_size_max(i->sink->core->mempool);
+    if (length > block_size_max)
+        length = pa_frame_align(block_size_max, &i->sink->sample_spec);
+    
     if (i->thread_info.move_silence > 0) {
         size_t l;
 
@@ -390,7 +401,10 @@
          * while until the old sink has drained its playback buffer */
 
         if (!i->thread_info.silence_memblock)
-            i->thread_info.silence_memblock = pa_silence_memblock_new(i->sink->core->mempool, &i->sink->sample_spec, SILENCE_BUFFER_LENGTH);
+            i->thread_info.silence_memblock = pa_silence_memblock_new(
+                    i->sink->core->mempool,
+                    &i->sink->sample_spec,
+                    pa_frame_align(SILENCE_BUFFER_LENGTH, &i->sink->sample_spec));
 
         chunk->memblock = pa_memblock_ref(i->thread_info.silence_memblock);
         chunk->index = 0;
@@ -404,7 +418,7 @@
 
     if (!i->thread_info.resampler) {
         do_volume_adj_here = 0; /* FIXME??? */
-        ret = i->peek(i, chunk);
+        ret = i->peek(i, length, chunk);
         goto finish;
     }
 
@@ -413,14 +427,21 @@
 
     while (!i->thread_info.resampled_chunk.memblock) {
         pa_memchunk tchunk;
-        size_t l;
-
-        if ((ret = i->peek(i, &tchunk)) < 0)
+        size_t l, rmbs;
+
+        l = pa_resampler_request(i->thread_info.resampler, length);
+
+        if (l <= 0)
+            l = pa_frame_align(CONVERT_BUFFER_LENGTH, &i->sample_spec);
+
+        rmbs = pa_resampler_max_block_size(i->thread_info.resampler);
+        if (l > rmbs)
+            l = rmbs;
+        
+        if ((ret = i->peek(i, l, &tchunk)) < 0)
             goto finish;
 
         pa_assert(tchunk.length > 0);
-
-        l = pa_resampler_request(i->thread_info.resampler, CONVERT_BUFFER_LENGTH);
 
         if (tchunk.length > l)
             tchunk.length = l;
@@ -477,6 +498,7 @@
 void pa_sink_input_drop(pa_sink_input *i, size_t length) {
     pa_sink_input_assert_ref(i);
     pa_assert(PA_SINK_INPUT_LINKED(i->thread_info.state));
+    pa_assert(pa_frame_aligned(length, &i->sink->sample_spec));
     pa_assert(length > 0);
 
     if (i->thread_info.move_silence > 0) {
@@ -527,9 +549,9 @@
                 pa_memchunk chunk;
                 pa_cvolume volume;
                 
-                if (pa_sink_input_peek(i, &chunk, &volume) >= 0) {
+                if (pa_sink_input_peek(i, length, &chunk, &volume) >= 0) {
                     size_t l;
-
+                    
                     pa_memblock_unref(chunk.memblock);
 
                     l = chunk.length;
@@ -541,11 +563,13 @@
                     
                 } else {
                     size_t l;
-
+                    
+                    l = pa_resampler_request(i->thread_info.resampler, length);
+                    
                     /* Hmmm, peeking failed, so let's at least drop
                      * the right amount of data */
 
-                    if ((l = pa_resampler_request(i->thread_info.resampler, length)) > 0)
+                    if (l > 0)
                         if (i->drop)
                             i->drop(i, l);
                             
@@ -798,9 +822,9 @@
         i->thread_info.move_silence = 0;
     else
         i->thread_info.move_silence = pa_usec_to_bytes(
-                pa_bytes_to_usec(i->thread_info.move_silence, &i->sample_spec) +
+                pa_bytes_to_usec(i->thread_info.move_silence, &origin->sample_spec) +
                 silence_usec,
-                &i->sample_spec);
+                &dest->sample_spec);
 
     pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i->sink), PA_SINK_MESSAGE_ADD_INPUT, i, 0, NULL);
     

Modified: branches/lennart/src/pulsecore/sink-input.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/sink-input.h?rev=1833&root=pulseaudio&r1=1832&r2=1833&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/sink-input.h (original)
+++ branches/lennart/src/pulsecore/sink-input.h Mon Sep 17 00:00:38 2007
@@ -83,8 +83,12 @@
     int muted;
 
     /* Returns the chunk of audio data (but doesn't drop it
-     * yet!). Returns -1 on failure. Called from IO thread context. */
-    int (*peek) (pa_sink_input *i, pa_memchunk *chunk);
+     * yet!). Returns -1 on failure. Called from IO thread context. If
+     * data needs to be generated from scratch then please in the
+     * specified length. This is an optimization only. If less data is
+     * available, it's fine to return a smaller block. If more data is
+     * already ready, it is better to return the full block.*/
+    int (*peek) (pa_sink_input *i, size_t length, pa_memchunk *chunk);
 
     /* Drops the specified number of bytes, usually called right after
      * peek(), but not necessarily. Called from IO thread context. */
@@ -217,7 +221,7 @@
 
 /* To be used exclusively by the sink driver thread */
 
-int pa_sink_input_peek(pa_sink_input *i, pa_memchunk *chunk, pa_cvolume *volume);
+int pa_sink_input_peek(pa_sink_input *i, size_t length, pa_memchunk *chunk, pa_cvolume *volume);
 void pa_sink_input_drop(pa_sink_input *i, size_t length);
 int pa_sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offset, pa_memchunk *chunk);
 

Modified: branches/lennart/src/pulsecore/sink.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/sink.c?rev=1833&root=pulseaudio&r1=1832&r2=1833&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/sink.c (original)
+++ branches/lennart/src/pulsecore/sink.c Mon Sep 17 00:00:38 2007
@@ -46,7 +46,8 @@
 #include "sink.h"
 
 #define MAX_MIX_CHANNELS 32
-#define SILENCE_BUFFER_LENGTH (64*1024)
+#define MIX_BUFFER_LENGTH (PA_PAGE_SIZE)
+#define SILENCE_BUFFER_LENGTH (PA_PAGE_SIZE*12)
 
 static PA_DEFINE_CHECK_TYPE(pa_sink, pa_msgobject);
 
@@ -311,7 +312,7 @@
     pa_asyncmsgq_post(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_PING, NULL, 0, NULL, NULL);
 }
 
-static unsigned fill_mix_info(pa_sink *s, pa_mix_info *info, unsigned maxinfo) {
+static unsigned fill_mix_info(pa_sink *s, size_t length, pa_mix_info *info, unsigned maxinfo) {
     pa_sink_input *i;
     unsigned n = 0;
     void *state = NULL;
@@ -322,7 +323,7 @@
     while ((i = pa_hashmap_iterate(s->thread_info.inputs, &state, NULL)) && maxinfo > 0) {
         pa_sink_input_assert_ref(i);
 
-        if (pa_sink_input_peek(i, &info->chunk, &info->volume) < 0)
+        if (pa_sink_input_peek(i, length, &info->chunk, &info->volume) < 0)
             continue;
 
         info->userdata = pa_sink_input_ref(i);
@@ -399,20 +400,32 @@
 void pa_sink_render(pa_sink*s, size_t length, pa_memchunk *result) {
     pa_mix_info info[MAX_MIX_CHANNELS];
     unsigned n;
-
+    size_t block_size_max;
+    
     pa_sink_assert_ref(s);
     pa_assert(PA_SINK_OPENED(s->thread_info.state));
-    pa_assert(length);
+    pa_assert(pa_frame_aligned(length, &s->sample_spec));
     pa_assert(result);
 
     pa_sink_ref(s);
 
-    n = s->thread_info.state == PA_SINK_RUNNING ? fill_mix_info(s, info, MAX_MIX_CHANNELS) : 0;
+    if (length <= 0)
+        length = pa_frame_align(MIX_BUFFER_LENGTH, &s->sample_spec);
+
+    block_size_max = pa_mempool_block_size_max(s->core->mempool);
+    if (length > block_size_max)
+        length = pa_frame_align(block_size_max, &s->sample_spec);
+
+    pa_assert(length > 0);
+    
+    n = s->thread_info.state == PA_SINK_RUNNING ? fill_mix_info(s, length, info, MAX_MIX_CHANNELS) : 0;
 
     if (n == 0) {
 
         if (length > SILENCE_BUFFER_LENGTH)
-            length = SILENCE_BUFFER_LENGTH;
+            length = pa_frame_align(SILENCE_BUFFER_LENGTH, &s->sample_spec);
+
+        pa_assert(length > 0);
 
         if (!s->silence || pa_memblock_get_length(s->silence) < length) {
             if (s->silence)
@@ -470,11 +483,12 @@
     pa_assert(PA_SINK_OPENED(s->thread_info.state));
     pa_assert(target);
     pa_assert(target->memblock);
-    pa_assert(target->length);
+    pa_assert(target->length > 0);
+    pa_assert(pa_frame_aligned(target->length, &s->sample_spec));
 
     pa_sink_ref(s);
 
-    n = s->thread_info.state == PA_SINK_RUNNING ? fill_mix_info(s, info, MAX_MIX_CHANNELS) : 0;
+    n = s->thread_info.state == PA_SINK_RUNNING ? fill_mix_info(s, target->length, info, MAX_MIX_CHANNELS) : 0;
 
     if (n == 0) {
         pa_silence_memchunk(target, &s->sample_spec);
@@ -536,7 +550,8 @@
     pa_assert(PA_SINK_OPENED(s->thread_info.state));
     pa_assert(target);
     pa_assert(target->memblock);
-    pa_assert(target->length);
+    pa_assert(target->length > 0);
+    pa_assert(pa_frame_aligned(target->length, &s->sample_spec));
 
     pa_sink_ref(s);
 
@@ -559,13 +574,15 @@
 void pa_sink_render_full(pa_sink *s, size_t length, pa_memchunk *result) {
     pa_sink_assert_ref(s);
     pa_assert(PA_SINK_OPENED(s->thread_info.state));
-    pa_assert(length);
+    pa_assert(length > 0);
+    pa_assert(pa_frame_aligned(length, &s->sample_spec));
     pa_assert(result);
 
     /*** This needs optimization ***/
 
-    result->memblock = pa_memblock_new(s->core->mempool, result->length = length);
     result->index = 0;
+    result->length = length;
+    result->memblock = pa_memblock_new(s->core->mempool, length);
 
     pa_sink_render_into_full(s, result);
 }
@@ -577,6 +594,7 @@
     pa_sink_assert_ref(s);
     pa_assert(PA_SINK_OPENED(s->thread_info.state));
     pa_assert(length > 0);
+    pa_assert(pa_frame_aligned(length, &s->sample_spec));
     
     if (pa_source_used_by(s->monitor_source)) {
         pa_memchunk chunk;
@@ -853,7 +871,7 @@
                     pa_cvolume volume;
                     size_t n;
                     
-                    if (pa_sink_input_peek(info->sink_input, &memchunk, &volume) < 0)
+                    if (pa_sink_input_peek(info->sink_input, info->buffer_bytes, &memchunk, &volume) < 0)
                         break;
                     
                     n = memchunk.length > info->buffer_bytes ? info->buffer_bytes : memchunk.length;

Modified: branches/lennart/src/pulsecore/sound-file-stream.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/sound-file-stream.c?rev=1833&root=pulseaudio&r1=1832&r2=1833&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/sound-file-stream.c (original)
+++ branches/lennart/src/pulsecore/sound-file-stream.c Mon Sep 17 00:00:38 2007
@@ -43,8 +43,6 @@
 #include <pulsecore/core-util.h>
 
 #include "sound-file-stream.h"
-
-#define BUF_SIZE (1024*16)
 
 typedef struct file_stream {
     pa_msgobject parent;
@@ -113,7 +111,7 @@
     file_stream_unlink(FILE_STREAM(i->userdata));
 }
 
-static int sink_input_peek_cb(pa_sink_input *i, pa_memchunk *chunk) {
+static int sink_input_peek_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk) {
     file_stream *u;
     
     pa_assert(i);
@@ -128,7 +126,7 @@
         
         if (!u->memchunk.memblock) {
             
-            u->memchunk.memblock = pa_memblock_new(i->sink->core->mempool, BUF_SIZE);
+            u->memchunk.memblock = pa_memblock_new(i->sink->core->mempool, length);
             u->memchunk.index = 0;
             
             if (u->readf_function) {
@@ -137,7 +135,7 @@
                 size_t fs = pa_frame_size(&i->sample_spec);
                 
                 p = pa_memblock_acquire(u->memchunk.memblock);
-                n = u->readf_function(u->sndfile, p, BUF_SIZE/fs);
+                n = u->readf_function(u->sndfile, p, length/fs);
                 pa_memblock_release(u->memchunk.memblock);
 
                 if (n <= 0)
@@ -149,7 +147,7 @@
                 void *p;
 
                 p = pa_memblock_acquire(u->memchunk.memblock);
-                n = sf_read_raw(u->sndfile, p, BUF_SIZE);
+                n = sf_read_raw(u->sndfile, p, length);
                 pa_memblock_release(u->memchunk.memblock);
                 
                 if (n <= 0)




More information about the pulseaudio-commits mailing list