mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2026-03-13 09:00:40 +08:00
avcodec/h264dec,mpeg_er: Move allocating er buffers to ff_er_init()
(This also stops zero-allocating er_temp_buffer for H.264, reverting back to the behavior from before commit 0a1dc817237b8546189960efd523257b4f62e1ab.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@@ -39,12 +39,22 @@
|
||||
#include "threadframe.h"
|
||||
#include "threadprogress.h"
|
||||
|
||||
av_cold void ff_er_init(ERContext *const s)
|
||||
av_cold int ff_er_init(ERContext *const s)
|
||||
{
|
||||
MECmpContext mecc;
|
||||
unsigned mb_array_size = s->mb_height * s->mb_stride;
|
||||
|
||||
s->error_status_table = av_mallocz(mb_array_size);
|
||||
if (!s->error_status_table)
|
||||
return AVERROR(ENOMEM);
|
||||
s->er_temp_buffer = av_malloc_array(mb_array_size, 4*sizeof(int) + 1);
|
||||
if (!s->er_temp_buffer)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
ff_me_cmp_init(&mecc, s->avctx);
|
||||
s->sad = mecc.sad[0];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -90,7 +90,7 @@ typedef struct ERContext {
|
||||
void *opaque;
|
||||
} ERContext;
|
||||
|
||||
void ff_er_init(ERContext *const s);
|
||||
int ff_er_init(ERContext *const s);
|
||||
|
||||
void ff_er_frame_start(ERContext *s);
|
||||
|
||||
|
||||
@@ -220,8 +220,6 @@ int ff_h264_alloc_tables(H264Context *h)
|
||||
}
|
||||
|
||||
if (CONFIG_ERROR_RESILIENCE) {
|
||||
const int er_size = h->mb_height * h->mb_stride * (4*sizeof(int) + 1);
|
||||
int mb_array_size = h->mb_height * h->mb_stride;
|
||||
int y_size = (2 * h->mb_width + 1) * (2 * h->mb_height + 1);
|
||||
int yc_size = y_size + 2 * big_mb_num;
|
||||
|
||||
@@ -239,8 +237,6 @@ int ff_h264_alloc_tables(H264Context *h)
|
||||
|
||||
// error resilience code looks cleaner with this
|
||||
if (!FF_ALLOCZ_TYPED_ARRAY(er->mb_index2xy, h->mb_num + 1) ||
|
||||
!FF_ALLOCZ_TYPED_ARRAY(er->error_status_table, mb_array_size) ||
|
||||
!FF_ALLOCZ_TYPED_ARRAY(er->er_temp_buffer, er_size) ||
|
||||
!FF_ALLOCZ_TYPED_ARRAY(h->dc_val_base, yc_size))
|
||||
return AVERROR(ENOMEM); // ff_h264_free_tables will clean up for us
|
||||
|
||||
@@ -256,7 +252,7 @@ int ff_h264_alloc_tables(H264Context *h)
|
||||
for (int i = 0; i < yc_size; i++)
|
||||
h->dc_val_base[i] = 1024;
|
||||
|
||||
ff_er_init(er);
|
||||
return ff_er_init(er);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -96,7 +96,6 @@ static void mpeg_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type,
|
||||
av_cold int ff_mpeg_er_init(MpegEncContext *s)
|
||||
{
|
||||
ERContext *er = &s->er;
|
||||
int mb_array_size = s->mb_height * s->mb_stride;
|
||||
|
||||
er->avctx = s->avctx;
|
||||
|
||||
@@ -111,22 +110,11 @@ av_cold int ff_mpeg_er_init(MpegEncContext *s)
|
||||
er->dc_val[1] = er->dc_val[0] + s->b8_stride * 2 * s->buffer_pools.alloc_mb_height + s->mb_stride;
|
||||
er->dc_val[2] = er->dc_val[1] + s->mb_stride * (s->buffer_pools.alloc_mb_height + 1);
|
||||
|
||||
er->er_temp_buffer = av_malloc(s->mb_height * s->mb_stride * (4*sizeof(int) + 1));
|
||||
er->error_status_table = av_mallocz(mb_array_size);
|
||||
if (!er->er_temp_buffer || !er->error_status_table)
|
||||
goto fail;
|
||||
|
||||
er->mbskip_table = s->mbskip_table;
|
||||
er->mbintra_table = s->mbintra_table;
|
||||
|
||||
er->decode_mb = mpeg_er_decode_mb;
|
||||
er->opaque = s;
|
||||
|
||||
ff_er_init(er);
|
||||
|
||||
return 0;
|
||||
fail:
|
||||
av_freep(&er->er_temp_buffer);
|
||||
av_freep(&er->error_status_table);
|
||||
return AVERROR(ENOMEM);
|
||||
return ff_er_init(er);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user