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

Bartlomiej Wolowiec bartek.wolowiec
Thu Aug 13 12:38:58 CEST 2009


Saturday 08 August 2009 03:53:11 Michael Niedermayer napisa?(a):
> On Thu, Aug 06, 2009 at 04:43:41PM +0200, Bartlomiej Wolowiec wrote:
> > 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
> >
> >  Changelog               |    1
> >  libavcodec/Makefile     |    1
> >  libavcodec/allcodecs.c  |    1
> >  libavcodec/dts14b_bsf.c |   64
> > ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 67
> > insertions(+)
> > 230ae63bdbc658d1b1a434794ce7a220f6cd9042  patch2
> > Index: libavcodec/dts14b_bsf.c
> > ===================================================================
> > --- libavcodec/dts14b_bsf.c	(wersja 0)
> > +++ libavcodec/dts14b_bsf.c	(wersja 0)
> > @@ -0,0 +1,64 @@
> > +/*
> > + * DTS RAW to DTS 14B bitstream filter
> > + * Copyright (c) 2009 Bartlomiej Wolowiec <bartek.wolowiec at gmail.com>
> > + *
> > + * This file is part of FFmpeg.
> > + *
> > + * FFmpeg is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU Lesser General Public
> > + * License as published by the Free Software Foundation; either
> > + * version 2.1 of the License, or (at your option) any later version.
> > + *
> > + * FFmpeg is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > + * Lesser General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU Lesser General Public
> > + * License along with FFmpeg; if not, write to the Free Software
> > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> > 02110-1301 USA + */
> > +
> > +#include "avcodec.h"
> > +#include "get_bits.h"
> > +#include "internal.h"
> > +#include "dca.h"
> > +
> > +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+2];
> > +    uint16_t *pout;
> > +
> > +    dca_buffer_size =
> > +        ff_dca_convert_bitstream(buf, buf_size, dca_buffer,
> > +                                 DCA_MAX_FRAME_SIZE);
> >
> > +    if (dca_buffer_size == -1) {
>
> can i convince you to treat all negative values as error?
> its more consistent through ffmpeg and allows functions return more
> verbose error codes
>
>
> [...]

Ok, I just copied it from libavcodec/dca.c.

-- 
Bartlomiej Wolowiec
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch2
Type: text/x-diff
Size: 3810 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090813/11432dbe/attachment.diff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch1
Type: text/x-diff
Size: 1505 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090813/11432dbe/attachment-0001.diff>



More information about the ffmpeg-devel mailing list