2 This file is part of PulseAudio.
4 PulseAudio is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 PulseAudio is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with PulseAudio; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <sys/types.h>
32 #include <pulse/gccmacro.h>
34 #include <pulsecore/core-util.h>
35 #include <pulsecore/mcalign.h>
37 /* A simple program for testing pa_mcalign */
39 int main(int argc, char *argv[]) {
44 p = pa_mempool_new(0);
46 a = pa_mcalign_new(11);
48 pa_memchunk_reset(&c);
57 c.memblock = pa_memblock_new(p, 2048);
58 c.index = c.length = 0;
61 assert(c.index < pa_memblock_get_length(c.memblock));
63 l = pa_memblock_get_length(c.memblock) - c.index;
65 l = l <= 1 ? l : rand() % (l-1) +1 ;
67 p = pa_memblock_acquire(c.memblock);
69 if ((r = read(STDIN_FILENO, (uint8_t*) p + c.index, l)) <= 0) {
70 pa_memblock_release(c.memblock);
71 fprintf(stderr, "read() failed: %s\n", r < 0 ? strerror(errno) : "EOF");
75 pa_memblock_release(c.memblock);
78 pa_mcalign_push(a, &c);
79 fprintf(stderr, "Read %ld bytes\n", (long)r);
83 if (c.index >= pa_memblock_get_length(c.memblock)) {
84 pa_memblock_unref(c.memblock);
85 pa_memchunk_reset(&c);
91 if (pa_mcalign_pop(a, &t) < 0)
94 p = pa_memblock_acquire(t.memblock);
95 pa_loop_write(STDOUT_FILENO, (uint8_t*) p + t.index, t.length, NULL);
96 pa_memblock_release(t.memblock);
97 fprintf(stderr, "Wrote %lu bytes.\n", (unsigned long) t.length);
99 pa_memblock_unref(t.memblock);
106 pa_memblock_unref(c.memblock);