[vlc-devel] [PATCH] headphone: fix overflow buffer handling

Tristan Matthews le.businessman at gmail.com
Sat May 24 23:10:44 CEST 2014


On Sat, May 24, 2014 at 4:51 PM, Tristan Matthews
<le.businessman at gmail.com> wrote:
> Fixes #11502
> ---
>  modules/audio_filter/channel_mixer/headphone.c | 34 ++++++++++++++------------
>  1 file changed, 18 insertions(+), 16 deletions(-)
>
> diff --git a/modules/audio_filter/channel_mixer/headphone.c b/modules/audio_filter/channel_mixer/headphone.c
> index 73180dd..1e1f726 100644
> --- a/modules/audio_filter/channel_mixer/headphone.c
> +++ b/modules/audio_filter/channel_mixer/headphone.c
> @@ -338,8 +338,9 @@ static void DoWork( filter_t * p_filter,
>
>      float * p_in = (float*) p_in_buf->p_buffer;
>      float * p_out;
> -    float * p_overflow;
> -    float * p_slide;
> +    uint8_t * p_overflow;
> +    uint8_t * p_end_overflow;
> +    uint8_t * p_slide;
>
>      size_t i_overflow_size;     /* in bytes */
>      size_t i_out_size;          /* in bytes */
> @@ -355,32 +356,33 @@ static void DoWork( filter_t * p_filter,
>      i_out_size = p_out_buf->i_buffer;
>
>      /* Slide the overflow buffer */
> -    p_overflow = p_sys->p_overflow_buffer;
> +    p_overflow = (uint8_t *) p_sys->p_overflow_buffer;
>      i_overflow_size = p_sys->i_overflow_buffer_size;
> +    p_end_overflow = p_overflow + i_overflow_size;
>
>      memset( p_out, 0, i_out_size );
> -    if ( i_out_size > i_overflow_size )
> -        memcpy( p_out, p_overflow, i_overflow_size );
> -    else
> -        memcpy( p_out, p_overflow, i_out_size );
> +    memcpy( p_out, p_overflow, __MIN(i_out_size, i_overflow_size) );
>
> -    p_slide = p_sys->p_overflow_buffer;
> -    while( p_slide < p_overflow + i_overflow_size )
> +    p_slide = (uint8_t *) p_sys->p_overflow_buffer;
> +    while( p_slide < p_end_overflow )
>      {
> -        if( p_slide + i_out_size < p_overflow + i_overflow_size )
> +        size_t i_bytes_copied;
> +
> +        if( p_slide + i_out_size < p_end_overflow )
>          {
>              memset( p_slide, 0, i_out_size );
> -            if( p_slide + 2 * i_out_size < p_overflow + i_overflow_size )
> -                memcpy( p_slide, p_slide + i_out_size, i_out_size );
> +            if( p_slide + 2 * i_out_size < p_end_overflow )
> +                i_bytes_copied = i_out_size;
>              else
> -                memcpy( p_slide, p_slide + i_out_size,
> -                        p_overflow + i_overflow_size - ( p_slide + i_out_size ) );
> +                i_bytes_copied = p_overflow + i_overflow_size - ( p_slide + i_out_size );
> +            memcpy( p_slide, p_slide + i_out_size, i_bytes_copied );

Just realized I can reuse p_end_overflow here...

>          }
>          else
>          {
> -            memset( p_slide, 0, p_overflow + i_overflow_size - p_slide );
> +            i_bytes_copied = p_overflow + i_overflow_size - p_slide;

...and here.

> +            memset( p_slide, 0, i_bytes_copied );
>          }
> -        p_slide += i_out_size;
> +        p_slide += i_bytes_copied;
>      }
>
>      /* apply the atomic operations */
> --
> 1.9.0
>



More information about the vlc-devel mailing list