153a5a1b3Sopenharmony_ci#ifndef foomcalignhfoo 253a5a1b3Sopenharmony_ci#define foomcalignhfoo 353a5a1b3Sopenharmony_ci 453a5a1b3Sopenharmony_ci/*** 553a5a1b3Sopenharmony_ci This file is part of PulseAudio. 653a5a1b3Sopenharmony_ci 753a5a1b3Sopenharmony_ci Copyright 2004-2006 Lennart Poettering 853a5a1b3Sopenharmony_ci 953a5a1b3Sopenharmony_ci PulseAudio is free software; you can redistribute it and/or modify 1053a5a1b3Sopenharmony_ci it under the terms of the GNU Lesser General Public License as 1153a5a1b3Sopenharmony_ci published by the Free Software Foundation; either version 2.1 of the 1253a5a1b3Sopenharmony_ci License, or (at your option) any later version. 1353a5a1b3Sopenharmony_ci 1453a5a1b3Sopenharmony_ci PulseAudio is distributed in the hope that it will be useful, but 1553a5a1b3Sopenharmony_ci WITHOUT ANY WARRANTY; without even the implied warranty of 1653a5a1b3Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1753a5a1b3Sopenharmony_ci Lesser General Public License for more details. 1853a5a1b3Sopenharmony_ci 1953a5a1b3Sopenharmony_ci You should have received a copy of the GNU Lesser General Public 2053a5a1b3Sopenharmony_ci License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>. 2153a5a1b3Sopenharmony_ci***/ 2253a5a1b3Sopenharmony_ci 2353a5a1b3Sopenharmony_ci#include <pulsecore/memblock.h> 2453a5a1b3Sopenharmony_ci#include <pulsecore/memchunk.h> 2553a5a1b3Sopenharmony_ci 2653a5a1b3Sopenharmony_ci/* An alignment object, used for aligning memchunks to multiples of 2753a5a1b3Sopenharmony_ci * the frame size. */ 2853a5a1b3Sopenharmony_ci 2953a5a1b3Sopenharmony_ci/* Method of operation: the user creates a new mcalign object by 3053a5a1b3Sopenharmony_ci * calling pa_mcalign_new() with the appropriate aligning 3153a5a1b3Sopenharmony_ci * granularity. After that they may call pa_mcalign_push() for an input 3253a5a1b3Sopenharmony_ci * memchunk. After exactly one memchunk the user has to call 3353a5a1b3Sopenharmony_ci * pa_mcalign_pop() until it returns -1. If pa_mcalign_pop() returns 3453a5a1b3Sopenharmony_ci * 0, the memchunk *c is valid and aligned to the granularity. Some 3553a5a1b3Sopenharmony_ci * pseudocode illustrating this: 3653a5a1b3Sopenharmony_ci * 3753a5a1b3Sopenharmony_ci * pa_mcalign *a = pa_mcalign_new(4, NULL); 3853a5a1b3Sopenharmony_ci * 3953a5a1b3Sopenharmony_ci * for (;;) { 4053a5a1b3Sopenharmony_ci * pa_memchunk input; 4153a5a1b3Sopenharmony_ci * 4253a5a1b3Sopenharmony_ci * ... fill input ... 4353a5a1b3Sopenharmony_ci * 4453a5a1b3Sopenharmony_ci * pa_mcalign_push(m, &input); 4553a5a1b3Sopenharmony_ci * pa_memblock_unref(input.memblock); 4653a5a1b3Sopenharmony_ci * 4753a5a1b3Sopenharmony_ci * for (;;) { 4853a5a1b3Sopenharmony_ci * pa_memchunk output; 4953a5a1b3Sopenharmony_ci * 5053a5a1b3Sopenharmony_ci * if (pa_mcalign_pop(m, &output) < 0) 5153a5a1b3Sopenharmony_ci * break; 5253a5a1b3Sopenharmony_ci * 5353a5a1b3Sopenharmony_ci * ... consume output ... 5453a5a1b3Sopenharmony_ci * 5553a5a1b3Sopenharmony_ci * pa_memblock_unref(output.memblock); 5653a5a1b3Sopenharmony_ci * } 5753a5a1b3Sopenharmony_ci * } 5853a5a1b3Sopenharmony_ci * 5953a5a1b3Sopenharmony_ci * pa_memchunk_free(a); 6053a5a1b3Sopenharmony_ci * */ 6153a5a1b3Sopenharmony_ci 6253a5a1b3Sopenharmony_citypedef struct pa_mcalign pa_mcalign; 6353a5a1b3Sopenharmony_ci 6453a5a1b3Sopenharmony_cipa_mcalign *pa_mcalign_new(size_t base); 6553a5a1b3Sopenharmony_civoid pa_mcalign_free(pa_mcalign *m); 6653a5a1b3Sopenharmony_ci 6753a5a1b3Sopenharmony_ci/* Push a new memchunk into the aligner. The caller of this routine 6853a5a1b3Sopenharmony_ci * has to free the memchunk by himself. */ 6953a5a1b3Sopenharmony_civoid pa_mcalign_push(pa_mcalign *m, const pa_memchunk *c); 7053a5a1b3Sopenharmony_ci 7153a5a1b3Sopenharmony_ci/* Pop a new memchunk from the aligner. Returns 0 when successful, 7253a5a1b3Sopenharmony_ci * nonzero otherwise. */ 7353a5a1b3Sopenharmony_ciint pa_mcalign_pop(pa_mcalign *m, pa_memchunk *c); 7453a5a1b3Sopenharmony_ci 7553a5a1b3Sopenharmony_ci/* If we pass l bytes in now, how many bytes would we get out? */ 7653a5a1b3Sopenharmony_cisize_t pa_mcalign_csize(pa_mcalign *m, size_t l); 7753a5a1b3Sopenharmony_ci 7853a5a1b3Sopenharmony_ci/* Flush what's still stored in the aligner */ 7953a5a1b3Sopenharmony_civoid pa_mcalign_flush(pa_mcalign *m); 8053a5a1b3Sopenharmony_ci 8153a5a1b3Sopenharmony_ci#endif 82