# HG changeset patch # User michael # Date 1135550301 0 # Node ID d377b0788381f57c9bce818f2a3f283dd5181de1 # Parent 0300c2647bc30fa37cac1db105f6de0bd774125e Fix DV memory leak and allow multiple instances patch by (Burkhard Plaum?) approved by Roman Shaposhnik diff -r 0300c2647bc3 -r d377b0788381 dv.c --- a/dv.c Sun Dec 25 18:34:02 2005 +0000 +++ b/dv.c Sun Dec 25 22:38:21 2005 +0000 @@ -49,6 +49,9 @@ void (*get_pixels)(DCTELEM *block, const uint8_t *pixels, int line_size); void (*fdct[2])(DCTELEM *block); void (*idct_put[2])(uint8_t *dest, int line_size, DCTELEM *block); + + /* MultiThreading */ + uint8_t** dv_anchor; } DVVideoContext; #define TEX_VLC_BITS 9 @@ -61,9 +64,6 @@ #define DV_VLC_MAP_LEV_SIZE 512 //FIXME sign was removed so this should be /2 but needs check #endif -/* MultiThreading */ -static uint8_t** dv_anchor; - /* XXX: also include quantization */ static RL_VLC_ELEM *dv_rl_vlc; /* VLC encoding lookup table */ @@ -118,12 +118,12 @@ return -ENOMEM; /* dv_anchor lets each thread know its Id */ - dv_anchor = av_malloc(12*27*sizeof(void*)); - if (!dv_anchor) { + s->dv_anchor = av_malloc(12*27*sizeof(void*)); + if (!s->dv_anchor) { return -ENOMEM; } for (i=0; i<12*27; i++) - dv_anchor[i] = (void*)(size_t)i; + s->dv_anchor[i] = (void*)(size_t)i; /* it's faster to include sign bit in a generic VLC parsing scheme */ for (i=0, j=0; idv_anchor); return -ENOMEM; } for(i = 0; i < dv_vlc.table_size; i++){ @@ -939,7 +939,7 @@ s->picture.top_field_first = 0; s->buf = buf; - avctx->execute(avctx, dv_decode_mt, (void**)&dv_anchor[0], NULL, + avctx->execute(avctx, dv_decode_mt, (void**)&s->dv_anchor[0], NULL, s->sys->difseg_size * 27); emms_c(); @@ -968,13 +968,23 @@ s->picture.pict_type = FF_I_TYPE; s->buf = buf; - c->execute(c, dv_encode_mt, (void**)&dv_anchor[0], NULL, + c->execute(c, dv_encode_mt, (void**)&s->dv_anchor[0], NULL, s->sys->difseg_size * 27); emms_c(); return s->sys->frame_size; } +static int dvvideo_close(AVCodecContext *c) +{ + DVVideoContext *s = c->priv_data; + + av_free(s->dv_anchor); + + return 0; +} + + #ifdef CONFIG_DVVIDEO_ENCODER AVCodec dvvideo_encoder = { "dvvideo", @@ -983,7 +993,7 @@ sizeof(DVVideoContext), dvvideo_init, dvvideo_encode_frame, - NULL, + dvvideo_close, NULL, CODEC_CAP_DR1, NULL @@ -997,7 +1007,7 @@ sizeof(DVVideoContext), dvvideo_init, NULL, - NULL, + dvvideo_close, dvvideo_decode_frame, CODEC_CAP_DR1, NULL