[Ffmpeg-devel] I'm giving up

Michael Niedermayer michaelni
Wed Dec 6 15:25:07 CET 2006


Hi

On Wed, Dec 06, 2006 at 02:47:32PM +0100, Panagiotis Issaris wrote:
[...]
> Index: libavcodec/h264enc.c
> ===================================================================
> --- libavcodec/h264enc.c	(revision 0)
> +++ libavcodec/h264enc.c	(revision 0)
> @@ -0,0 +1,93 @@
> +/*
> + * H.264 encoder
> + *
> + * This library 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 of the License, or (at your option) any later version.
> + *
> + * This library 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 this library; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include "common.h"
> +#include "bitstream.h"
> +
> +/**
> + * @param b2 the data which should be escaped
> + * @param dest the target buffer, dst+1 == src is allowed as a special case
> + * @param length the length of the src data
> + * @param destsize the length of the dst array
> + * @returns pointer to current position in the output buffer or NULL if an error occured
> + */
> +static uint8_t *h264_write_nal_unit(int nal_ref_idc, int nal_unit_type, uint8_t *dest, int *destsize,
> +                          PutBitContext *b2)
> +{
> +    PutBitContext b;
> +    int i, destpos, rbsplen, escape_count;
> +    uint8_t *rbsp;
> +
> +    // Align b2 on a byte boundary
> +
> +    align_put_bits(b2);

is the rbsp trailing stuff correct? shouldnt there be a put_bits(1,1) ?


> +    rbsplen = put_bits_count(b2)/8;
> +    flush_put_bits(b2);
> +    rbsp = b2->buf;
> +
> +    init_put_bits(&b,dest,*destsize);
> +
> +    put_bits(&b,16,0);
> +    put_bits(&b,16,0x01);
> +
> +    put_bits(&b,1,0); // forbidden zero bit
> +    put_bits(&b,2,nal_ref_idc); // nal_ref_idc
> +    put_bits(&b,5,nal_unit_type); // nal_unit_type
> +
> +    flush_put_bits(&b);
> +
> +    destpos = 5;
> +    escape_count= 0;
> +    for(i=0; i<rbsplen; i+=2){
> +        if(rbsp[i]) continue;
> +        if(i>0 && rbsp[i-1]==0)
> +            i--;
> +        if(i+2<rbsplen && rbsp[i+1]==0 && rbsp[i+2]<=3){
> +            escape_count++;
> +            i+=2;
> +        }
> +    }
> +
> +    if(escape_count==0){
> +        if(dest+destpos != rbsp) {
> +            memcpy(dest+destpos, rbsp, rbsplen);
> +            *destsize -= (rbsplen+destpos);
> +        }
> +        return dest+rbsplen+destpos;
> +    }
> +    if(rbsplen + escape_count + 1> *destsize)
> +    {
> +        av_log(NULL, AV_LOG_ERROR, "Destination buffer too small!\n");
> +        return NULL;
> +    }
> +    //this should be damn rare (hopefully)
> +    for (i = 0 ; i < rbsplen ; i++)
> +    {
> +        if (i + 2 < rbsplen && (rbsp[i] == 0 && rbsp[i+1] == 0 && rbsp[i+2] < 4))
> +        {
> +            dest[destpos++] = rbsp[i++];
> +            dest[destpos++] = rbsp[i];
> +            dest[destpos++] = 0x03; // emulation prevention byte
> +        }
> +        else
> +            dest[destpos++] = rbsp[i];
> +    }

the {} placement is inconsistant

except these iam fine with commiting h264enc.c

[...]
> +static void h264_dct_c(DCTELEM block[4][4])
> +{
> +    DCTELEM pieces[4][4];
> +
> +    pieces[0][0] = block[0][0]+block[1][0]+block[2][0]+block[3][0];
> +    pieces[0][1] = block[0][1]+block[1][1]+block[2][1]+block[3][1];
> +    pieces[0][2] = block[0][2]+block[1][2]+block[2][2]+block[3][2];
> +    pieces[0][3] = block[0][3]+block[1][3]+block[2][3]+block[3][3];
> +
> +    pieces[1][0] = (block[0][0]<<1)+block[1][0]-block[2][0]-(block[3][0]<<1);
> +    pieces[1][1] = (block[0][1]<<1)+block[1][1]-block[2][1]-(block[3][1]<<1);
> +    pieces[1][2] = (block[0][2]<<1)+block[1][2]-block[2][2]-(block[3][2]<<1);
> +    pieces[1][3] = (block[0][3]<<1)+block[1][3]-block[2][3]-(block[3][3]<<1);
> +
> +    pieces[2][0] = block[0][0]-block[1][0]-block[2][0]+block[3][0];
> +    pieces[2][1] = block[0][1]-block[1][1]-block[2][1]+block[3][1];
> +    pieces[2][2] = block[0][2]-block[1][2]-block[2][2]+block[3][2];
> +    pieces[2][3] = block[0][3]-block[1][3]-block[2][3]+block[3][3];
> +
> +    pieces[3][0] = block[0][0]-(block[1][0]<<1)+(block[2][0]<<1)-block[3][0];
> +    pieces[3][1] = block[0][1]-(block[1][1]<<1)+(block[2][1]<<1)-block[3][1];
> +    pieces[3][2] = block[0][2]-(block[1][2]<<1)+(block[2][2]<<1)-block[3][2];
> +    pieces[3][3] = block[0][3]-(block[1][3]<<1)+(block[2][3]<<1)-block[3][3];
> +
> +    block[0][0] = pieces[0][0]+pieces[0][1]+pieces[0][2]+pieces[0][3];
> +    block[0][1] = pieces[1][0]+pieces[1][1]+pieces[1][2]+pieces[1][3];
> +    block[0][2] = pieces[2][0]+pieces[2][1]+pieces[2][2]+pieces[2][3];
> +    block[0][3] = pieces[3][0]+pieces[3][1]+pieces[3][2]+pieces[3][3];
> +
> +    block[1][0] = (pieces[0][0] << 1)+pieces[0][1]-pieces[0][2]-(pieces[0][3]<<1);
> +    block[1][1] = (pieces[1][0] << 1)+pieces[1][1]-pieces[1][2]-(pieces[1][3]<<1);
> +    block[1][2] = (pieces[2][0] << 1)+pieces[2][1]-pieces[2][2]-(pieces[2][3]<<1);
> +    block[1][3] = (pieces[3][0] << 1)+pieces[3][1]-pieces[3][2]-(pieces[3][3]<<1);
> +
> +    block[2][0] = pieces[0][0]-pieces[0][1]-pieces[0][2]+pieces[0][3];
> +    block[2][1] = pieces[1][0]-pieces[1][1]-pieces[1][2]+pieces[1][3];
> +    block[2][2] = pieces[2][0]-pieces[2][1]-pieces[2][2]+pieces[2][3];
> +    block[2][3] = pieces[3][0]-pieces[3][1]-pieces[3][2]+pieces[3][3];
> +
> +    block[3][0] = pieces[0][0]-(pieces[0][1]<<1)+(pieces[0][2]<<1)-pieces[0][3];
> +    block[3][1] = pieces[1][0]-(pieces[1][1]<<1)+(pieces[1][2]<<1)-pieces[1][3];
> +    block[3][2] = pieces[2][0]-(pieces[2][1]<<1)+(pieces[2][2]<<1)-pieces[2][3];
> +    block[3][3] = pieces[3][0]-(pieces[3][1]<<1)+(pieces[3][2]<<1)-pieces[3][3];

theres are alot of redundant operations in the above, these should be
simplified


[...]
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 03c1ae4..ac369eb 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -86,6 +86,7 @@ OBJS-$(CONFIG_GIF_ENCODER)             +
>  OBJS-$(CONFIG_H261_DECODER)            += h261.o
>  OBJS-$(CONFIG_H261_ENCODER)            += h261.o
>  OBJS-$(CONFIG_H264_DECODER)            += h264.o
> +OBJS-$(CONFIG_H264_ENCODER)            += h264enc.o h264cavlc.o h264dsp.o
>  OBJS-$(CONFIG_HUFFYUV_DECODER)         += huffyuv.o
>  OBJS-$(CONFIG_HUFFYUV_ENCODER)         += huffyuv.o
>  OBJS-$(CONFIG_IDCIN_DECODER)           += idcinvideo.o

this can be commited if it does not break compilation


> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index 9678f6b..c2c3bbb 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -75,7 +75,7 @@ void avcodec_register_all(void)
>      REGISTER_ENCDEC (H263, h263);
>      REGISTER_DECODER(H263I, h263i);
>      REGISTER_ENCODER(H263P, h263p);
> -    REGISTER_DECODER(H264, h264);
> +    REGISTER_ENCDEC(H264, h264);
>      REGISTER_ENCDEC (HUFFYUV, huffyuv);

this can be commited if it does not break compilation


>      REGISTER_DECODER(IDCIN, idcin);
>      REGISTER_DECODER(INDEO2, indeo2);
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 96ea77a..4457969 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -149,6 +149,7 @@ enum CodecID {
>      CODEC_ID_TIERTEXSEQVIDEO,
>      CODEC_ID_TIFF,
>      CODEC_ID_GIF,
> +    CODEC_ID_FFH264,

ok can be commited


>  
>      /* various pcm "codecs" */
>      CODEC_ID_PCM_S16LE= 0x10000,
> diff --git a/libavcodec/dsputil.c b/libavcodec/dsputil.c
> index 51eddbc..84f1bfb 100644
> --- a/libavcodec/dsputil.c
> +++ b/libavcodec/dsputil.c
> @@ -2549,6 +2549,11 @@ void ff_put_vc1_mspel_mc00_c(uint8_t *ds
>  }
>  #endif /* CONFIG_VC1_DECODER||CONFIG_WMV3_DECODER */
>  
> +#if defined(CONFIG_H264_ENCODER)
> +/* H264 specific */
> +void ff_h264dsp_init(DSPContext* c, AVCodecContext *avctx);
> +#endif /* CONFIG_H264_ENCODER */

this can be commited as soon as theres a ff_h264dsp_init() and as long
as doing so doenst break anything

[...]

> @@ -383,6 +385,14 @@ typedef struct DSPContext {
>      void (*h264_idct8_add)(uint8_t *dst, DCTELEM *block, int stride);
>      void (*h264_idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
>      void (*h264_idct8_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
> +    void (*h264_dct)(DCTELEM block[4][4]);

iam ok with adding this one anytime


> +    void (*h264_idct_notranspose_add)(uint8_t *dst, DCTELEM *block, int stride);

> +    void (*h264_hadamard_mult4x4)(DCTELEM Y[4][4]);

mult4x4 vs. mult_4x4 ?


[...]
> diff --git a/libavcodec/h264.c b/libavcodec/h264.c
> index 7405456..00ab7d7 100644
> --- a/libavcodec/h264.c
> +++ b/libavcodec/h264.c
> @@ -408,6 +408,15 @@ static always_inline uint32_t pack16to32
>  #endif
>  }
>  
> +const uint8_t ff_rem6[52]={
> +0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
> +};
> +
> +const uint8_t ff_div6[52]={
> +0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
> +};

can be commited with all the needed renamings


> +
> +
>  /**
>   * fill a rectangle.
>   * @param h height of the rectangle, should be a constant
> @@ -1946,42 +1955,6 @@ static inline int get_chroma_qp(int chro
>      return chroma_qp[clip(qscale + chroma_qp_index_offset, 0, 51)];
>  }
>  
> -
> -#if 0
> -static void h264_diff_dct_c(DCTELEM *block, uint8_t *src1, uint8_t *src2, int stride){
> -    int i;
> -    //FIXME try int temp instead of block
> -
> -    for(i=0; i<4; i++){
> -        const int d0= src1[0 + i*stride] - src2[0 + i*stride];
> -        const int d1= src1[1 + i*stride] - src2[1 + i*stride];
> -        const int d2= src1[2 + i*stride] - src2[2 + i*stride];
> -        const int d3= src1[3 + i*stride] - src2[3 + i*stride];
> -        const int z0= d0 + d3;
> -        const int z3= d0 - d3;
> -        const int z1= d1 + d2;
> -        const int z2= d1 - d2;
> -
> -        block[0 + 4*i]=   z0 +   z1;
> -        block[1 + 4*i]= 2*z3 +   z2;
> -        block[2 + 4*i]=   z0 -   z1;
> -        block[3 + 4*i]=   z3 - 2*z2;
> -    }
> -
> -    for(i=0; i<4; i++){
> -        const int z0= block[0*4 + i] + block[3*4 + i];
> -        const int z3= block[0*4 + i] - block[3*4 + i];
> -        const int z1= block[1*4 + i] + block[2*4 + i];
> -        const int z2= block[1*4 + i] - block[2*4 + i];
> -
> -        block[0*4 + i]=   z0 +   z1;
> -        block[1*4 + i]= 2*z3 +   z2;
> -        block[2*4 + i]=   z0 -   z1;
> -        block[3*4 + i]=   z3 - 2*z2;
> -    }
> -}
> -#endif

ok, can be commited


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

If you really think that XML is the answer, then you definitly missunderstood
the question -- Attila Kinali




More information about the ffmpeg-devel mailing list