5 This file is part of PulseAudio.
7 Copyright 2004-2006 Lennart Poettering
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as
11 published by the Free Software Foundation; either version 2.1 of the
12 License, or (at your option) any later version.
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 #include <pulsecore/memblock.h>
26 #include <pulsecore/memchunk.h>
28 /* An alignment object, used for aligning memchunks to multiples of
31 /* Method of operation: the user creates a new mcalign object by
32 * calling pa_mcalign_new() with the appropriate aligning
33 * granularity. After that he may call pa_mcalign_push() for an input
34 * memchunk. After exactly one memchunk the user has to call
35 * pa_mcalign_pop() until it returns -1. If pa_mcalign_pop() returns
36 * 0, the memchunk *c is valid and aligned to the granularity. Some
37 * pseudocode illustrating this:
39 * pa_mcalign *a = pa_mcalign_new(4, NULL);
46 * pa_mcalign_push(m, &input);
47 * pa_memblock_unref(input.memblock);
52 * if (pa_mcalign_pop(m, &output) < 0)
55 * ... consume output ...
57 * pa_memblock_unref(output.memblock);
61 * pa_memchunk_free(a);
64 typedef struct pa_mcalign pa_mcalign;
66 pa_mcalign *pa_mcalign_new(size_t base);
67 void pa_mcalign_free(pa_mcalign *m);
69 /* Push a new memchunk into the aligner. The caller of this routine
70 * has to free the memchunk by himself. */
71 void pa_mcalign_push(pa_mcalign *m, const pa_memchunk *c);
73 /* Pop a new memchunk from the aligner. Returns 0 when sucessful,
74 * nonzero otherwise. */
75 int pa_mcalign_pop(pa_mcalign *m, pa_memchunk *c);
77 /* If we pass l bytes in now, how many bytes would we get out? */
78 size_t pa_mcalign_csize(pa_mcalign *m, size_t l);
80 /* Flush what's still stored in the aligner */
81 void pa_mcalign_flush(pa_mcalign *m);