[pulseaudio-commits] r1777 - in /branches/lennart/src: modules/module-alsa-source.c modules/module-oss.c pulsecore/memblock.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Thu Sep 6 16:29:17 PDT 2007


Author: lennart
Date: Fri Sep  7 01:29:16 2007
New Revision: 1777

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1777&root=pulseaudio&view=rev
Log:
fix an assert when runnig module-oss in record only-mode. optimize allocation of memblocks on playback

Modified:
    branches/lennart/src/modules/module-alsa-source.c
    branches/lennart/src/modules/module-oss.c
    branches/lennart/src/pulsecore/memblock.c

Modified: branches/lennart/src/modules/module-alsa-source.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/modules/module-alsa-source.c?rev=1777&root=pulseaudio&r1=1776&r2=1777&view=diff
==============================================================================
--- branches/lennart/src/modules/module-alsa-source.c (original)
+++ branches/lennart/src/modules/module-alsa-source.c Fri Sep  7 01:29:16 2007
@@ -210,7 +210,7 @@
 
     for (;;) {
         void *p;
-        snd_pcm_sframes_t t;
+        snd_pcm_sframes_t t, k;
         ssize_t l;
         int err;
         pa_memchunk chunk;
@@ -228,10 +228,17 @@
         if (l <= 0)
             return work_done;
                     
-        chunk.memblock = pa_memblock_new(u->core->mempool, l);
+        chunk.memblock = pa_memblock_new(u->core->mempool, (size_t) -1);
+
+        k = pa_memblock_get_length(chunk.memblock);
+
+        if (k > l)
+            k = l;
+
+        k = (k/u->frame_size)*u->frame_size;
 
         p = pa_memblock_acquire(chunk.memblock);
-        t = snd_pcm_readi(u->pcm_handle, (uint8_t*) p, l / u->frame_size);
+        t = snd_pcm_readi(u->pcm_handle, (uint8_t*) p, k / u->frame_size);
         pa_memblock_release(chunk.memblock);
         
 /*                     pa_log("wrote %i bytes of %u (%u)", t*u->frame_size, u->memchunk.length, l);   */

Modified: branches/lennart/src/modules/module-oss.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/modules/module-oss.c?rev=1777&root=pulseaudio&r1=1776&r2=1777&view=diff
==============================================================================
--- branches/lennart/src/modules/module-oss.c (original)
+++ branches/lennart/src/modules/module-oss.c Fri Sep  7 01:29:16 2007
@@ -110,6 +110,7 @@
     
     pa_memchunk memchunk;
 
+    size_t frame_size;
     uint32_t in_fragment_size, out_fragment_size, in_nfrags, out_nfrags, in_hwbuf_size, out_hwbuf_size;
     int use_getospace, use_getispace;
     int use_getodelay;
@@ -941,14 +942,21 @@
                 }
 
                 do {
-                    ssize_t t;
+                    ssize_t t, k;
 
                     pa_assert(l > 0);
 
-                    memchunk.memblock = pa_memblock_new(u->core->mempool, l);
-
+                    memchunk.memblock = pa_memblock_new(u->core->mempool, (size_t) -1);
+
+                    k = pa_memblock_get_length(memchunk.memblock);
+
+                    if (k > l)
+                        k = l;
+
+                    k = (k/u->frame_size)*u->frame_size;
+        
                     p = pa_memblock_acquire(memchunk.memblock);
-                    t = pa_read(u->fd, p, l, &read_type);
+                    t = pa_read(u->fd, p, k, &read_type);
                     pa_memblock_release(memchunk.memblock);
 
                     pa_assert(t != 0); /* EOF cannot happen */
@@ -992,16 +1000,20 @@
 /*         pa_log("loop2"); */
 
         /* Now give the sink inputs some to time to process their data */
-        if ((ret = pa_sink_process_inputs(u->sink)) < 0)
-            goto fail;
-        if (ret > 0)
-            continue;
+        if (u->sink) {
+            if ((ret = pa_sink_process_inputs(u->sink)) < 0)
+                goto fail;
+            if (ret > 0)
+                continue;
+        }
 
         /* Now give the source outputs some to time to process their data */
-        if ((ret = pa_source_process_outputs(u->source)) < 0)
-            goto fail;
-        if (ret > 0)
-            continue;
+        if (u->source) {
+            if ((ret = pa_source_process_outputs(u->source)) < 0)
+                goto fail;
+            if (ret > 0)
+                continue;
+        }
         
         /* Check whether there is a message for us to process */
         if ((ret = pa_thread_mq_process(&u->thread_mq) < 0))
@@ -1148,6 +1160,7 @@
     u->use_getodelay = 1;
     u->use_input_volume = u->use_pcm_volume = 1;
     u->mode = mode;
+    u->frame_size = pa_frame_size(&ss);
     u->device_name = pa_xstrdup(dev);
     u->in_nfrags = u->out_nfrags = u->nfrags = nfrags;
     u->out_fragment_size = u->in_fragment_size = u->frag_size = frag_size;

Modified: branches/lennart/src/pulsecore/memblock.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/memblock.c?rev=1777&root=pulseaudio&r1=1776&r2=1777&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/memblock.c (original)
+++ branches/lennart/src/pulsecore/memblock.c Fri Sep  7 01:29:16 2007
@@ -218,6 +218,11 @@
     pa_assert(p);
     pa_assert(length > 0);
 
+    /* If -1 is passed as length we choose the size for the caller. */
+    
+    if (length == (size_t) -1)
+        length = p->block_size - PA_ALIGN(sizeof(struct mempool_slot)) - PA_ALIGN(sizeof(pa_memblock));
+    
     b = pa_xmalloc(PA_ALIGN(sizeof(pa_memblock)) + length);
     PA_REFCNT_INIT(b);
     b->pool = p;
@@ -261,7 +266,7 @@
 static void* mempool_slot_data(struct mempool_slot *slot) {
     pa_assert(slot);
 
-    return (uint8_t*) slot + sizeof(struct mempool_slot);
+    return (uint8_t*) slot + PA_ALIGN(sizeof(struct mempool_slot));
 }
 
 /* No lock necessary */
@@ -292,16 +297,22 @@
     pa_assert(p);
     pa_assert(length > 0);
 
-    if (p->block_size - sizeof(struct mempool_slot) >= sizeof(pa_memblock) + length) {
+    /* If -1 is passed as length we choose the size for the caller: we
+     * take the largest size that fits in one of our slots. */
+    
+    if (length == (size_t) -1)
+        length = p->block_size - PA_ALIGN(sizeof(struct mempool_slot)) - PA_ALIGN(sizeof(pa_memblock));
+    
+    if (p->block_size - PA_ALIGN(sizeof(struct mempool_slot)) >= PA_ALIGN(sizeof(pa_memblock)) + length) {
 
         if (!(slot = mempool_allocate_slot(p)))
             return NULL;
 
         b = mempool_slot_data(slot);
         b->type = PA_MEMBLOCK_POOL;
-        pa_atomic_ptr_store(&b->data, (uint8_t*) b + sizeof(pa_memblock));
-
-    } else if (p->block_size - sizeof(struct mempool_slot) >= length) {
+        pa_atomic_ptr_store(&b->data, (uint8_t*) b + PA_ALIGN(sizeof(pa_memblock)));
+
+    } else if (p->block_size - PA_ALIGN(sizeof(struct mempool_slot)) >= length) {
 
         if (!(slot = mempool_allocate_slot(p)))
             return NULL;
@@ -313,7 +324,7 @@
         pa_atomic_ptr_store(&b->data, mempool_slot_data(slot));
 
     } else {
-        pa_log_debug("Memory block too large for pool: %lu > %lu", (unsigned long) length, (unsigned long) (p->block_size - sizeof(struct mempool_slot)));
+        pa_log_debug("Memory block too large for pool: %lu > %lu", (unsigned long) length, (unsigned long) (p->block_size - PA_ALIGN(sizeof(struct mempool_slot))));
         pa_atomic_inc(&p->stat.n_too_large_for_pool);
         return NULL;
     }
@@ -335,6 +346,7 @@
 
     pa_assert(p);
     pa_assert(d);
+    pa_assert(length != (size_t) -1);
     pa_assert(length > 0);
 
     if (!(b = pa_flist_pop(PA_STATIC_FLIST_GET(unused_memblocks))))
@@ -359,6 +371,7 @@
     pa_assert(p);
     pa_assert(d);
     pa_assert(length > 0);
+    pa_assert(length != (size_t) -1);
     pa_assert(free_cb);
 
     if (!(b = pa_flist_pop(PA_STATIC_FLIST_GET(unused_memblocks))))
@@ -555,7 +568,7 @@
 
     pa_atomic_dec(&b->pool->stat.n_allocated_by_type[b->type]);
 
-    if (b->length <= b->pool->block_size - sizeof(struct mempool_slot)) {
+    if (b->length <= b->pool->block_size - PA_ALIGN(sizeof(struct mempool_slot))) {
         struct mempool_slot *slot;
 
         if ((slot = mempool_allocate_slot(b->pool))) {
@@ -657,7 +670,7 @@
 
     p->n_blocks = PA_MEMPOOL_SLOTS_MAX;
 
-    pa_assert(p->block_size > sizeof(struct mempool_slot));
+    pa_assert(p->block_size > PA_ALIGN(sizeof(struct mempool_slot)));
 
     if (pa_shm_create_rw(&p->memory, p->n_blocks * p->block_size, shared, 0700) < 0) {
         pa_xfree(p);
@@ -725,8 +738,8 @@
 
     while ((slot = pa_flist_pop(list))) {
         pa_shm_punch(&p->memory,
-                     (uint8_t*) slot - (uint8_t*) p->memory.ptr + sizeof(struct mempool_slot),
-                     p->block_size - sizeof(struct mempool_slot));
+                     (uint8_t*) slot - (uint8_t*) p->memory.ptr + PA_ALIGN(sizeof(struct mempool_slot)),
+                     p->block_size - PA_ALIGN(sizeof(struct mempool_slot)));
 
         while (pa_flist_push(p->free_slots, slot))
             ;




More information about the pulseaudio-commits mailing list