Mercurial > libavcodec.hg
changeset 1892:5ac49e7a1b8f libavcodec
init cleanup
author | michael |
---|---|
date | Tue, 16 Mar 2004 16:11:29 +0000 |
parents | f403b3e286b3 |
children | 779bdf5063ce |
files | h263dec.c h264.c mjpeg.c mpeg12.c mpegvideo.c mpegvideo.h rv10.c svq1.c |
diffstat | 8 files changed, 76 insertions(+), 59 deletions(-) [+] |
line wrap: on
line diff
--- a/h263dec.c Tue Mar 16 15:38:40 2004 +0000 +++ b/h263dec.c Tue Mar 16 16:11:29 2004 +0000 @@ -42,8 +42,8 @@ s->workaround_bugs= avctx->workaround_bugs; // set defaults + MPV_decode_defaults(s); s->quant_precision=5; - s->progressive_sequence=1; s->decode_mb= ff_h263_decode_mb; s->low_delay= 1; avctx->pix_fmt= PIX_FMT_YUV420P;
--- a/h264.c Tue Mar 16 15:38:40 2004 +0000 +++ b/h264.c Tue Mar 16 16:11:29 2004 +0000 @@ -2166,6 +2166,8 @@ H264Context *h= avctx->priv_data; MpegEncContext * const s = &h->s; + MPV_decode_defaults(s); + s->avctx = avctx; common_init(h); @@ -2173,7 +2175,6 @@ s->workaround_bugs= avctx->workaround_bugs; // set defaults - s->progressive_sequence=1; // s->decode_mb= ff_h263_decode_mb; s->low_delay= 1; avctx->pix_fmt= PIX_FMT_YUV420P;
--- a/mjpeg.c Tue Mar 16 15:38:40 2004 +0000 +++ b/mjpeg.c Tue Mar 16 16:11:29 2004 +0000 @@ -862,13 +862,11 @@ memset(&s2, 0, sizeof(MpegEncContext)); s2.avctx= avctx; // s2->out_format = FMT_MJPEG; - s2.width = 8; - s2.height = 8; - if (MPV_common_init(&s2) < 0) - return -1; + dsputil_init(&s2.dsp, avctx); + DCT_common_init(&s2); + s->scantable= s2.intra_scantable; s->idct_put= s2.dsp.idct_put; - MPV_common_end(&s2); s->mpeg_enc_ctx_allocated = 0; s->buffer_size = 102400; /* smaller buffer should be enough,
--- a/mpeg12.c Tue Mar 16 15:38:40 2004 +0000 +++ b/mpeg12.c Tue Mar 16 16:11:29 2004 +0000 @@ -1760,6 +1760,9 @@ static int mpeg_decode_init(AVCodecContext *avctx) { Mpeg1Context *s = avctx->priv_data; + MpegEncContext *s2 = &s->mpeg_enc_ctx; + + MPV_decode_defaults(s2); s->mpeg_enc_ctx.avctx= avctx; s->mpeg_enc_ctx.flags= avctx->flags;
--- a/mpegvideo.c Tue Mar 16 15:38:40 2004 +0000 +++ b/mpegvideo.c Tue Mar 16 16:11:29 2004 +0000 @@ -502,7 +502,62 @@ #undef COPY } -/* init common structure for both encoder and decoder */ +/** + * sets the given MpegEncContext to common defaults (same for encoding and decoding). + * the changed fields will not depend upon the prior state of the MpegEncContext. + */ +static void MPV_common_defaults(MpegEncContext *s){ + s->y_dc_scale_table= + s->c_dc_scale_table= ff_mpeg1_dc_scale_table; + s->chroma_qscale_table= ff_default_chroma_qscale_table; + s->progressive_frame= 1; + s->progressive_sequence= 1; + s->picture_structure= PICT_FRAME; + + s->coded_picture_number = 0; + s->picture_number = 0; + s->input_picture_number = 0; + + s->picture_in_gop_number = 0; +} + +/** + * sets the given MpegEncContext to defaults for decoding. + * the changed fields will not depend upon the prior state of the MpegEncContext. + */ +void MPV_decode_defaults(MpegEncContext *s){ + MPV_common_defaults(s); +} + +/** + * sets the given MpegEncContext to defaults for encoding. + * the changed fields will not depend upon the prior state of the MpegEncContext. + */ +void MPV_encode_defaults(MpegEncContext *s){ + static int done=0; + + MPV_common_defaults(s); + + if(!done){ + int i; + done=1; + + default_mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) ); + memset(default_mv_penalty, 0, sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1)); + memset(default_fcode_tab , 0, sizeof(uint8_t)*(2*MAX_MV+1)); + + for(i=-16; i<16; i++){ + default_fcode_tab[i + MAX_MV]= 1; + } + } + s->me.mv_penalty= default_mv_penalty; + s->fcode_tab= default_fcode_tab; +} + +/** + * init common structure for both encoder and decoder. + * this assumes that some variables like width/height are already set + */ int MPV_common_init(MpegEncContext *s) { int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y; @@ -533,28 +588,11 @@ s->block_wrap[3]= s->mb_width*2 + 2; s->block_wrap[4]= s->block_wrap[5]= s->mb_width + 2; - - s->y_dc_scale_table= - s->c_dc_scale_table= ff_mpeg1_dc_scale_table; - s->chroma_qscale_table= ff_default_chroma_qscale_table; - if( s->codec_id != CODEC_ID_MPEG1VIDEO && - s->codec_id != CODEC_ID_MPEG2VIDEO) - { - /* default structure is frame */ - s->progressive_frame= 1; - s->picture_structure= PICT_FRAME; - - s->y_dc_scale_table= - s->c_dc_scale_table= ff_mpeg1_dc_scale_table; - if (!s->encoding) - s->progressive_sequence= 1; - } - s->coded_picture_number = 0; - + y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); c_size = (s->mb_width + 2) * (s->mb_height + 2); yc_size = y_size + 2 * c_size; - + /* convert fourcc to upper case */ s->avctx->codec_tag= toupper( s->avctx->codec_tag &0xFF) + (toupper((s->avctx->codec_tag>>8 )&0xFF)<<8 ) @@ -663,9 +701,6 @@ CHECKED_ALLOCZ(s->mbintra_table, mb_array_size); memset(s->mbintra_table, 1, mb_array_size); - /* default structure is frame */ - s->picture_structure = PICT_FRAME; - /* init macroblock skip table */ CHECKED_ALLOCZ(s->mbskip_table, mb_array_size+2); //Note the +1 is for a quicker mpeg4 slice_end detection @@ -787,6 +822,8 @@ MpegEncContext *s = avctx->priv_data; int i, dummy; int chroma_h_shift, chroma_v_shift; + + MPV_encode_defaults(s); avctx->pix_fmt = PIX_FMT_YUV420P; // FIXME @@ -1070,28 +1107,6 @@ return -1; } - { /* set up some save defaults, some codecs might override them later */ - static int done=0; - if(!done){ - int i; - done=1; - - default_mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) ); - memset(default_mv_penalty, 0, sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1)); - memset(default_fcode_tab , 0, sizeof(uint8_t)*(2*MAX_MV+1)); - - for(i=-16; i<16; i++){ - default_fcode_tab[i + MAX_MV]= 1; - } - } - } - s->me.mv_penalty= default_mv_penalty; - s->fcode_tab= default_fcode_tab; - - /* dont use mv_penalty table for crap MV as it would be confused */ - //FIXME remove after fixing / removing old ME - if (s->me_method < ME_EPZS) s->me.mv_penalty = default_mv_penalty; - s->encoding = 1; /* init */ @@ -1119,7 +1134,7 @@ ff_mpeg1_encode_init(s); #endif - /* init default q matrix */ + /* init q matrix */ for(i=0;i<64;i++) { int j= s->dsp.idct_permutation[i]; #ifdef CONFIG_RISKY @@ -1153,13 +1168,10 @@ if(ff_rate_control_init(s) < 0) return -1; - s->picture_number = 0; - s->input_picture_number = 0; - s->picture_in_gop_number = 0; /* motion detector init */ s->f_code = 1; s->b_code = 1; - + return 0; }
--- a/mpegvideo.h Tue Mar 16 15:38:40 2004 +0000 +++ b/mpegvideo.h Tue Mar 16 16:11:29 2004 +0000 @@ -706,6 +706,7 @@ int DCT_common_init(MpegEncContext *s); +void MPV_decode_defaults(MpegEncContext *s); int MPV_common_init(MpegEncContext *s); void MPV_common_end(MpegEncContext *s); void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]);
--- a/rv10.c Tue Mar 16 15:38:40 2004 +0000 +++ b/rv10.c Tue Mar 16 16:11:29 2004 +0000 @@ -441,6 +441,8 @@ MpegEncContext *s = avctx->priv_data; static int done=0; + MPV_decode_defaults(s); + s->avctx= avctx; s->out_format = FMT_H263; s->codec_id= avctx->codec_id; @@ -490,8 +492,6 @@ h263_decode_init_vlc(s); - s->progressive_sequence=1; - /* init rv vlc */ if (!done) { init_vlc(&rv_dc_lum, DC_VLC_BITS, 256,