]> code.delx.au - pulseaudio/blob - src/pulsecore/mcalign.h
commit glitch-free work
[pulseaudio] / src / pulsecore / mcalign.h
1 #ifndef foomcalignhfoo
2 #define foomcalignhfoo
3
4 /* $Id$ */
5
6 /***
7 This file is part of PulseAudio.
8
9 Copyright 2004-2006 Lennart Poettering
10
11 PulseAudio is free software; you can redistribute it and/or modify
12 it under the terms of the GNU Lesser General Public License as
13 published by the Free Software Foundation; either version 2.1 of the
14 License, or (at your option) any later version.
15
16 PulseAudio is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
20
21 You should have received a copy of the GNU Lesser General Public
22 License along with PulseAudio; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 USA.
25 ***/
26
27 #include <pulsecore/memblock.h>
28 #include <pulsecore/memchunk.h>
29
30 /* An alignment object, used for aligning memchunks to multiples of
31 * the frame size. */
32
33 /* Method of operation: the user creates a new mcalign object by
34 * calling pa_mcalign_new() with the appropriate aligning
35 * granularity. After that he may call pa_mcalign_push() for an input
36 * memchunk. After exactly one memchunk the user has to call
37 * pa_mcalign_pop() until it returns -1. If pa_mcalign_pop() returns
38 * 0, the memchunk *c is valid and aligned to the granularity. Some
39 * pseudocode illustrating this:
40 *
41 * pa_mcalign *a = pa_mcalign_new(4, NULL);
42 *
43 * for (;;) {
44 * pa_memchunk input;
45 *
46 * ... fill input ...
47 *
48 * pa_mcalign_push(m, &input);
49 * pa_memblock_unref(input.memblock);
50 *
51 * for (;;) {
52 * pa_memchunk output;
53 *
54 * if (pa_mcalign_pop(m, &output) < 0)
55 * break;
56 *
57 * ... consume output ...
58 *
59 * pa_memblock_unref(output.memblock);
60 * }
61 * }
62 *
63 * pa_memchunk_free(a);
64 * */
65
66 typedef struct pa_mcalign pa_mcalign;
67
68 pa_mcalign *pa_mcalign_new(size_t base);
69 void pa_mcalign_free(pa_mcalign *m);
70
71 /* Push a new memchunk into the aligner. The caller of this routine
72 * has to free the memchunk by himself. */
73 void pa_mcalign_push(pa_mcalign *m, const pa_memchunk *c);
74
75 /* Pop a new memchunk from the aligner. Returns 0 when sucessful,
76 * nonzero otherwise. */
77 int pa_mcalign_pop(pa_mcalign *m, pa_memchunk *c);
78
79 /* If we pass l bytes in now, how many bytes would we get out? */
80 size_t pa_mcalign_csize(pa_mcalign *m, size_t l);
81
82 /* Flush what's still stored in the aligner */
83 void pa_mcalign_flush(pa_mcalign *m);
84
85 #endif