[FFmpeg-devel] [PATCH] move some bitstream related functions

Aurelien Jacobs aurel
Thu Jul 5 15:39:05 CEST 2007


On Thu, 5 Jul 2007 15:04:19 +0200
Michael Niedermayer <michaelni at gmx.at> wrote:

> Hi
> 
> On Thu, Jul 05, 2007 at 12:08:50PM +0200, Aurelien Jacobs wrote:
> > Hi,
> > 
> > The attached patch moves some bitstream related functions from mpegvideo_enc.c
> > to bitstream.c. Those functions are used by other encoders which don't
> > depend on mpegvideo_enc.c otherwise (such as svq1.c and h263.c).
> > So moving them will then allows me to ensure mpegvideo_enc.c is compiled
> > only when necessary (and not as soon as any encoder is enabled).
> > 
> > Is it ok ?
> [...]
> > Index: libavcodec/bitstream.c
> > ===================================================================
> > --- libavcodec/bitstream.c	(r??vision 9467)
> > +++ libavcodec/bitstream.c	(copie de travail)
> > @@ -29,6 +29,7 @@
> >  
> >  #include "avcodec.h"
> >  #include "bitstream.h"
> > +#include "dsputil.h"
> 
> ugly

OK.

> >  /**
> >   * Same as av_mallocz_static(), but does a realloc.
> > @@ -60,6 +61,42 @@
> >          put_bits(pbc, 8, 0);
> >  }
> >  
> > +void ff_copy_bits(PutBitContext *pb, uint8_t *src, int length)
> > +{
> > +    const uint16_t *srcw= (uint16_t*)src;
> > +    int words= length>>4;
> > +    int bits= length&15;
> > +    int i;
> > +
> > +    if(length==0) return;
> > +
> > +    if(words < 16){
> > +        for(i=0; i<words; i++) put_bits(pb, 16, be2me_16(srcw[i]));
> > +    }else if(put_bits_count(pb)&7){
> > +        for(i=0; i<words; i++) put_bits(pb, 16, be2me_16(srcw[i]));
> > +    }else{
> > +        for(i=0; put_bits_count(pb)&31; i++)
> > +            put_bits(pb, 8, src[i]);
> > +        flush_put_bits(pb);
> > +        memcpy(pbBufPtr(pb), src+i, 2*words-i);
> > +        skip_put_bytes(pb, 2*words-i);
> > +    }
> > +
> > +    put_bits(pb, bits, be2me_16(srcw[words])>>(16-bits));
> > +}
> 
> can be simplified

Indeed. But this patch only moves some code from one file to another.
Well, I will simplify this function, but later, in another patch.

> > +void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix){
> > +    int i;
> > +
> > +    if(matrix){
> > +        put_bits(pb, 1, 1);
> > +        for(i=0;i<64;i++) {
> > +            put_bits(pb, 8, matrix[ ff_zigzag_direct[i] ]);
> > +        }
> > +    }else
> > +        put_bits(pb, 1, 0);
> > +}
> > +
> >  /* VLC decoding */
> 
> doesnt belong in bitstream.* at all

I have to agree with this. On the other hand, this function is used
in h263.c and create a dependency on mpegvideo_enc.c for just one
small function. Any idea where I could move this function ?

Anyway, let's start simply. New attached patch just move ff_copy_bits()
to bitstream.c without any other modifications. OK ?

Aurel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mpeg-bitstream2.diff
Type: text/x-diff
Size: 3179 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070705/76f7cb98/attachment.diff>



More information about the ffmpeg-devel mailing list