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

Michael Niedermayer michaelni
Fri Apr 18 22:08:24 CEST 2008


On Fri, Apr 18, 2008 at 09:05:23PM +0200, Lars T?uber wrote:
> 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?

Well, what if someone would store CODEC_ID_PCM_DVD in for example .mkv .avi
.mov  ...

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If you really think that XML is the answer, then you definitly missunderstood
the question -- Attila Kinali
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080418/f2074787/attachment.pgp>



More information about the ffmpeg-devel mailing list