From aff7768fb1076b53bc8416fdbdcc454e4b52ec41 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 8 Jan 2009 21:12:03 +0100 Subject: Add new debuuging API pa_memchunk_dump_to_file() --- src/pulsecore/sample-util.c | 27 +++++++++++++++++++++++++++ src/pulsecore/sample-util.h | 2 ++ 2 files changed, 29 insertions(+) (limited to 'src/pulsecore') diff --git a/src/pulsecore/sample-util.c b/src/pulsecore/sample-util.c index 9f0f795c..414c1c81 100644 --- a/src/pulsecore/sample-util.c +++ b/src/pulsecore/sample-util.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -987,3 +988,29 @@ size_t pa_usec_to_bytes_round_up(pa_usec_t t, const pa_sample_spec *spec) { return (size_t) u; } + +void pa_memchunk_dump_to_file(pa_memchunk *c, const char *fn) { + FILE *f; + void *p; + + pa_assert(c); + pa_assert(fn); + + /* Only for debugging purposes */ + + f = fopen(fn, "a"); + + if (!f) { + pa_log_warn("Failed to open '%s': %s", fn, pa_cstrerror(errno)); + return; + } + + p = pa_memblock_acquire(c->memblock); + + if (fwrite((uint8_t*) p + c->index, 1, c->length, f) != c->length) + pa_log_warn("Failed to write to '%s': %s", fn, pa_cstrerror(errno)); + + pa_memblock_release(c->memblock); + + fclose(f); +} diff --git a/src/pulsecore/sample-util.h b/src/pulsecore/sample-util.h index 2fe2c81d..36d19e48 100644 --- a/src/pulsecore/sample-util.h +++ b/src/pulsecore/sample-util.h @@ -81,4 +81,6 @@ void pa_sample_clamp(pa_sample_format_t format, void *dst, size_t dstr, const vo pa_usec_t pa_bytes_to_usec_round_up(uint64_t length, const pa_sample_spec *spec); 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); + #endif -- cgit