Index: libmpcodecs/vf_uspp.c =================================================================== RCS file: /cvsroot/mplayer/main/libmpcodecs/vf_uspp.c,v retrieving revision 1.5 diff -u -r1.5 vf_uspp.c --- libmpcodecs/vf_uspp.c 31 Jan 2006 23:36:12 -0000 1.5 +++ libmpcodecs/vf_uspp.c 12 Feb 2006 06:27:38 -0000 @@ -188,7 +188,8 @@ p->frame->data[2]= p->src[2] + x1/2 + y1/2 * p->frame->linesize[2]; out_size = avcodec_encode_video(p->avctx_enc[i], p->outbuf, p->outbuf_size, p->frame); - avcodec_decode_video(p->avctx_dec[i], p->frame_dec, &got_picture, p->outbuf, out_size); +// avcodec_decode_video(p->avctx_dec[i], p->frame_dec, &got_picture, p->outbuf, out_size); + p->frame_dec = p->avctx_enc[i]->coded_frame; offset= (BLOCK-x1) + (BLOCK-y1)*p->frame_dec->linesize[0]; //FIXME optimize Index: libavcodec/snow.c =================================================================== RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/snow.c,v retrieving revision 1.87 diff -u -r1.87 snow.c --- libavcodec/snow.c 30 Jan 2006 23:33:18 -0000 1.87 +++ libavcodec/snow.c 12 Feb 2006 06:27:41 -0000 @@ -36,6 +36,12 @@ #define LOSSLESS_QLOG -128 #define FRAC_BITS 8 +// define this if you want to save memory for multiple snow encoders, +// not thread safe. helps a lot with mencoder's uspp. +#define SAVE_MEMORY +// define for uspp +#define SKIP_BITSTREAM + static const int8_t quant3[256]={ 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -492,6 +498,19 @@ #define slice_buffer_get_line(slice_buf, line_num) ((slice_buf)->line[line_num] ? (slice_buf)->line[line_num] : slice_buffer_load_line((slice_buf), (line_num))) //#define slice_buffer_get_line(slice_buf, line_num) (slice_buffer_load_line((slice_buf), (line_num))) +#ifdef SAVE_MEMORY +// for static_buffer_init +static DWTELEM * *sbi_buf_line = NULL; +static DWTELEM * *sbi_buf_data_stack = NULL; +// for alloc_blocks +static BlockNode *ab_s_block = NULL; +// for comon_init +static DWTELEM *ci_s_spatial_dwt_buffer = NULL; +static x_and_coeff *ci_b_x_coeff = NULL; +// for encode_init +static MpegEncContext *ei_s_m = NULL; +#endif + static void iterative_me(SnowContext *s); static void slice_buffer_init(slice_buffer * buf, int line_count, int max_allocated_lines, int line_width, DWTELEM * base_buffer) @@ -502,6 +521,11 @@ buf->line_count = line_count; buf->line_width = line_width; buf->data_count = max_allocated_lines; + +#ifdef SAVE_MEMORY + if(sbi_buf_line == NULL) { +#endif + buf->line = (DWTELEM * *) av_mallocz (sizeof(DWTELEM *) * line_count); buf->data_stack = (DWTELEM * *) av_malloc (sizeof(DWTELEM *) * max_allocated_lines); @@ -510,6 +534,16 @@ buf->data_stack[i] = (DWTELEM *) av_malloc (sizeof(DWTELEM) * line_width); } +#ifdef SAVE_MEMORY + sbi_buf_line = buf->line; + sbi_buf_data_stack = buf->data_stack; + } else { + buf->line = (DWTELEM * *) sbi_buf_line; + buf->data_stack = (DWTELEM * *) sbi_buf_data_stack; + } +#endif + + buf->data_stack_top = max_allocated_lines - 1; } @@ -1946,7 +1980,18 @@ s->b_width = w; s->b_height= h; +#ifdef SAVE_MEMORY + if(ab_s_block == NULL) { +#endif + s->block= av_mallocz(w * h * sizeof(BlockNode) << (s->block_max_depth*2)); + +#ifdef SAVE_MEMORY + ab_s_block = s->block; + } else + s->block = (BlockNode *) ab_s_block; +#endif + return 0; } @@ -3790,6 +3835,7 @@ SnowContext *s = avctx->priv_data; int width, height; int level, orientation, plane_index, dec; + x_and_coeff *xc_buf; s->avctx= avctx; @@ -3847,8 +3893,22 @@ width= s->avctx->width; height= s->avctx->height; +#ifdef SAVE_MEMORY + if(ci_s_spatial_dwt_buffer == NULL) { +#endif + s->spatial_dwt_buffer= av_mallocz(width*height*sizeof(DWTELEM)); +#ifdef SAVE_MEMORY + xc_buf = av_mallocz(((s->avctx->width+2) * (s->avctx->height+2))*sizeof(x_and_coeff)); + ci_s_spatial_dwt_buffer = s->spatial_dwt_buffer; + ci_b_x_coeff = xc_buf; + } else { + s->spatial_dwt_buffer = ci_s_spatial_dwt_buffer; + xc_buf = ci_b_x_coeff; + } +#endif + s->mv_scale= (s->avctx->flags & CODEC_FLAG_QPEL) ? 2 : 4; s->block_max_depth= (s->avctx->flags & CODEC_FLAG_4MV) ? 1 : 0; @@ -3888,7 +3948,13 @@ if(level) b->parent= &s->plane[plane_index].band[level-1][orientation]; + +#ifdef SAVE_MEMORY + b->x_coeff = xc_buf; + xc_buf += (b->width+1) * b->height+1; +#else b->x_coeff=av_mallocz(((b->width+1) * b->height+1)*sizeof(x_and_coeff)); +#endif } w= (w+1)>>1; h= (h+1)>>1; @@ -3955,12 +4021,23 @@ s->m.flags = avctx->flags; s->m.bit_rate= avctx->bit_rate; +#ifdef SAVE_MEMORY + if(ei_s_m == NULL) { +#endif + s->m.me.scratchpad= av_mallocz((avctx->width+64)*2*16*2*sizeof(uint8_t)); s->m.me.map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); s->m.me.score_map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); s->m.obmc_scratchpad= av_mallocz(MB_SIZE*MB_SIZE*12*sizeof(uint32_t)); h263_encode_init(&s->m); //mv_penalty +#ifdef SAVE_MEMORY + ei_s_m = &s->m; + } else { + s->m = *ei_s_m; + } +#endif + if(avctx->flags&CODEC_FLAG_PASS1){ if(!avctx->stats_out) avctx->stats_out = av_mallocz(256); @@ -4166,7 +4243,9 @@ quantize(s, b, b->buf, b->stride, s->qbias); if(orientation==0) decorrelate(s, b, b->buf, b->stride, pict->pict_type == P_TYPE, 0); +#ifndef SKIP_BITSTREAM encode_subband(s, b, b->buf, b->parent ? b->parent->buf : NULL, b->stride, orientation); +#endif assert(b->parent==NULL || b->parent->stride == b->stride*2); if(orientation==0) correlate(s, b, b->buf, b->stride, 1, 0); @@ -4234,15 +4313,26 @@ static void common_end(SnowContext *s){ int plane_index, level, orientation; +#ifdef SAVE_MEMORY + if(ci_s_spatial_dwt_buffer != NULL){ +#endif + av_freep(&s->spatial_dwt_buffer); + av_freep(&s->block); + av_freep(&ci_b_x_coeff); +#ifdef SAVE_MEMORY + ci_s_spatial_dwt_buffer = NULL; + ei_s_m = NULL; + ab_s_block = NULL; +#endif + av_freep(&s->m.me.scratchpad); av_freep(&s->m.me.map); av_freep(&s->m.me.score_map); av_freep(&s->m.obmc_scratchpad); - - av_freep(&s->block); - + +#ifndef SAVE_MEMORY for(plane_index=0; plane_index<3; plane_index++){ for(level=s->spatial_decomposition_count-1; level>=0; level--){ for(orientation=level ? 1 : 0; orientation<4; orientation++){ @@ -4251,6 +4341,7 @@ av_freep(&b->x_coeff); } } +#endif } }