X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fmpegpicture.c;h=0652b7c87946bd571bc1941067da2f0a5a3b1c24;hb=718e03e5f297564b828730dfc012fa3f6fbf576b;hp=c0e06900fe2a79e4c9335bf3cb3423cac68bd938;hpb=64425e005edf3bdd77c34c078c3e74ab5ecef557;p=ffmpeg diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c index c0e06900fe2..0652b7c8794 100644 --- a/libavcodec/mpegpicture.c +++ b/libavcodec/mpegpicture.c @@ -23,6 +23,7 @@ #include "libavutil/avassert.h" #include "libavutil/common.h" #include "libavutil/pixdesc.h" +#include "libavutil/imgutils.h" #include "avcodec.h" #include "motion_est.h" @@ -57,6 +58,7 @@ do {\ int ff_mpeg_framesize_alloc(AVCodecContext *avctx, MotionEstContext *me, ScratchpadContext *sc, int linesize) { +# define EMU_EDGE_HEIGHT (4 * 70) int alloc_size = FFALIGN(FFABS(linesize) + 64, 32); if (avctx->hwaccel) @@ -67,26 +69,27 @@ int ff_mpeg_framesize_alloc(AVCodecContext *avctx, MotionEstContext *me, return AVERROR_PATCHWELCOME; } + if (av_image_check_size2(alloc_size, EMU_EDGE_HEIGHT, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0) + return AVERROR(ENOMEM); + // edge emu needs blocksize + filter length - 1 // (= 17x17 for halfpel / 21x21 for H.264) // VC-1 computes luma and chroma simultaneously and needs 19X19 + 9x9 // at uvlinesize. It supports only YUV420 so 24x24 is enough // linesize * interlaced * MBsize // we also use this buffer for encoding in encode_mb_internal() needig an additional 32 lines - FF_ALLOCZ_ARRAY_OR_GOTO(avctx, sc->edge_emu_buffer, alloc_size, 4 * 70, - fail); + if (!FF_ALLOCZ_TYPED_ARRAY(sc->edge_emu_buffer, alloc_size * EMU_EDGE_HEIGHT) || + !FF_ALLOCZ_TYPED_ARRAY(me->scratchpad, alloc_size * 4 * 16 * 2)) { + av_freep(&sc->edge_emu_buffer); + return AVERROR(ENOMEM); + } - FF_ALLOCZ_ARRAY_OR_GOTO(avctx, me->scratchpad, alloc_size, 4 * 16 * 2, - fail) me->temp = me->scratchpad; sc->rd_scratchpad = me->scratchpad; sc->b_scratchpad = me->scratchpad; sc->obmc_scratchpad = me->scratchpad + 16; return 0; -fail: - av_freep(&sc->edge_emu_buffer); - return AVERROR(ENOMEM); } /** @@ -203,10 +206,7 @@ static int alloc_picture_tables(AVCodecContext *avctx, Picture *pic, int encodin } if (out_format == FMT_H263 || encoding || -#if FF_API_DEBUG_MV - avctx->debug_mv || -#endif - (avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS)) { + (avctx->export_side_data & AV_CODEC_EXPORT_DATA_MVS)) { int mv_size = 2 * (b8_array_size + 4) * sizeof(int16_t); int ref_index_size = 4 * mb_array_size; @@ -220,6 +220,7 @@ static int alloc_picture_tables(AVCodecContext *avctx, Picture *pic, int encodin pic->alloc_mb_width = mb_width; pic->alloc_mb_height = mb_height; + pic->alloc_mb_stride = mb_stride; return 0; } @@ -315,30 +316,22 @@ void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *pic) int ff_update_picture_tables(Picture *dst, Picture *src) { - int i; - -#define UPDATE_TABLE(table) \ -do { \ - if (src->table && \ - (!dst->table || dst->table->buffer != src->table->buffer)) { \ - av_buffer_unref(&dst->table); \ - dst->table = av_buffer_ref(src->table); \ - if (!dst->table) { \ - ff_free_picture_tables(dst); \ - return AVERROR(ENOMEM); \ - } \ - } \ -} while (0) + int i, ret; - UPDATE_TABLE(mb_var_buf); - UPDATE_TABLE(mc_mb_var_buf); - UPDATE_TABLE(mb_mean_buf); - UPDATE_TABLE(mbskip_table_buf); - UPDATE_TABLE(qscale_table_buf); - UPDATE_TABLE(mb_type_buf); + ret = av_buffer_replace(&dst->mb_var_buf, src->mb_var_buf); + ret |= av_buffer_replace(&dst->mc_mb_var_buf, src->mc_mb_var_buf); + ret |= av_buffer_replace(&dst->mb_mean_buf, src->mb_mean_buf); + ret |= av_buffer_replace(&dst->mbskip_table_buf, src->mbskip_table_buf); + ret |= av_buffer_replace(&dst->qscale_table_buf, src->qscale_table_buf); + ret |= av_buffer_replace(&dst->mb_type_buf, src->mb_type_buf); for (i = 0; i < 2; i++) { - UPDATE_TABLE(motion_val_buf[i]); - UPDATE_TABLE(ref_index_buf[i]); + ret |= av_buffer_replace(&dst->motion_val_buf[i], src->motion_val_buf[i]); + ret |= av_buffer_replace(&dst->ref_index_buf[i], src->ref_index_buf[i]); + } + + if (ret < 0) { + ff_free_picture_tables(dst); + return ret; } dst->mb_var = src->mb_var; @@ -354,6 +347,7 @@ do { \ dst->alloc_mb_width = src->alloc_mb_width; dst->alloc_mb_height = src->alloc_mb_height; + dst->alloc_mb_stride = src->alloc_mb_stride; return 0; }