On 2013-02-13 19:51:18 +0100, Anton Khirnov wrote:
> ---
>  libavcodec/svq3.c |   51 +++++++++++++++++++++++++++++++--------------------
>  1 file changed, 31 insertions(+), 20 deletions(-)
> 
> diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c
> index 880bda2..330f3ab 100644
> --- a/libavcodec/svq3.c
> +++ b/libavcodec/svq3.c
> @@ -1027,27 +1027,29 @@ static int get_buffer(AVCodecContext *avctx, Picture 
> *pic)
>      const int b4_array_size = b4_stride * h->mb_height * 4;
>      int ret;
>  
> -    if (!pic->motion_val_base[0]) {
> +    if (!pic->motion_val_buf[0]) {
>          int i;
>  
> -        pic->mb_type_base = av_mallocz((big_mb_num + h->mb_stride) * 
> sizeof(uint32_t));
> -        if (!pic->mb_type_base)
> +        pic->mb_type_buf = av_buffer_allocz((big_mb_num + h->mb_stride) * 
> sizeof(uint32_t));
> +        if (!pic->mb_type_buf)
>              return AVERROR(ENOMEM);
> -        pic->mb_type = pic->mb_type_base + 2 * h->mb_stride + 1;
> +        pic->mb_type = (uint32_t*)pic->mb_type_buf->data + 2 * h->mb_stride 
> + 1;
>  
>          for (i = 0; i < 2; i++) {
> -            pic->motion_val_base[i] = av_mallocz(2 * (b4_array_size + 4) * 
> sizeof(int16_t));
> -            pic->ref_index[i]     = av_mallocz(4 * mb_array_size);
> -            if (!pic->motion_val_base[i] || !pic->ref_index[i])
> +            pic->motion_val_buf[i] = av_buffer_allocz(2 * (b4_array_size + 
> 4) * sizeof(int16_t));
> +            pic->ref_index_buf[i]  = av_buffer_allocz(4 * mb_array_size);
> +            if (!pic->motion_val_buf[i] || !pic->ref_index_buf[i])
>                  return AVERROR(ENOMEM);

buffer leak on error

>  
> -            pic->motion_val[i] = pic->motion_val_base[i] + 4;
> +            pic->motion_val[i] = (int16_t 
> (*)[2])pic->motion_val_buf[i]->data + 4;
> +            pic->ref_index[i]  = pic->ref_index_buf[i]->data;
>          }
>      }
>      pic->f.motion_subsample_log2 = 2;
>      pic->reference = !(h->pict_type == AV_PICTURE_TYPE_B);
>  
> -    ret = ff_get_buffer(avctx, &pic->f);
> +    ret = ff_get_buffer(avctx, &pic->f,
> +                        pic->reference ? AV_GET_BUFFER_FLAG_REF : 0);
>  
>      h->linesize   = pic->f.linesize[0];
>      h->uvlinesize = pic->f.linesize[1];
> @@ -1067,7 +1069,9 @@ static int svq3_decode_frame(AVCodecContext *avctx, 
> void *data,
>      /* special case for last picture */
>      if (buf_size == 0) {
>          if (s->next_pic->f.data[0] && !h->low_delay && 
> !s->last_frame_output) {
> -            *(AVFrame *) data   = s->next_pic->f;
> +            ret = av_frame_ref(data, &s->next_pic->f);
> +            if (ret < 0)
> +                return ret;
>              s->last_frame_output = 1;
>              *got_frame          = 1;
>          }
> @@ -1086,8 +1090,7 @@ static int svq3_decode_frame(AVCodecContext *avctx, 
> void *data,
>      if (h->pict_type != AV_PICTURE_TYPE_B)
>          FFSWAP(Picture*, s->next_pic, s->last_pic);
>  
> -    if (s->cur_pic->f.data[0])
> -        avctx->release_buffer(avctx, &s->cur_pic->f);
> +    av_frame_unref(&s->cur_pic->f);
>  
>      /* for skipping the frame */
>      s->cur_pic->f.pict_type = h->pict_type;
> @@ -1098,7 +1101,11 @@ static int svq3_decode_frame(AVCodecContext *avctx, 
> void *data,
>          return ret;
>  
>      h->cur_pic_ptr = s->cur_pic;
> +    av_frame_unref(&h->cur_pic.f);
>      h->cur_pic     = *s->cur_pic;
> +    ret = av_frame_ref(&h->cur_pic.f, &s->cur_pic->f);
> +    if (ret < 0)
> +        return ret;
>  
>      for (i = 0; i < 16; i++) {
>          h->block_offset[i]           = (4 * ((scan8[i] - scan8[0]) & 7)) + 4 
> * h->linesize * ((scan8[i] - scan8[0]) >> 3);
> @@ -1229,9 +1236,11 @@ static int svq3_decode_frame(AVCodecContext *avctx, 
> void *data,
>      }
>  
>      if (h->pict_type == AV_PICTURE_TYPE_B || h->low_delay)
> -        *(AVFrame *)data = s->cur_pic->f;
> -    else
> -        *(AVFrame *)data = s->last_pic->f;
> +        ret = av_frame_ref(data, &s->cur_pic->f);
> +    else if (s->last_pic->f.data[0])
> +        ret = av_frame_ref(data, &s->last_pic->f);
> +    if (ret < 0)
> +        return ret;
>  
>      /* Do not output the last pic after seeking. */
>      if (s->last_pic->f.data[0] || h->low_delay)
> @@ -1239,6 +1248,8 @@ static int svq3_decode_frame(AVCodecContext *avctx, 
> void *data,
>  
>      if (h->pict_type != AV_PICTURE_TYPE_B) {
>          FFSWAP(Picture*, s->cur_pic, s->next_pic);
> +    } else {
> +        av_frame_unref(&s->cur_pic->f);
>      }
>  
>      return buf_size;
> @@ -1248,13 +1259,12 @@ static void free_picture(AVCodecContext *avctx, 
> Picture *pic)
>  {
>      int i;
>      for (i = 0; i < 2; i++) {
> -        av_freep(&pic->motion_val_base[i]);
> -        av_freep(&pic->ref_index[i]);
> +        av_buffer_unref(&pic->motion_val_buf[i]);
> +        av_buffer_unref(&pic->ref_index_buf[i]);
>      }
> -    av_freep(&pic->mb_type_base);
> +    av_buffer_unref(&pic->mb_type_buf);
>  
> -    if (pic->f.data[0])
> -        avctx->release_buffer(avctx, &pic->f);
> +    av_frame_unref(&pic->f);
>      av_freep(&pic);
>  }
>  
> @@ -1266,6 +1276,7 @@ static int svq3_decode_end(AVCodecContext *avctx)
>      free_picture(avctx, s->cur_pic);
>      free_picture(avctx, s->next_pic);
>      free_picture(avctx, s->last_pic);
> +    av_frame_unref(&h->cur_pic.f);
>  
>      ff_h264_free_context(h);

otherwise ok

Janne
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to