X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=libavcodec%2Fsnow.c;h=d69f452e5d4c7c12150667dc3ac76db4c5cbb132;hb=c4cccc8d3f6605c5fdd73723a865486c5b7fb117;hp=545f883541239b131b80308bfb03a81b545d1d20;hpb=44b0edda3f4f8006c16e1b124199cafaf6363f3d;p=ffmpeg diff --git a/libavcodec/snow.c b/libavcodec/snow.c index 545f8835412..d69f452e5d4 100644 --- a/libavcodec/snow.c +++ b/libavcodec/snow.c @@ -99,7 +99,7 @@ static void init_qexp(void){ double v=128; for(i=0; i>6; } - src1+=stride; - src2+=stride; - src3+=stride; - src4+=stride; + src1+=stride1; + src2+=stride2; + src3+=stride3; + src4+=stride4; dst +=stride; } }else{ const uint8_t *src1= hpel[l]; const uint8_t *src2= hpel[r]; + int stride1 = MC_STRIDE(l); + int stride2 = MC_STRIDE(r); int a= weight[((dx&7) + (8*(dy&7)))]; int b= 8-a; for(y=0; y < b_h; y++){ for(x=0; x < b_w; x++){ dst[x]= (a*src1[x] + b*src2[x] + 4)>>3; } - src1+=stride; - src2+=stride; + src1+=stride1; + src2+=stride2; dst +=stride; } } @@ -385,12 +394,13 @@ mca( 8, 8,8) av_cold int ff_snow_common_init(AVCodecContext *avctx){ SnowContext *s = avctx->priv_data; int width, height; - int i, j; + int i, j, ret; + int emu_buf_size; s->avctx= avctx; s->max_ref_frames=1; //just make sure its not an invalid value in case of no initial keyframe - dsputil_init(&s->dsp, avctx); + ff_dsputil_init(&s->dsp, avctx); ff_dwt_init(&s->dwt); #define mcf(dx,dy)\ @@ -438,17 +448,27 @@ av_cold int ff_snow_common_init(AVCodecContext *avctx){ width= s->avctx->width; height= s->avctx->height; - s->spatial_idwt_buffer= av_mallocz(width*height*sizeof(IDWTELEM)); - s->spatial_dwt_buffer= av_mallocz(width*height*sizeof(DWTELEM)); //FIXME this does not belong here + FF_ALLOCZ_OR_GOTO(avctx, s->spatial_idwt_buffer, width * height * sizeof(IDWTELEM), fail); + FF_ALLOCZ_OR_GOTO(avctx, s->spatial_dwt_buffer, width * height * sizeof(DWTELEM), fail); //FIXME this does not belong here + FF_ALLOCZ_OR_GOTO(avctx, s->temp_dwt_buffer, width * sizeof(DWTELEM), fail); + FF_ALLOCZ_OR_GOTO(avctx, s->temp_idwt_buffer, width * sizeof(IDWTELEM), fail); + FF_ALLOC_OR_GOTO(avctx, s->run_buffer, ((width + 1) >> 1) * ((height + 1) >> 1) * sizeof(*s->run_buffer), fail); for(i=0; iavctx->get_buffer(s->avctx, &s->mconly_picture); - s->scratchbuf = av_malloc(s->mconly_picture.linesize[0]*7*MB_SIZE); + if ((ret = s->avctx->get_buffer(s->avctx, &s->mconly_picture)) < 0) { + av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return ret; + } + FF_ALLOC_OR_GOTO(avctx, s->scratchbuf, s->mconly_picture.linesize[0]*7*MB_SIZE, fail); + emu_buf_size = s->mconly_picture.linesize[0] * (2 * MB_SIZE + HTAPS_MAX - 1); + FF_ALLOC_OR_GOTO(avctx, s->emu_edge_buffer, emu_buf_size, fail); return 0; +fail: + return AVERROR(ENOMEM); } int ff_snow_common_init_after_header(AVCodecContext *avctx) { @@ -516,9 +536,9 @@ static void halfpel_interpol(SnowContext *s, uint8_t *halfpel[4][4], AVFrame *fr int ls= frame->linesize[p]; uint8_t *src= frame->data[p]; - halfpel[1][p] = av_malloc(ls * (h + 2 * EDGE_WIDTH)) + EDGE_WIDTH * (1 + ls); - halfpel[2][p] = av_malloc(ls * (h + 2 * EDGE_WIDTH)) + EDGE_WIDTH * (1 + ls); - halfpel[3][p] = av_malloc(ls * (h + 2 * EDGE_WIDTH)) + EDGE_WIDTH * (1 + ls); + halfpel[1][p] = (uint8_t*) av_malloc(ls * (h + 2 * EDGE_WIDTH)) + EDGE_WIDTH * (1 + ls); + halfpel[2][p] = (uint8_t*) av_malloc(ls * (h + 2 * EDGE_WIDTH)) + EDGE_WIDTH * (1 + ls); + halfpel[3][p] = (uint8_t*) av_malloc(ls * (h + 2 * EDGE_WIDTH)) + EDGE_WIDTH * (1 + ls); halfpel[0][p]= src; for(y=0; yspatial_dwt_buffer); + av_freep(&s->temp_dwt_buffer); av_freep(&s->spatial_idwt_buffer); + av_freep(&s->temp_idwt_buffer); + av_freep(&s->run_buffer); s->m.me.temp= NULL; av_freep(&s->m.me.scratchpad); @@ -628,6 +651,7 @@ av_cold void ff_snow_common_end(SnowContext *s) av_freep(&s->block); av_freep(&s->scratchbuf); + av_freep(&s->emu_edge_buffer); for(i=0; iref_mvs[i]); @@ -650,4 +674,3 @@ av_cold void ff_snow_common_end(SnowContext *s) if (s->current_picture.data[0]) s->avctx->release_buffer(s->avctx, &s->current_picture); } -