Add new debuuging API pa_memchunk_dump_to_file()
authorLennart Poettering <lennart@poettering.net>
Thu, 8 Jan 2009 20:12:03 +0000 (21:12 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 8 Jan 2009 20:12:03 +0000 (21:12 +0100)
src/pulsecore/sample-util.c
src/pulsecore/sample-util.h

index 9f0f795c647211096d6f1363a934db6f763b80c7..414c1c81c64f99ae28b91e9f34ab1846c7a573a7 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
 
 #include <liboil/liboilfuncs.h>
 #include <liboil/liboil.h>
@@ -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);
+}
index 2fe2c81d7a48ad1e3f348ee49f615479659f9dc3..36d19e480c7450b95ce869d7bf296959e612628f 100644 (file)
@@ -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