[vlc-devel] [PATCH 2/2] avcodec: initialize buffers when first frame comes in

Denis Charmet typx at dinauz.org
Fri Sep 20 11:32:01 CEST 2013


Hi,

Le vendredi 20 septembre 2013 à 11:33:17, Ilkka Ollakka a écrit :
> @@ -1122,6 +1110,29 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
>      int got_packet,i_out;
>      size_t buffer_delay = 0, i_samples_left = 0;
>  
> +    /* Take buffers only when first frame arrives, as for example
> +     * faad sometimes has channels count only at this point*/
> +    if( unlikely( p_sys->i_buffer_out == 0 ) )
> +    {
> +        p_sys->i_buffer_out = p_sys->i_frame_size * p_sys->i_sample_bytes * p_enc->fmt_in.audio.i_channels;
> +        p_sys->p_buffer = malloc( p_sys->i_buffer_out );
> +        if ( unlikely( p_sys->p_buffer == NULL ) )
> +        {
> +            p_sys->i_buffer_out = 0;
> +            return NULL;
> +        }
> +
> +        if( p_sys->b_planar )
> +        {
> +            p_sys->p_interleave_buf = malloc( p_sys->i_buffer_out );
> +            if( unlikely( p_sys->p_interleave_buf == NULL ) )
> +            {
> +                p_sys->i_buffer_out = 0;
This would leak  p_sys->p_buffer next time the function is called.
> +                return NULL;
> +            }
> +        }
> +    }
> +
>      //i_bytes_left is amount of bytes we get
>      i_samples_left = p_aout_buf ? p_aout_buf->i_nb_samples : 0;
>      buffer_delay = p_sys->i_samples_delay * p_sys->i_sample_bytes * p_enc->fmt_in.audio.i_channels;

Regards,

-- 
Denis Charmet - TypX
Le mauvais esprit est un art de vivre



More information about the vlc-devel mailing list