summaryrefslogtreecommitdiffstats
path: root/polyp
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-08-17 19:37:29 +0000
committerLennart Poettering <lennart@poettering.net>2004-08-17 19:37:29 +0000
commite75b65715b2fc9a3363bd4ac598fe02888b7ed21 (patch)
tree4143a433981356e6a784ecf0a0c0bfc3806348ea /polyp
parent81822a751929fbc153282de3af447b9430d5c474 (diff)
remove global memblock statistic variables in favor of memblock_stat objects
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@137 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'polyp')
-rw-r--r--polyp/cli-command.c6
-rw-r--r--polyp/core.c4
-rw-r--r--polyp/core.h3
-rw-r--r--polyp/memblock.c71
-rw-r--r--polyp/memblock.h24
-rw-r--r--polyp/memblockq.c7
-rw-r--r--polyp/memblockq.h3
-rw-r--r--polyp/memchunk.c10
-rw-r--r--polyp/memchunk.h4
-rw-r--r--polyp/module-alsa-sink.c2
-rw-r--r--polyp/module-alsa-source.c2
-rw-r--r--polyp/module-oss-mmap.c4
-rw-r--r--polyp/module-oss.c4
-rw-r--r--polyp/pactl.c4
-rw-r--r--polyp/polyplib-context.c8
-rw-r--r--polyp/polyplib-internal.h2
-rw-r--r--polyp/polyplib-introspect.c6
-rw-r--r--polyp/polyplib-introspect.h6
-rw-r--r--polyp/polyplib-stream.c4
-rw-r--r--polyp/protocol-esound.c8
-rw-r--r--polyp/protocol-native.c14
-rw-r--r--polyp/protocol-simple.c6
-rw-r--r--polyp/pstream.c8
-rw-r--r--polyp/pstream.h2
-rw-r--r--polyp/resampler.c8
-rw-r--r--polyp/resampler.h2
-rw-r--r--polyp/sink-input.c2
-rw-r--r--polyp/sink.c4
-rw-r--r--polyp/sound-file.c4
-rw-r--r--polyp/sound-file.h2
-rw-r--r--polyp/source-output.c2
31 files changed, 158 insertions, 78 deletions
diff --git a/polyp/cli-command.c b/polyp/cli-command.c
index 8459d71b..5a8ff177 100644
--- a/polyp/cli-command.c
+++ b/polyp/cli-command.c
@@ -210,7 +210,7 @@ static int pa_cli_command_source_outputs(struct pa_core *c, struct pa_tokenizer
static int pa_cli_command_stat(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
assert(c && t);
- pa_strbuf_printf(buf, "Memory blocks allocated: %u, total size: %u bytes.\n", pa_memblock_get_count(), pa_memblock_get_total());
+ pa_strbuf_printf(buf, "Memory blocks currently allocated: %u, size: %u bytes.\nMemory blocks allocated during the whole lifetime: %u, size: %u bytes.\n", c->memblock_stat->total, c->memblock_stat->total_size, c->memblock_stat->allocated, c->memblock_stat->allocated_size);
return 0;
}
@@ -504,7 +504,7 @@ static int pa_cli_command_scache_load(struct pa_core *c, struct pa_tokenizer *t,
return -1;
}
- if (pa_sound_file_load(fname, &ss, &chunk) < 0) {
+ if (pa_sound_file_load(fname, &ss, &chunk, c->memblock_stat) < 0) {
pa_strbuf_puts(buf, "Failed to load sound file.\n");
return -1;
}
@@ -532,7 +532,7 @@ static int pa_cli_command_play_file(struct pa_core *c, struct pa_tokenizer *t, s
return -1;
}
- if (pa_sound_file_load(fname, &ss, &chunk) < 0) {
+ if (pa_sound_file_load(fname, &ss, &chunk, c->memblock_stat) < 0) {
pa_strbuf_puts(buf, "Failed to load sound file.\n");
return -1;
}
diff --git a/polyp/core.c b/polyp/core.c
index 55944aad..b43eb639 100644
--- a/polyp/core.c
+++ b/polyp/core.c
@@ -68,6 +68,8 @@ struct pa_core* pa_core_new(struct pa_mainloop_api *m) {
c->subscription_defer_event = NULL;
c->subscription_event_queue = NULL;
c->subscriptions = NULL;
+
+ c->memblock_stat = pa_memblock_stat_new();
pa_check_for_sigpipe();
@@ -102,6 +104,8 @@ void pa_core_free(struct pa_core *c) {
pa_xfree(c->default_source_name);
pa_xfree(c->default_sink_name);
+
+ pa_memblock_stat_unref(c->memblock_stat);
pa_xfree(c);
};
diff --git a/polyp/core.h b/polyp/core.h
index 43691771..c0a2d6d8 100644
--- a/polyp/core.h
+++ b/polyp/core.h
@@ -26,6 +26,7 @@
#include "hashmap.h"
#include "mainloop-api.h"
#include "sample.h"
+#include "memblock.h"
struct pa_core {
struct pa_mainloop_api *mainloop;
@@ -43,6 +44,8 @@ struct pa_core {
struct pa_defer_event *subscription_defer_event;
struct pa_queue *subscription_event_queue;
struct pa_subscription *subscriptions;
+
+ struct pa_memblock_stat *memblock_stat;
};
struct pa_core* pa_core_new(struct pa_mainloop_api *m);
diff --git a/polyp/memblock.c b/polyp/memblock.c
index a4452efa..500d8b20 100644
--- a/polyp/memblock.c
+++ b/polyp/memblock.c
@@ -31,45 +31,63 @@
#include "memblock.h"
#include "xmalloc.h"
-static unsigned memblock_count = 0, memblock_total = 0;
+static void stat_add(struct pa_memblock*m, struct pa_memblock_stat *s) {
+ assert(m);
+
+ m->stat = pa_memblock_stat_ref(s);
+ s->total++;
+ s->allocated++;
+ s->total_size += m->length;
+ s->allocated_size += m->length;
+}
+
+static void stat_remove(struct pa_memblock *m) {
+ assert(m);
+
+ if (!m->stat)
+ return;
-struct pa_memblock *pa_memblock_new(size_t length) {
+ m->stat->total--;
+ m->stat->total_size -= m->length;
+
+ pa_memblock_stat_unref(m->stat);
+ m->stat = NULL;
+}
+
+struct pa_memblock *pa_memblock_new(size_t length, struct pa_memblock_stat*s) {
struct pa_memblock *b = pa_xmalloc(sizeof(struct pa_memblock)+length);
b->type = PA_MEMBLOCK_APPENDED;
b->ref = 1;
b->length = length;
b->data = b+1;
b->free_cb = NULL;
- memblock_count++;
- memblock_total += length;
+ stat_add(b, s);
return b;
}
-struct pa_memblock *pa_memblock_new_fixed(void *d, size_t length) {
+struct pa_memblock *pa_memblock_new_fixed(void *d, size_t length, struct pa_memblock_stat*s) {
struct pa_memblock *b = pa_xmalloc(sizeof(struct pa_memblock));
b->type = PA_MEMBLOCK_FIXED;
b->ref = 1;
b->length = length;
b->data = d;
b->free_cb = NULL;
- memblock_count++;
- memblock_total += length;
+ stat_add(b, s);
return b;
}
-struct pa_memblock *pa_memblock_new_dynamic(void *d, size_t length) {
+struct pa_memblock *pa_memblock_new_dynamic(void *d, size_t length, struct pa_memblock_stat*s) {
struct pa_memblock *b = pa_xmalloc(sizeof(struct pa_memblock));
b->type = PA_MEMBLOCK_DYNAMIC;
b->ref = 1;
b->length = length;
b->data = d;
b->free_cb = NULL;
- memblock_count++;
- memblock_total += length;
+ stat_add(b, s);
return b;
}
-struct pa_memblock *pa_memblock_new_user(void *d, size_t length, void (*free_cb)(void *p)) {
+struct pa_memblock *pa_memblock_new_user(void *d, size_t length, void (*free_cb)(void *p), struct pa_memblock_stat*s) {
struct pa_memblock *b;
assert(d && length && free_cb);
b = pa_xmalloc(sizeof(struct pa_memblock));
@@ -78,8 +96,7 @@ struct pa_memblock *pa_memblock_new_user(void *d, size_t length, void (*free_cb)
b->length = length;
b->data = d;
b->free_cb = free_cb;
- memblock_count++;
- memblock_total += length;
+ stat_add(b, s);
return b;
}
@@ -93,8 +110,7 @@ void pa_memblock_unref(struct pa_memblock*b) {
assert(b && b->ref >= 1);
if ((--(b->ref)) == 0) {
- memblock_count--;
- memblock_total -= b->length;
+ stat_remove(b);
if (b->type == PA_MEMBLOCK_USER) {
assert(b->free_cb);
@@ -118,10 +134,27 @@ void pa_memblock_unref_fixed(struct pa_memblock *b) {
}
}
-unsigned pa_memblock_get_count(void) {
- return memblock_count;
+struct pa_memblock_stat* pa_memblock_stat_new(void) {
+ struct pa_memblock_stat *s;
+
+ s = pa_xmalloc(sizeof(struct pa_memblock_stat));
+ s->ref = 1;
+ s->total = s->total_size = s->allocated = s->allocated_size = 0;
+
+ return s;
+}
+
+void pa_memblock_stat_unref(struct pa_memblock_stat *s) {
+ assert(s && s->ref >= 1);
+
+ if (!(--(s->ref))) {
+ assert(!s->total);
+ pa_xfree(s);
+ }
}
-unsigned pa_memblock_get_total(void) {
- return memblock_total;
+struct pa_memblock_stat * pa_memblock_stat_ref(struct pa_memblock_stat *s) {
+ assert(s);
+ s->ref++;
+ return s;
}
diff --git a/polyp/memblock.h b/polyp/memblock.h
index 6e79aa3e..949a0a08 100644
--- a/polyp/memblock.h
+++ b/polyp/memblock.h
@@ -27,25 +27,37 @@
enum pa_memblock_type { PA_MEMBLOCK_FIXED, PA_MEMBLOCK_APPENDED, PA_MEMBLOCK_DYNAMIC, PA_MEMBLOCK_USER };
+struct pa_memblock_stat;
+
struct pa_memblock {
enum pa_memblock_type type;
unsigned ref;
size_t length;
void *data;
void (*free_cb)(void *p);
+ struct pa_memblock_stat *stat;
};
-struct pa_memblock *pa_memblock_new(size_t length);
-struct pa_memblock *pa_memblock_new_fixed(void *data, size_t length);
-struct pa_memblock *pa_memblock_new_dynamic(void *data, size_t length);
-struct pa_memblock *pa_memblock_new_user(void *data, size_t length, void (*free_cb)(void *p));
+struct pa_memblock *pa_memblock_new(size_t length, struct pa_memblock_stat*s);
+struct pa_memblock *pa_memblock_new_fixed(void *data, size_t length, struct pa_memblock_stat*s);
+struct pa_memblock *pa_memblock_new_dynamic(void *data, size_t length, struct pa_memblock_stat*s);
+struct pa_memblock *pa_memblock_new_user(void *data, size_t length, void (*free_cb)(void *p), struct pa_memblock_stat*s);
void pa_memblock_unref(struct pa_memblock*b);
struct pa_memblock* pa_memblock_ref(struct pa_memblock*b);
void pa_memblock_unref_fixed(struct pa_memblock*b);
-unsigned pa_memblock_get_count(void);
-unsigned pa_memblock_get_total(void);
+struct pa_memblock_stat {
+ int ref;
+ unsigned total;
+ unsigned total_size;
+ unsigned allocated;
+ unsigned allocated_size;
+};
+
+struct pa_memblock_stat* pa_memblock_stat_new(void);
+void pa_memblock_stat_unref(struct pa_memblock_stat *s);
+struct pa_memblock_stat * pa_memblock_stat_ref(struct pa_memblock_stat *s);
#endif
diff --git a/polyp/memblockq.c b/polyp/memblockq.c
index 8f499df0..bc5d7437 100644
--- a/polyp/memblockq.c
+++ b/polyp/memblockq.c
@@ -45,9 +45,10 @@ struct pa_memblockq {
int measure_delay;
uint32_t delay;
struct pa_mcalign *mcalign;
+ struct pa_memblock_stat *memblock_stat;
};
-struct pa_memblockq* pa_memblockq_new(size_t maxlength, size_t tlength, size_t base, size_t prebuf, size_t minreq) {
+struct pa_memblockq* pa_memblockq_new(size_t maxlength, size_t tlength, size_t base, size_t prebuf, size_t minreq, struct pa_memblock_stat *s) {
struct pa_memblockq* bq;
assert(maxlength && base && maxlength);
@@ -83,6 +84,8 @@ struct pa_memblockq* pa_memblockq_new(size_t maxlength, size_t tlength, size_t b
bq->delay = 0;
bq->mcalign = NULL;
+
+ bq->memblock_stat = s;
return bq;
}
@@ -306,7 +309,7 @@ void pa_memblockq_push_align(struct pa_memblockq* bq, const struct pa_memchunk *
}
if (!bq->mcalign) {
- bq->mcalign = pa_mcalign_new(bq->base);
+ bq->mcalign = pa_mcalign_new(bq->base, bq->memblock_stat);
assert(bq->mcalign);
}
diff --git a/polyp/memblockq.h b/polyp/memblockq.h
index 40184703..af8fa374 100644
--- a/polyp/memblockq.h
+++ b/polyp/memblockq.h
@@ -40,7 +40,8 @@ struct pa_memblockq* pa_memblockq_new(size_t maxlength,
size_t tlength,
size_t base,
size_t prebuf,
- size_t minreq);
+ size_t minreq,
+ struct pa_memblock_stat *s);
void pa_memblockq_free(struct pa_memblockq*bq);
/* Push a new memory chunk into the queue. Optionally specify a value for future cancellation. This is currently not implemented, however! */
diff --git a/polyp/memchunk.c b/polyp/memchunk.c
index 77e1b7dd..5913c6e3 100644
--- a/polyp/memchunk.c
+++ b/polyp/memchunk.c
@@ -31,14 +31,14 @@
#include "memchunk.h"
#include "xmalloc.h"
-void pa_memchunk_make_writable(struct pa_memchunk *c) {
+void pa_memchunk_make_writable(struct pa_memchunk *c, struct pa_memblock_stat *s) {
struct pa_memblock *n;
assert(c && c->memblock && c->memblock->ref >= 1);
if (c->memblock->ref == 1)
return;
- n = pa_memblock_new(c->length);
+ n = pa_memblock_new(c->length, s);
assert(n);
memcpy(n->data, c->memblock->data+c->index, c->length);
pa_memblock_unref(c->memblock);
@@ -52,9 +52,10 @@ struct pa_mcalign {
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_mcalign *pa_mcalign_new(size_t base, struct pa_memblock_stat *s) {
struct pa_mcalign *m;
assert(base);
@@ -64,6 +65,7 @@ struct pa_mcalign *pa_mcalign_new(size_t base) {
m->chunk.length = m->chunk.index = 0;
m->buffer = NULL;
m->buffer_fill = 0;
+ m->memblock_stat = s;
return m;
}
@@ -111,7 +113,7 @@ int pa_mcalign_pop(struct pa_mcalign *m, struct pa_memchunk *c) {
assert(m->buffer_fill <= m->base);
if (m->buffer_fill == m->base) {
- c->memblock = pa_memblock_new_dynamic(m->buffer, 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;
diff --git a/polyp/memchunk.h b/polyp/memchunk.h
index 341c145c..3a592f04 100644
--- a/polyp/memchunk.h
+++ b/polyp/memchunk.h
@@ -29,11 +29,11 @@ struct pa_memchunk {
size_t index, length;
};
-void pa_memchunk_make_writable(struct pa_memchunk *c);
+void pa_memchunk_make_writable(struct pa_memchunk *c, struct pa_memblock_stat *s);
struct pa_mcalign;
-struct pa_mcalign *pa_mcalign_new(size_t base);
+struct pa_mcalign *pa_mcalign_new(size_t base, struct pa_memblock_stat *s);
void pa_mcalign_free(struct pa_mcalign *m);
void pa_mcalign_push(struct pa_mcalign *m, const struct pa_memchunk *c);
int pa_mcalign_pop(struct pa_mcalign *m, struct pa_memchunk *c);
diff --git a/polyp/module-alsa-sink.c b/polyp/module-alsa-sink.c
index 5b4a7b73..06b07f33 100644
--- a/polyp/module-alsa-sink.c
+++ b/polyp/module-alsa-sink.c
@@ -217,7 +217,7 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
fprintf(stderr, __FILE__": using %u fragments of size %u bytes.\n", periods, u->fragment_size);
- u->silence.memblock = pa_memblock_new(u->silence.length = u->fragment_size);
+ u->silence.memblock = pa_memblock_new(u->silence.length = u->fragment_size, c->memblock_stat);
assert(u->silence.memblock);
pa_silence_memblock(u->silence.memblock, &ss);
u->silence.index = 0;
diff --git a/polyp/module-alsa-source.c b/polyp/module-alsa-source.c
index df716f73..9dc623d4 100644
--- a/polyp/module-alsa-source.c
+++ b/polyp/module-alsa-source.c
@@ -89,7 +89,7 @@ static void do_read(struct userdata *u) {
size_t l;
if (!u->memchunk.memblock) {
- u->memchunk.memblock = pa_memblock_new(u->memchunk.length = u->fragment_size);
+ u->memchunk.memblock = pa_memblock_new(u->memchunk.length = u->fragment_size, u->source->core->memblock_stat);
u->memchunk.index = 0;
}
diff --git a/polyp/module-oss-mmap.c b/polyp/module-oss-mmap.c
index ea768a98..7c7750d1 100644
--- a/polyp/module-oss-mmap.c
+++ b/polyp/module-oss-mmap.c
@@ -100,7 +100,7 @@ static void out_fill_memblocks(struct userdata *u, unsigned n) {
if (u->out_memblocks[u->out_current])
pa_memblock_unref_fixed(u->out_memblocks[u->out_current]);
- chunk.memblock = u->out_memblocks[u->out_current] = pa_memblock_new_fixed(u->out_mmap+u->out_fragment_size*u->out_current, u->out_fragment_size);
+ chunk.memblock = u->out_memblocks[u->out_current] = pa_memblock_new_fixed(u->out_mmap+u->out_fragment_size*u->out_current, u->out_fragment_size, u->core->memblock_stat);
assert(chunk.memblock);
chunk.length = chunk.memblock->length;
chunk.index = 0;
@@ -141,7 +141,7 @@ static void in_post_memblocks(struct userdata *u, unsigned n) {
struct pa_memchunk chunk;
if (!u->in_memblocks[u->in_current]) {
- chunk.memblock = u->in_memblocks[u->in_current] = pa_memblock_new_fixed(u->in_mmap+u->in_fragment_size*u->in_current, u->in_fragment_size);
+ chunk.memblock = u->in_memblocks[u->in_current] = pa_memblock_new_fixed(u->in_mmap+u->in_fragment_size*u->in_current, u->in_fragment_size, u->core->memblock_stat);
chunk.length = chunk.memblock->length;
chunk.index = 0;
diff --git a/polyp/module-oss.c b/polyp/module-oss.c
index a8db4a33..d5517b5e 100644
--- a/polyp/module-oss.c
+++ b/polyp/module-oss.c
@@ -131,7 +131,7 @@ static void do_read(struct userdata *u) {
update_usage(u);
- memchunk.memblock = pa_memblock_new(u->in_fragment_size);
+ memchunk.memblock = pa_memblock_new(u->in_fragment_size, u->core->memblock_stat);
assert(memchunk.memblock);
if ((r = pa_iochannel_read(u->io, memchunk.memblock->data, memchunk.memblock->length)) < 0) {
pa_memblock_unref(memchunk.memblock);
@@ -273,7 +273,7 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
u->out_fragment_size = out_frag_size;
u->in_fragment_size = in_frag_size;
- u->silence.memblock = pa_memblock_new(u->silence.length = u->out_fragment_size);
+ u->silence.memblock = pa_memblock_new(u->silence.length = u->out_fragment_size, u->core->memblock_stat);
assert(u->silence.memblock);
pa_silence_memblock(u->silence.memblock, &ss);
u->silence.index = 0;
diff --git a/polyp/pactl.c b/polyp/pactl.c
index 0ff2aa90..f2556706 100644
--- a/polyp/pactl.c
+++ b/polyp/pactl.c
@@ -88,7 +88,9 @@ static void stat_callback(struct pa_context *c, const struct pa_stat_info *i, vo
return;
}
- fprintf(stderr, "Currently in use: %u blocks containing %u bytes total.\n", i->memblock_count, i->memblock_total);
+ fprintf(stderr, "Currently in use: %u blocks containing %u bytes total.\n"
+ "Allocated during whole lifetime: %u blocks containing %u bytes total.\n",
+ i->memblock_total, i->memblock_total_size, i->memblock_allocated, i->memblock_allocated_size);
drain();
}
diff --git a/polyp/polyplib-context.c b/polyp/polyplib-context.c
index 2a0c24a5..fcf3f6b9 100644
--- a/polyp/polyplib-context.c
+++ b/polyp/polyplib-context.c
@@ -78,6 +78,8 @@ struct pa_context *pa_context_new(struct pa_mainloop_api *mainloop, const char *
c->subscribe_callback = NULL;
c->subscribe_userdata = NULL;
+ c->memblock_stat = pa_memblock_stat_new();
+
pa_check_for_sigpipe();
return c;
}
@@ -104,7 +106,9 @@ static void context_free(struct pa_context *c) {
pa_dynarray_free(c->record_streams, NULL, NULL);
if (c->playback_streams)
pa_dynarray_free(c->playback_streams, NULL, NULL);
-
+
+ pa_memblock_stat_unref(c->memblock_stat);
+
pa_xfree(c->name);
pa_xfree(c);
}
@@ -280,7 +284,7 @@ static void on_connection(struct pa_socket_client *client, struct pa_iochannel*i
}
assert(!c->pstream);
- c->pstream = pa_pstream_new(c->mainloop, io);
+ c->pstream = pa_pstream_new(c->mainloop, io, c->memblock_stat);
assert(c->pstream);
pa_pstream_set_die_callback(c->pstream, pstream_die_callback, c);
diff --git a/polyp/polyplib-internal.h b/polyp/polyplib-internal.h
index c8228a86..fd6cd38f 100644
--- a/polyp/polyplib-internal.h
+++ b/polyp/polyplib-internal.h
@@ -73,6 +73,8 @@ struct pa_context {
void (*subscribe_callback)(struct pa_context *c, enum pa_subscription_event_type t, uint32_t index, void *userdata);
void *subscribe_userdata;
+
+ struct pa_memblock_stat *memblock_stat;
};
struct pa_stream {
diff --git a/polyp/polyplib-introspect.c b/polyp/polyplib-introspect.c
index 9a7ec157..0efc599d 100644
--- a/polyp/polyplib-introspect.c
+++ b/polyp/polyplib-introspect.c
@@ -42,8 +42,10 @@ static void context_stat_callback(struct pa_pdispatch *pd, uint32_t command, uin
goto finish;
p = NULL;
- } else if (pa_tagstruct_getu32(t, &i.memblock_count) < 0 ||
- pa_tagstruct_getu32(t, &i.memblock_total) < 0 ||
+ } else if (pa_tagstruct_getu32(t, &i.memblock_total) < 0 ||
+ pa_tagstruct_getu32(t, &i.memblock_total_size) < 0 ||
+ pa_tagstruct_getu32(t, &i.memblock_allocated) < 0 ||
+ pa_tagstruct_getu32(t, &i.memblock_allocated_size) < 0 ||
!pa_tagstruct_eof(t)) {
pa_context_fail(o->context, PA_ERROR_PROTOCOL);
goto finish;
diff --git a/polyp/polyplib-introspect.h b/polyp/polyplib-introspect.h
index dfa24ed5..c453eb2f 100644
--- a/polyp/polyplib-introspect.h
+++ b/polyp/polyplib-introspect.h
@@ -130,8 +130,10 @@ struct pa_operation* pa_context_set_sink_input_volume(struct pa_context *c, uint
/** Memory block statistics */
struct pa_stat_info {
- uint32_t memblock_count; /**< Allocated memory blocks */
- uint32_t memblock_total; /**< Total size of allocated memory blocks */
+ uint32_t memblock_total; /**< Currently allocated memory blocks */
+ uint32_t memblock_total_size; /**< Currentl total size of allocated memory blocks */
+ uint32_t memblock_allocated; /**< Allocated memory blocks during the whole lifetime of the daemon */
+ uint32_t memblock_allocated_size; /**< Total size of all memory blocks allocated during the whole lifetime of the daemon */
};
/** Get daemon memory block statistics */
diff --git a/polyp/polyplib-stream.c b/polyp/polyplib-stream.c
index 362dbad1..2b591f36 100644
--- a/polyp/polyplib-stream.c
+++ b/polyp/polyplib-stream.c
@@ -272,10 +272,10 @@ void pa_stream_write(struct pa_stream *s, const void *data, size_t length, void
assert(s && s->context && data && length && s->state == PA_STREAM_READY && s->ref >= 1);
if (free_cb) {
- chunk.memblock = pa_memblock_new_user((void*) data, length, free_cb);
+ chunk.memblock = pa_memblock_new_user((void*) data, length, free_cb, s->context->memblock_stat);
assert(chunk.memblock && chunk.memblock->data);
} else {
- chunk.memblock = pa_memblock_new(length);
+ chunk.memblock = pa_memblock_new(length, s->context->memblock_stat);
assert(chunk.memblock && chunk.memblock->data);
memcpy(chunk.memblock->data, data, length);
}
diff --git a/polyp/protocol-esound.c b/polyp/protocol-esound.c
index fb639b7f..f5efa419 100644
--- a/polyp/protocol-esound.c
+++ b/polyp/protocol-esound.c
@@ -291,7 +291,7 @@ static int esd_proto_stream_play(struct connection *c, esd_proto_t request, cons
assert(!c->input_memblockq);
l = (size_t) (pa_bytes_per_second(&ss)*PLAYBACK_BUFFER_SECONDS);
- c->input_memblockq = pa_memblockq_new(l, 0, pa_frame_size(&ss), l/2, l/PLAYBACK_BUFFER_FRAGMENTS);
+ c->input_memblockq = pa_memblockq_new(l, 0, pa_frame_size(&ss), l/2, l/PLAYBACK_BUFFER_FRAGMENTS, c->protocol->core->memblock_stat);
assert(c->input_memblockq);
pa_iochannel_socket_set_rcvbuf(c->io, l/PLAYBACK_BUFFER_FRAGMENTS*2);
c->playback.fragment_size = l/10;
@@ -355,7 +355,7 @@ static int esd_proto_stream_record(struct connection *c, esd_proto_t request, co
assert(!c->output_memblockq);
l = (size_t) (pa_bytes_per_second(&ss)*RECORD_BUFFER_SECONDS);
- c->output_memblockq = pa_memblockq_new(l, 0, pa_frame_size(&ss), 0, 0);
+ c->output_memblockq = pa_memblockq_new(l, 0, pa_frame_size(&ss), 0, 0, c->protocol->core->memblock_stat);
assert(c->output_memblockq);
pa_iochannel_socket_set_sndbuf(c->io, l/RECORD_BUFFER_FRAGMENTS*2);
@@ -574,7 +574,7 @@ static int esd_proto_sample_cache(struct connection *c, esd_proto_t request, con
name[sizeof(name)-1] = 0;
assert(!c->scache_memchunk.memblock);
- c->scache_memchunk.memblock = pa_memblock_new(sc_length);
+ c->scache_memchunk.memblock = pa_memblock_new(sc_length, c->protocol->core->memblock_stat);
c->scache_memchunk.index = 0;
c->scache_memchunk.length = sc_length;
c->scache_sample_spec = ss;
@@ -778,7 +778,7 @@ static int do_read(struct connection *c) {
}
if (!c->playback.current_memblock) {
- c->playback.current_memblock = pa_memblock_new(c->playback.fragment_size*2);
+ c->playback.current_memblock = pa_memblock_new(c->playback.fragment_size*2, c->protocol->core->memblock_stat);
assert(c->playback.current_memblock && c->playback.current_memblock->length >= l);
c->playback.memblock_index = 0;
}
diff --git a/polyp/protocol-native.c b/polyp/protocol-native.c
index e86c78f0..060b4241 100644
--- a/polyp/protocol-native.c
+++ b/polyp/protocol-native.c
@@ -229,7 +229,7 @@ static struct record_stream* record_stream_new(struct connection *c, struct pa_s
s->source_output->owner = c->protocol->module;
s->source_output->client = c->client;
- s->memblockq = pa_memblockq_new(maxlength, 0, base = pa_frame_size(ss), 0, 0);
+ s->memblockq = pa_memblockq_new(maxlength, 0, base = pa_frame_size(ss), 0, 0, c->protocol->core->memblock_stat);
assert(s->memblockq);
s->fragment_size = (fragment_size/base)*base;
@@ -274,7 +274,7 @@ static struct playback_stream* playback_stream_new(struct connection *c, struct
s->sink_input->owner = c->protocol->module;
s->sink_input->client = c->client;
- s->memblockq = pa_memblockq_new(maxlength, tlength, pa_frame_size(ss), prebuf, minreq);
+ s->memblockq = pa_memblockq_new(maxlength, tlength, pa_frame_size(ss), prebuf, minreq, c->protocol->core->memblock_stat);
assert(s->memblockq);
s->requested_bytes = 0;
@@ -780,8 +780,10 @@ static void command_stat(struct pa_pdispatch *pd, uint32_t command, uint32_t tag
assert(reply);
pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
pa_tagstruct_putu32(reply, tag);
- pa_tagstruct_putu32(reply, pa_memblock_get_count());
- pa_tagstruct_putu32(reply, pa_memblock_get_total());
+ pa_tagstruct_putu32(reply, c->protocol->core->memblock_stat->total);
+ pa_tagstruct_putu32(reply, c->protocol->core->memblock_stat->total_size);
+ pa_tagstruct_putu32(reply, c->protocol->core->memblock_stat->allocated);
+ pa_tagstruct_putu32(reply, c->protocol->core->memblock_stat->allocated_size);
pa_pstream_send_tagstruct(c->pstream, reply);
}
@@ -1313,7 +1315,7 @@ static void pstream_memblock_callback(struct pa_pstream *p, uint32_t channel, in
u->length = 0;
fprintf(stderr, "COPY\n");
} else {
- u->memchunk.memblock = pa_memblock_new(u->length);
+ u->memchunk.memblock = pa_memblock_new(u->length, c->protocol->core->memblock_stat);
u->memchunk.index = u->memchunk.length = 0;
}
}
@@ -1372,7 +1374,7 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
c->client->userdata = c;
c->client->owner = p->module;
- c->pstream = pa_pstream_new(p->core->mainloop, io);
+ c->pstream = pa_pstream_new(p->core->mainloop, io, p->core->memblock_stat);
assert(c->pstream);
pa_pstream_set_recieve_packet_callback(c->pstream, pstream_packet_callback, c);
diff --git a/polyp/protocol-simple.c b/polyp/protocol-simple.c
index bd0e1488..58343486 100644
--- a/polyp/protocol-simple.c
+++ b/polyp/protocol-simple.c
@@ -115,7 +115,7 @@ static int do_read(struct connection *c) {
}
if (!c->playback.current_memblock) {
- c->playback.current_memblock = pa_memblock_new(c->playback.fragment_size*2);
+ c->playback.current_memblock = pa_memblock_new(c->playback.fragment_size*2, c->protocol->core->memblock_stat);
assert(c->playback.current_memblock && c->playback.current_memblock->length >= l);
c->playback.memblock_index = 0;
}
@@ -318,7 +318,7 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
c->sink_input->userdata = c;
l = (size_t) (pa_bytes_per_second(&p->sample_spec)*PLAYBACK_BUFFER_SECONDS);
- c->input_memblockq = pa_memblockq_new(l, 0, pa_frame_size(&p->sample_spec), l/2, l/PLAYBACK_BUFFER_FRAGMENTS);
+ c->input_memblockq = pa_memblockq_new(l, 0, pa_frame_size(&p->sample_spec), l/2, l/PLAYBACK_BUFFER_FRAGMENTS, p->core->memblock_stat);
assert(c->input_memblockq);
pa_iochannel_socket_set_rcvbuf(io, l/PLAYBACK_BUFFER_FRAGMENTS*5);
c->playback.fragment_size = l/10;
@@ -346,7 +346,7 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
c->source_output->userdata = c;
l = (size_t) (pa_bytes_per_second(&p->sample_spec)*RECORD_BUFFER_SECONDS);
- c->output_memblockq = pa_memblockq_new(l, 0, pa_frame_size(&p->sample_spec), 0, 0);
+ c->output_memblockq = pa_memblockq_new(l, 0, pa_frame_size(&p->sample_spec), 0, 0, p->core->memblock_stat);
pa_iochannel_socket_set_sndbuf(io, l/RECORD_BUFFER_FRAGMENTS*2);
}
diff --git a/polyp/pstream.c b/polyp/pstream.c
index 2d147e03..5664e18a 100644
--- a/polyp/pstream.c
+++ b/polyp/pstream.c
@@ -91,6 +91,8 @@ struct pa_pstream {
void (*drain_callback)(struct pa_pstream *p, void *userdata);
void *drain_userdata;
+
+ struct pa_memblock_stat *memblock_stat;
};
static void do_write(struct pa_pstream *p);
@@ -129,7 +131,7 @@ static void defer_callback(struct pa_mainloop_api *m, struct pa_defer_event *e,
do_something(p);
}
-struct pa_pstream *pa_pstream_new(struct pa_mainloop_api *m, struct pa_iochannel *io) {
+struct pa_pstream *pa_pstream_new(struct pa_mainloop_api *m, struct pa_iochannel *io, struct pa_memblock_stat *s) {
struct pa_pstream *p;
assert(io);
@@ -165,6 +167,8 @@ struct pa_pstream *pa_pstream_new(struct pa_mainloop_api *m, struct pa_iochannel
p->drain_callback = NULL;
p->drain_userdata = NULL;
+ p->memblock_stat = s;
+
return p;
}
@@ -350,7 +354,7 @@ static void do_read(struct pa_pstream *p) {
p->read.data = p->read.packet->data;
} else {
/* Frame is a memblock frame */
- p->read.memblock = pa_memblock_new(ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH]));
+ p->read.memblock = pa_memblock_new(ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH]), p->memblock_stat);
assert(p->read.memblock);
p->read.data = p->read.memblock->data;
}
diff --git a/polyp/pstream.h b/polyp/pstream.h
index ff70a855..9a289507 100644
--- a/polyp/pstream.h
+++ b/polyp/pstream.h
@@ -32,7 +32,7 @@
struct pa_pstream;
-struct pa_pstream* pa_pstream_new(struct pa_mainloop_api *m, struct pa_iochannel *io);
+struct pa_pstream* pa_pstream_new(struct pa_mainloop_api *m, struct pa_iochannel *io, struct pa_memblock_stat *s);
void pa_pstream_unref(struct pa_pstream*p);
struct pa_pstream* pa_pstream_ref(struct pa_pstream*p);
diff --git a/polyp/resampler.c b/polyp/resampler.c
index 241f97c4..ed44cbb7 100644
--- a/polyp/resampler.c
+++ b/polyp/resampler.c
@@ -43,9 +43,11 @@ struct pa_resampler {
pa_convert_to_float32_func_t to_float32_func;
pa_convert_from_float32_func_t from_float32_func;
SRC_STATE *src_state;
+
+ struct pa_memblock_stat *memblock_stat;
};
-struct pa_resampler* pa_resampler_new(const struct pa_sample_spec *a, const struct pa_sample_spec *b) {
+struct pa_resampler* pa_resampler_new(const struct pa_sample_spec *a, const struct pa_sample_spec *b, struct pa_memblock_stat *s) {
struct pa_resampler *r = NULL;
int err;
assert(a && b && pa_sample_spec_valid(a) && pa_sample_spec_valid(b));
@@ -82,6 +84,8 @@ struct pa_resampler* pa_resampler_new(const struct pa_sample_spec *a, const stru
r->from_float32_func = pa_get_convert_from_float32_function(b->format);
assert(r->to_float32_func && r->from_float32_func);
+
+ r->memblock_stat = s;
return r;
@@ -134,7 +138,7 @@ void pa_resampler_run(struct pa_resampler *r, const struct pa_memchunk *in, stru
eff_ons = ons;
}
- out->memblock = pa_memblock_new(out->length = (ons*r->o_sz));
+ out->memblock = pa_memblock_new(out->length = (ons*r->o_sz), r->memblock_stat);
out->index = 0;
assert(out->memblock);
diff --git a/polyp/resampler.h b/polyp/resampler.h
index 8e979478..e23d145d 100644
--- a/polyp/resampler.h
+++ b/polyp/resampler.h
@@ -28,7 +28,7 @@
struct pa_resampler;
-struct pa_resampler* pa_resampler_new(const struct pa_sample_spec *a, const struct pa_sample_spec *b);
+struct pa_resampler* pa_resampler_new(const struct pa_sample_spec *a, const struct pa_sample_spec *b, struct pa_memblock_stat *s);
void pa_resampler_free(struct pa_resampler *r);
size_t pa_resampler_request(struct pa_resampler *r, size_t out_length);
diff --git a/polyp/sink-input.c b/polyp/sink-input.c
index efa8c551..c57dd8e0 100644
--- a/polyp/sink-input.c
+++ b/polyp/sink-input.c
@@ -43,7 +43,7 @@ struct pa_sink_input* pa_sink_input_new(struct pa_sink *s, const char *name, con
assert(s && spec);
if (!pa_sample_spec_equal(spec, &s->sample_spec))
- if (!(resampler = pa_resampler_new(spec, &s->sample_spec)))
+ if (!(resampler = pa_resampler_new(spec, &s->sample_spec, s->core->memblock_stat)))
return NULL;
i = pa_xmalloc(sizeof(struct pa_sink_input));
diff --git a/polyp/sink.c b/polyp/sink.c
index becaef9e..62b9a7af 100644
--- a/polyp/sink.c
+++ b/polyp/sink.c
@@ -179,11 +179,11 @@ int pa_sink_render(struct pa_sink*s, size_t length, struct pa_memchunk *result)
volume = pa_volume_multiply(s->volume, info[0].volume);
if (volume != PA_VOLUME_NORM) {
- pa_memchunk_make_writable(result);
+ pa_memchunk_make_writable(result, s->core->memblock_stat);
pa_volume_memchunk(result, &s->sample_spec, volume);
}
} else {
- result->memblock = pa_memblock_new(length);
+ result->memblock = pa_memblock_new(length, s->core->memblock_stat);
assert(result->memblock);
result->length = l = pa_mix(info, n, result->memblock->data, length, &s->sample_spec, s->volume);
diff --git a/polyp/sound-file.c b/polyp/sound-file.c
index b0df7185..bf635fa0 100644
--- a/polyp/sound-file.c
+++ b/polyp/sound-file.c
@@ -8,7 +8,7 @@
#define MAX_FILE_SIZE (1024*1024)
-int pa_sound_file_load(const char *fname, struct pa_sample_spec *ss, struct pa_memchunk *chunk) {
+int pa_sound_file_load(const char *fname, struct pa_sample_spec *ss, struct pa_memchunk *chunk, struct pa_memblock_stat *s) {
SNDFILE*sf = NULL;
SF_INFO sfinfo;
int ret = -1;
@@ -39,7 +39,7 @@ int pa_sound_file_load(const char *fname, struct pa_sample_spec *ss, struct pa_m
goto finish;
}
- chunk->memblock = pa_memblock_new(l);
+ chunk->memblock = pa_memblock_new(l, s);
assert(chunk->memblock);
chunk->index = 0;
chunk->length = l;
diff --git a/polyp/sound-file.h b/polyp/sound-file.h
index 3a6fa415..62a4a371 100644
--- a/polyp/sound-file.h
+++ b/polyp/sound-file.h
@@ -4,6 +4,6 @@
#include "memchunk.h"
#include "sample.h"
-int pa_sound_file_load(const char *fname, struct pa_sample_spec *ss, struct pa_memchunk *chunk);
+int pa_sound_file_load(const char *fname, struct pa_sample_spec *ss, struct pa_memchunk *chunk, struct pa_memblock_stat *s);
#endif
diff --git a/polyp/source-output.c b/polyp/source-output.c
index c53831c7..b8083a79 100644
--- a/polyp/source-output.c
+++ b/polyp/source-output.c
@@ -38,7 +38,7 @@ struct pa_source_output* pa_source_output_new(struct pa_source *s, const char *n
assert(s && spec);
if (!pa_sample_spec_equal(&s->sample_spec, spec))
- if (!(resampler = pa_resampler_new(&s->sample_spec, spec)))
+ if (!(resampler = pa_resampler_new(&s->sample_spec, spec, s->core->memblock_stat)))
return NULL;
o = pa_xmalloc(sizeof(struct pa_source_output));