[pulseaudio-discuss] [PATCH 09/11] resampler: Extend fit_buf() helper to copy leftover data to new buffer

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Fri Nov 8 06:53:39 PST 2013


On Sun, 2013-07-21 at 23:14 +0200, Peter Meerwald wrote:
> Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
> ---
>  src/pulsecore/resampler.c | 40 +++++++++++++++++++---------------------
>  1 file changed, 19 insertions(+), 21 deletions(-)
> 
> diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
> index 2cbcc52..3cb4e8a 100644
> --- a/src/pulsecore/resampler.c
> +++ b/src/pulsecore/resampler.c
> @@ -1029,13 +1029,26 @@ static void calc_map_table(pa_resampler *r) {
>      pa_init_remap(m);
>  }
>  
> -static size_t fit_buf(pa_resampler *r, pa_memchunk *buf, size_t size) {
> +/* check if buf's memblock is large enough to hold 'size' bytes; create a
> + * new memblock if necessary and optionally preserve 'copy' data bytes */

The comment is incorrect: the function doesn't check if buf's memblock
is large enough to hold 'size' bytes. What it does is to check if buf's
memblock is large enough to hold 'buf->length' bytes, and the caller is
expected to tell the current memblock size with the 'size' variable.
(Perhaps "current_block_size" would be a more informative variable
name?)

I wonder if it would be possible to change the code match the comment
instead of changing the comment to match the code, since the comment
that you wrote describes a much saner system...

> +static size_t fit_buf(pa_resampler *r, pa_memchunk *buf, size_t size, size_t copy) {
>      if (!buf->memblock || size < buf->length) {
>          size = buf->length;
> +        pa_memblock *new_block = pa_memblock_new(r->mempool, size);

  CC       pulsecore/libpulsecore_4.0_la-resampler.lo
pulsecore/resampler.c: In function 'fit_buf':
pulsecore/resampler.c:1149:9: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
         pa_memblock *new_block = pa_memblock_new(r->mempool, size);
         ^

Please put variable declarations to the beginning of a code block.

There was also a fit_buf() call in convert_to_work_format() that was
updated only in a later patch, so this patch didn't compile.

-- 
Tanu



More information about the pulseaudio-discuss mailing list