summaryrefslogtreecommitdiffstats
path: root/polyp/memchunk.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-11-17 00:05:25 +0000
committerLennart Poettering <lennart@poettering.net>2004-11-17 00:05:25 +0000
commit0a2bbc528b7865b08139155e0316738a717c4e42 (patch)
tree99166840892bb315fe109436093876386adac51d /polyp/memchunk.c
parentf5f6605254d17c5bc06b8c1ec98e8ee09009af10 (diff)
* some commenting work
* add new field "read_only" to memory blocks * add new API function pa_context_get_server() * filter capture data through mcalign on client * make module-tunnel use pa_socket_client_new_string() instead of using pa_resolve_server() directly. * remove pa_resolve_server() * remove debug.h and replace it by a macro definition on the gcc command line * some strbuf cleanups * small fixes in pa_stream for cleanup when server dies * new CLI command "load-sample-dir-lazy" * send FQDN as part of server info * rework mcalign, this time with memory block merging * fix iochannel cleanup when connection dies * check getaddrinfo() results git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@286 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'polyp/memchunk.c')
-rw-r--r--polyp/memchunk.c118
1 files changed, 13 insertions, 105 deletions
diff --git a/polyp/memchunk.c b/polyp/memchunk.c
index a8aeb881..d1c923f3 100644
--- a/polyp/memchunk.c
+++ b/polyp/memchunk.c
@@ -31,120 +31,28 @@
#include "memchunk.h"
#include "xmalloc.h"
-void pa_memchunk_make_writable(struct pa_memchunk *c, struct pa_memblock_stat *s) {
+void pa_memchunk_make_writable(struct pa_memchunk *c, struct pa_memblock_stat *s, size_t min) {
struct pa_memblock *n;
+ size_t l;
assert(c && c->memblock && c->memblock->ref >= 1);
- if (c->memblock->ref == 1)
+ if (c->memblock->ref == 1 && !c->memblock->read_only && c->memblock->length >= c->index+min)
return;
+
+ l = c->length;
+ if (l < min)
+ l = min;
- n = pa_memblock_new(c->length, s);
- assert(n);
- memcpy(n->data, (uint8_t*) c->memblock->data+c->index, c->length);
+ n = pa_memblock_new(l, s);
+ memcpy(n->data, (uint8_t*) c->memblock->data + c->index, c->length);
pa_memblock_unref(c->memblock);
c->memblock = n;
c->index = 0;
}
+void pa_memchunk_reset(struct pa_memchunk *c) {
+ assert(c);
-struct pa_mcalign {
- size_t base;
- struct pa_memchunk chunk;
- uint8_t *buffer;
- size_t buffer_fill;
- struct pa_memblock_stat *memblock_stat;
-};
-
-struct pa_mcalign *pa_mcalign_new(size_t base, struct pa_memblock_stat *s) {
- struct pa_mcalign *m;
- assert(base);
-
- m = pa_xmalloc(sizeof(struct pa_mcalign));
- m->base = base;
- m->chunk.memblock = NULL;
- m->chunk.length = m->chunk.index = 0;
- m->buffer = NULL;
- m->buffer_fill = 0;
- m->memblock_stat = s;
- return m;
-}
-
-void pa_mcalign_free(struct pa_mcalign *m) {
- assert(m);
-
- pa_xfree(m->buffer);
-
- if (m->chunk.memblock)
- pa_memblock_unref(m->chunk.memblock);
-
- pa_xfree(m);
-}
-
-void pa_mcalign_push(struct pa_mcalign *m, const struct pa_memchunk *c) {
- assert(m && c && !m->chunk.memblock && c->memblock && c->length);
-
- m->chunk = *c;
- pa_memblock_ref(m->chunk.memblock);
-}
-
-int pa_mcalign_pop(struct pa_mcalign *m, struct pa_memchunk *c) {
- int ret;
- assert(m && c && m->base > m->buffer_fill);
-
- if (!m->chunk.memblock)
- return -1;
-
- if (m->buffer_fill) {
- size_t l = m->base - m->buffer_fill;
- if (l > m->chunk.length)
- l = m->chunk.length;
- assert(m->buffer && l);
-
- memcpy((uint8_t*) m->buffer + m->buffer_fill, (uint8_t*) m->chunk.memblock->data + m->chunk.index, l);
- m->buffer_fill += l;
- m->chunk.index += l;
- m->chunk.length -= l;
-
- if (m->chunk.length == 0) {
- m->chunk.length = m->chunk.index = 0;
- pa_memblock_unref(m->chunk.memblock);
- m->chunk.memblock = NULL;
- }
-
- assert(m->buffer_fill <= m->base);
- if (m->buffer_fill == m->base) {
- c->memblock = pa_memblock_new_dynamic(m->buffer, m->base, m->memblock_stat);
- assert(c->memblock);
- c->index = 0;
- c->length = m->base;
- m->buffer = NULL;
- m->buffer_fill = 0;
-
- return 0;
- }
-
- return -1;
- }
-
- m->buffer_fill = m->chunk.length % m->base;
-
- if (m->buffer_fill) {
- assert(!m->buffer);
- m->buffer = pa_xmalloc(m->base);
- m->chunk.length -= m->buffer_fill;
- memcpy(m->buffer, (uint8_t*) m->chunk.memblock->data + m->chunk.index + m->chunk.length, m->buffer_fill);
- }
-
- if (m->chunk.length) {
- *c = m->chunk;
- pa_memblock_ref(c->memblock);
- ret = 0;
- } else
- ret = -1;
-
- m->chunk.length = m->chunk.index = 0;
- pa_memblock_unref(m->chunk.memblock);
- m->chunk.memblock = NULL;
-
- return ret;
+ c->memblock = NULL;
+ c->length = c->index = 0;
}