[FFmpeg-devel] [PATCH] Bitstream filter DTS from any format to 14bit format.

Bartlomiej Wolowiec bartek.wolowiec
Thu Aug 6 16:43:41 CEST 2009


Wednesday 05 August 2009 13:33:58 M?ns Rullg?rd napisa?(a):
> Bartlomiej Wolowiec <bartek.wolowiec at gmail.com> writes:
> > Tuesday 04 August 2009 22:29:55 M?ns Rullg?rd napisa?(a):
> >> Bartlomiej Wolowiec <bartek.wolowiec at gmail.com> writes:
> >> > Hi,
> >> > Here is a small bitstream filter, which may be useful for someone.
[...]
> > +static int dts14b_filter(AVBitStreamFilterContext * bsfc,
> > +                         AVCodecContext * avctx, const char *args,
> > +                         uint8_t ** poutbuf, int *poutbuf_size,
> > +                         const uint8_t * buf, int buf_size, int
> > keyframe) +{
> > +    GetBitContext gb;
> > +    int dca_buffer_size;
> > +    uint8_t dca_buffer[DCA_MAX_FRAME_SIZE];
> > +    uint16_t *pout;
> > +
> > +    dca_buffer_size =
> > +        ff_dca_convert_bitstream(buf, buf_size, dca_buffer,
> > +                                 DCA_MAX_FRAME_SIZE);
>
> Would it be worthwhile to check if the source is already in the
> desired format, or shall we assume the user wouldn't ask for
> conversion in that case?

I think its unnecessary complication...

> > +    if (dca_buffer_size == -1) {
> > +        av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n");
> > +        return -1;
> > +    }
> > +
> > +    *poutbuf_size = ((dca_buffer_size + 13) / 14) << 4;
>
> Shouldn't this be (((dca_buffer_size << 3) + 13) / 14) << 1, or am I
> missing some trick?

((dca_buffer_size + 13) / 14) << 4 contains padding size

> > +    *poutbuf = av_malloc(*poutbuf_size + FF_INPUT_BUFFER_PADDING_SIZE);
> > +    pout = (uint16_t *) * poutbuf;
>
>                             ^
> Please drop that space -----+ like this:
>
> +    pout = (uint16_t *) *poutbuf
>
> It's not multiplication...
>
> > +    init_get_bits(&gb, dca_buffer, dca_buffer_size);
> > +    while (get_bits_count(&gb) < dca_buffer_size << 3)
>
> This can over-read the end of the input buffer.  You should add a few
> bytes padding to be safe.

Yes, it may over-read two bytes. I corrected it.

> > +        *pout++ = be2me_16(get_sbits(&gb, 14));
> > +
> > +    while (((uint8_t *) pout - *poutbuf) & 7)
> > +        *pout++ = 0;
>
> Shouldn't the tail padding be included in the returned size?

I hope that returning size includes tail padding ;)

-- 
Bartlomiej Wolowiec
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch2
Type: text/x-diff
Size: 3839 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090806/0063f942/attachment.diff>



More information about the ffmpeg-devel mailing list