[MPlayer-dev-eng] [PATCH] latm faad handling

Reimar Döffinger Reimar.Doeffinger at gmx.de
Mon Jun 21 18:48:56 CEST 2010


On Mon, Jun 21, 2010 at 06:16:40PM +0200, Dan Oscarsson wrote:
> On 2010-06-17 at 22:05 +0200 Reimar Döffinger wrote:
> > On Wed, Jun 16, 2010 at 09:14:05PM +0200, Dan Oscarsson wrote:
> > > +    if (faac_init < 0 && sh->format == mmioFOURCC('M', 'P', '4', 'L')) {
> > > +        // working LATM not found at first try, look further on in stream
> > > +        for (int i = 0; i < 5; i++) {
> > 
> > Move the "int" out, this will not work with some older compilers.
> > 
> > > +            pos = sh->a_in_buffer_len-3;
> > 
> > This can overflow (or rather underfflow).
> > 
> > > +            memmove(sh->a_in_buffer, &(sh->a_in_buffer[pos]), 3);
> > 
> > Pointless ().
> > 
> 
> Fixed in the attached updated patch.

Applied the demux_ts part.
Does someone know what this patch will cause to happen if the LATM
demuxing support is enabled in the libavformat demuxer and it does
not use a separate codec id for LATM?

> --- libmpcodecs/ad_faad.c.org	2010-06-12 17:25:38.999522927 +0200
> +++ libmpcodecs/ad_faad.c	2010-06-21 18:00:21.204759059 +0200
> @@ -126,6 +126,27 @@
>      faacDecSetConfiguration(faac_hdec, faac_conf);
>  
>      sh->a_in_buffer_len = demux_read_data(sh->ds, sh->a_in_buffer, sh->a_in_buffer_size);
> +    /* init the codec, look for LATM */
> +    faac_init = faacDecInit(faac_hdec, sh->a_in_buffer,
> +                            sh->a_in_buffer_len, &faac_samplerate, &faac_channels,1);
> +    if (faac_init < 0 && sh->format == mmioFOURCC('M', 'P', '4', 'L')) {
> +        // working LATM not found at first try, look further on in stream
> +        int i;
> +
> +        for (i = 0; i < 5 && sh->a_in_buffer_len >= 3; i++) {
> +            pos = sh->a_in_buffer_len-3;
> +            memmove(sh->a_in_buffer, &(sh->a_in_buffer[pos]), 3);
> +            sh->a_in_buffer_len  = 3;

sh->a_in_buffer_len >= 3 should always be true except possibly during the first iteration,
so this check can go into the first if (though it might actually be better to call demux_read_data
in a loop untile we get enough data, and I really suspect 3 bytes are not enough for faacDecInit
in general...)

> +            sh->a_in_buffer_len += demux_read_data(sh->ds,&sh->a_in_buffer[sh->a_in_buffer_len],
> +                                                   sh->a_in_buffer_size - sh->a_in_buffer_len);

This may cause an endless loop if demux_read_data always returns 0 due to reaching eof.

> +            pos = 0;

Setting this to 0 inside the loop seems pointless...



More information about the MPlayer-dev-eng mailing list