[FFmpeg-devel] [PATCH] ALAC Encoder

Jai Menon realityman
Sun Aug 17 07:47:10 CEST 2008


Hi,

On Sunday 17 Aug 2008 8:05:14 am Michael Niedermayer wrote:
> On Sun, Aug 17, 2008 at 04:14:43AM +0530, Jai Menon wrote:
> > Hi,
> >
> > The attached ALAC encoder was written as part of GSoC and mentored by
> > Justin Ruggles. I'm posting it for inclusion into FFmpeg-svn.
>
> [...]
>
> > +static void alac_linear_predictor(AlacEncodeContext *s, int ch)
> > +{
> > +    int i;
> > +    LPCContext lpc = s->lpc[ch];
> > +
> > +    if(lpc.lpc_order == 31) {
> > +        s->predictor_buf[0] = s->sample_buf[ch][0];
> >
> > +        i = s->avctx->frame_size - 1;
> > +        while(i > 0) {
> > +            s->predictor_buf[i] = s->sample_buf[ch][i] -
> > s->sample_buf[ch][i-1]; 
> > +            i--; 
> > +        }
>
> i suspect that 0 .. n is faster than n .. 0
>

I'll need a temp variable in that case.   Is that okay?

>
> [...]
> >
> > +    if(buf_size < s->max_coded_frame_size) {
> > +        av_log(avctx, AV_LOG_ERROR, "buffer size is too small\n");
> > +        return -1;
> > +    }
> > +
> > +    init_put_bits(pb, frame, buf_size);
> > +
> > +    if(s->compression_level == 0) {
> > +        // Verbatim mode
> > +        int16_t *samples = data;
> > +        write_frame_header(s, 1);
> > +        for(i=0; i<avctx->frame_size*s->channels; i++) {
> > +            put_sbits(pb, 16, *samples++);
> > +        }
> > +    } else {
> > +        init_sample_buffers(s, data);
> > +        write_frame_header(s, 0);
> > +        write_compressed_frame(s);
> > +    }
> > +
> > +    put_bits(pb, 3, 7);
> > +    flush_put_bits(pb);
> > +    out_bytes = put_bits_count(pb) >> 3;
> > +
> > +    if(out_bytes > s->max_coded_frame_size) {
>
> At this point it is possible that the encoder wrote over the end of the
> array, the check farther up should ensure that there really is enough
> space available even for larger then optimal frames
>

I'm not sure If I understand this comment correctly. We already check to see 
if buf_size < max_coded_frame_size. So it would not write past the end.
This check here would take care of reencoding in verbatim mode if actual 
output was > max_coded_frame_size. It handles this case similar to the flac 
encoder.

Regards,

Jai Menon




More information about the ffmpeg-devel mailing list