• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef foomcalignhfoo
2 #define foomcalignhfoo
3 
4 /***
5   This file is part of PulseAudio.
6 
7   Copyright 2004-2006 Lennart Poettering
8 
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.
13 
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.
18 
19   You should have received a copy of the GNU Lesser General Public
20   License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
21 ***/
22 
23 #include <pulsecore/memblock.h>
24 #include <pulsecore/memchunk.h>
25 
26 /* An alignment object, used for aligning memchunks to multiples of
27  * the frame size. */
28 
29 /* Method of operation: the user creates a new mcalign object by
30  * calling pa_mcalign_new() with the appropriate aligning
31  * granularity. After that they may call pa_mcalign_push() for an input
32  * memchunk. After exactly one memchunk the user has to call
33  * pa_mcalign_pop() until it returns -1. If pa_mcalign_pop() returns
34  * 0, the memchunk *c is valid and aligned to the granularity. Some
35  * pseudocode illustrating this:
36  *
37  * pa_mcalign *a = pa_mcalign_new(4, NULL);
38  *
39  * for (;;) {
40  *   pa_memchunk input;
41  *
42  *   ... fill input ...
43  *
44  *   pa_mcalign_push(m, &input);
45  *   pa_memblock_unref(input.memblock);
46  *
47  *   for (;;) {
48  *     pa_memchunk output;
49  *
50  *     if (pa_mcalign_pop(m, &output) < 0)
51  *       break;
52  *
53  *     ... consume output ...
54  *
55  *     pa_memblock_unref(output.memblock);
56  *   }
57  * }
58  *
59  * pa_memchunk_free(a);
60  * */
61 
62 typedef struct pa_mcalign pa_mcalign;
63 
64 pa_mcalign *pa_mcalign_new(size_t base);
65 void pa_mcalign_free(pa_mcalign *m);
66 
67 /* Push a new memchunk into the aligner. The caller of this routine
68  * has to free the memchunk by himself. */
69 void pa_mcalign_push(pa_mcalign *m, const pa_memchunk *c);
70 
71 /* Pop a new memchunk from the aligner. Returns 0 when successful,
72  * nonzero otherwise. */
73 int pa_mcalign_pop(pa_mcalign *m, pa_memchunk *c);
74 
75 /* If we pass l bytes in now, how many bytes would we get out? */
76 size_t pa_mcalign_csize(pa_mcalign *m, size_t l);
77 
78 /* Flush what's still stored in the aligner */
79 void pa_mcalign_flush(pa_mcalign *m);
80 
81 #endif
82