From 4f90f33ab4a4b1b4a36d71034b526b71f08b9ee6 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sun, 9 Sep 2007 13:47:25 +0000 Subject: [PATCH] perform init after reading the values needed for init fixes decoding of files with spatial_decomposition_count!=5 Originally committed as revision 10457 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/snow.c | 64 ++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/libavcodec/snow.c b/libavcodec/snow.c index edf6e5c661..81a07c19a4 100644 --- a/libavcodec/snow.c +++ b/libavcodec/snow.c @@ -1656,7 +1656,7 @@ static void reset_contexts(SnowContext *s){ //FIXME better initial contexts int plane_index, level, orientation; for(plane_index=0; plane_index<3; plane_index++){ - for(level=0; levelspatial_decomposition_count; level++){ + for(level=0; levelplane[plane_index].band[level][orientation].state, MID_STATE, sizeof(s->plane[plane_index].band[level][orientation].state)); } @@ -3697,7 +3697,6 @@ static void init_qexp(void){ static int common_init(AVCodecContext *avctx){ SnowContext *s = avctx->priv_data; int width, height; - int level, orientation, plane_index; int i, j; s->avctx= avctx; @@ -3745,12 +3744,6 @@ static int common_init(AVCodecContext *avctx){ if(!qexp[0]) init_qexp(); - s->spatial_decomposition_count= 5; - s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type - - s->chroma_h_shift= 1; //FIXME XXX - s->chroma_v_shift= 1; - // dec += FFMAX(s->chroma_h_shift, s->chroma_v_shift); width= s->avctx->width; @@ -3759,8 +3752,18 @@ static int common_init(AVCodecContext *avctx){ s->spatial_idwt_buffer= av_mallocz(width*height*sizeof(IDWTELEM)); s->spatial_dwt_buffer= av_mallocz(width*height*sizeof(DWTELEM)); //FIXME this doesnt belong here - s->mv_scale= (s->avctx->flags & CODEC_FLAG_QPEL) ? 2 : 4; - s->block_max_depth= (s->avctx->flags & CODEC_FLAG_4MV) ? 1 : 0; + for(i=0; iavctx->get_buffer(s->avctx, &s->mconly_picture); + + return 0; +} + +static int common_init_after_header(AVCodecContext *avctx){ + SnowContext *s = avctx->priv_data; + int plane_index, level, orientation; for(plane_index=0; plane_index<3; plane_index++){ int w= s->avctx->width; @@ -3773,13 +3776,6 @@ static int common_init(AVCodecContext *avctx){ s->plane[plane_index].width = w; s->plane[plane_index].height= h; - s->plane[plane_index].diag_mc= 1; - s->plane[plane_index].htaps= 6; - s->plane[plane_index].hcoeff[0]= 40; - s->plane[plane_index].hcoeff[1]= -10; - s->plane[plane_index].hcoeff[2]= 2; - s->plane[plane_index].fast_mc= 1; - //av_log(NULL, AV_LOG_DEBUG, "%d %d\n", w, h); for(level=s->spatial_decomposition_count-1; level>=0; level--){ for(orientation=level ? 1 : 0; orientation<4; orientation++){ @@ -3807,6 +3803,8 @@ static int common_init(AVCodecContext *avctx){ if(level) b->parent= &s->plane[plane_index].band[level-1][orientation]; + //FIXME avoid this realloc + av_freep(&b->x_coeff); b->x_coeff=av_mallocz(((b->width+1) * b->height+1)*sizeof(x_and_coeff)); } w= (w+1)>>1; @@ -3814,18 +3812,6 @@ static int common_init(AVCodecContext *avctx){ } } - for(i=0; iwidth= avctx->width; - height= s->height= avctx->height; - - assert(width && height); -*/ - s->avctx->get_buffer(s->avctx, &s->mconly_picture); - return 0; } @@ -3931,7 +3917,26 @@ static int encode_init(AVCodecContext *avctx) return -1; } + s->spatial_decomposition_count= 5; + s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type + + s->chroma_h_shift= 1; //FIXME XXX + s->chroma_v_shift= 1; + + s->mv_scale = (avctx->flags & CODEC_FLAG_QPEL) ? 2 : 4; + s->block_max_depth= (avctx->flags & CODEC_FLAG_4MV ) ? 1 : 0; + + for(plane_index=0; plane_index<3; plane_index++){ + s->plane[plane_index].diag_mc= 1; + s->plane[plane_index].htaps= 6; + s->plane[plane_index].hcoeff[0]= 40; + s->plane[plane_index].hcoeff[1]= -10; + s->plane[plane_index].hcoeff[2]= 2; + s->plane[plane_index].fast_mc= 1; + } + common_init(avctx); + common_init_after_header(avctx); alloc_blocks(s); s->version=0; @@ -4414,6 +4419,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 s->current_picture.pict_type= FF_I_TYPE; //FIXME I vs. P decode_header(s); + common_init_after_header(avctx); // realloc slice buffer for the case that spatial_decomposition_count changed slice_buffer_destroy(&s->sb);