[FFmpeg-devel] [RFC] LPCM 24 bits support

Lars Täuber lars.taeuber
Fri Apr 18 21:05:23 CEST 2008


On Fri, 18 Apr 2008 15:39:43 +0200 Michael Niedermayer <michaelni at gmx.at> wrote:
> On Thu, Apr 17, 2008 at 10:13:40PM +0200, Lars T?uber wrote:
> > On Thu, 17 Apr 2008 22:49:08 +0200 Michael Niedermayer <michaelni at gmx.at> wrote:
> > > On Thu, Apr 17, 2008 at 09:10:07PM +0100, M?ns Rullg?rd wrote:
[...]
> > diff -pur ffmpeg/libavcodec/pcm.c ffmpeg.1/libavcodec/pcm.c
> > --- ffmpeg/libavcodec/pcm.c	2008-03-21 13:17:05.000000000 +0100
> > +++ ffmpeg.1/libavcodec/pcm.c	2008-04-17 21:46:27.000000000 +0200
> > @@ -492,6 +498,31 @@ static int pcm_decode_frame(AVCodecConte
> >              *samples++ = s->table[*src++];
> >          }
> >          break;
> > +    case CODEC_ID_PCM_DVD: {
> > +            int audio24[8*2], *ap;
> > +            const uint8_t *src_LSB;
> > +
> 
> > +            n = buf_size / (avctx->channels * 2 * avctx->bits_per_sample / 8);
> 
> Is there something that prevents that from overflowing? If not then this is a
> little risky

I'm not sure what you mean, but all values are calculated in libavformat/mpeg.c during parsing:

        st->codec->channels = 1 + (b1 & 7);
        st->codec->bits_per_sample = 16 + ((b1 >> 6) & 3) * 4;

and 2 * bits_per_sample is always dividable by 8 because
bits_per_sample is 16 xor 20 xor 24

buf_size is given at call and then
buf_size= FFMIN(buf_size, *data_size/2)

> 
> 
> > +            while (n--) {
> > +                ap = audio24;
> > +                src_LSB = src + avctx->channels * 2 * 2;
> > +
> 
> > +                if (avctx->bits_per_sample == 20)
> > +                    for (c=0; c < avctx->channels; c++, src+=4, src_LSB++ ) {
> > +                        *ap++ = src[0]<<16 | src[1]<<8 | (*src_LSB & 0xf0);
> > +                        *ap++ = src[2]<<16 | src[3]<<8 | (*src_LSB & 0x0f)<<4;
> > +                    }
> 
> Is there something that prevents channels from being larger than 8?

Yes, because it's calculated as shown above. (There are only 3 bits that tell the number of channels)

> The array should either be sized related to MAX_CHANNELS or channels be
> checked against the size of the array.

the widest sample size is 24 bits*channels => fit into int
channels <= 8
exactly 2 samples per block
=> max 2*8 ints/block

Is that enough to be safe?
Lars
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pcm_dvd.Makefile.diff
Type: text/x-diff
Size: 559 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080418/0f43be95/attachment.diff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pcm_dvd.mpeg.diff
Type: text/x-diff
Size: 1471 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080418/0f43be95/attachment-0001.diff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pcm_dvd.pcm.diff
Type: text/x-diff
Size: 2594 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080418/0f43be95/attachment-0002.diff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sanity_check.pcm.diff
Type: text/x-diff
Size: 1127 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080418/0f43be95/attachment-0003.diff>



More information about the ffmpeg-devel mailing list