[FFmpeg-devel] [PATCH v2 5/7] avcodec/h264dec: define and use FF_ALLOCZ_TYPED_ARRAY helper macro
lance.lmwang at gmail.com
lance.lmwang at gmail.com
Fri May 29 08:02:32 EEST 2020
From: Limin Wang <lance.lmwang at gmail.com>
Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
---
libavcodec/h264dec.c | 30 +++++++++++++++---------------
libavutil/internal.h | 3 +++
2 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 8a4c85018f..6dba6efe56 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -185,17 +185,17 @@ int ff_h264_alloc_tables(H264Context *h)
const int st_size = big_mb_num + h->mb_stride;
int x, y;
- if (!(h->intra4x4_pred_mode = av_mallocz_array(row_mb_num * 8, sizeof(*h->intra4x4_pred_mode))) ||
- !(h->non_zero_count = av_mallocz_array(big_mb_num * 48, sizeof(*h->non_zero_count))) ||
- !(h->slice_table_base = av_mallocz_array(st_size, sizeof(*h->slice_table_base))) ||
- !(h->cbp_table = av_mallocz_array(big_mb_num, sizeof(*h->cbp_table))) ||
- !(h->chroma_pred_mode_table = av_mallocz_array(big_mb_num, sizeof(*h->chroma_pred_mode_table))) ||
- !(h->mvd_table[0] = av_mallocz_array(row_mb_num * 16, sizeof(*h->mvd_table[0]))) ||
- !(h->mvd_table[1] = av_mallocz_array(row_mb_num * 16, sizeof(*h->mvd_table[1]))) ||
- !(h->direct_table = av_mallocz_array(big_mb_num * 4, sizeof(*h->direct_table))) ||
- !(h->list_counts = av_mallocz_array(big_mb_num, sizeof(*h->list_counts))) ||
- !(h->mb2b_xy = av_mallocz_array(big_mb_num, sizeof(*h->mb2b_xy))) ||
- !(h->mb2br_xy = av_mallocz_array(big_mb_num, sizeof(*h->mb2br_xy))))
+ if (!FF_ALLOCZ_TYPED_ARRAY(h->intra4x4_pred_mode, row_mb_num * 8) ||
+ !FF_ALLOCZ_TYPED_ARRAY(h->non_zero_count, big_mb_num * 48) ||
+ !FF_ALLOCZ_TYPED_ARRAY(h->slice_table_base, st_size) ||
+ !FF_ALLOCZ_TYPED_ARRAY(h->cbp_table, big_mb_num) ||
+ !FF_ALLOCZ_TYPED_ARRAY(h->chroma_pred_mode_table, big_mb_num) ||
+ !FF_ALLOCZ_TYPED_ARRAY(h->mvd_table[0], row_mb_num * 16) ||
+ !FF_ALLOCZ_TYPED_ARRAY(h->mvd_table[1], row_mb_num * 16) ||
+ !FF_ALLOCZ_TYPED_ARRAY(h->direct_table, big_mb_num * 4) ||
+ !FF_ALLOCZ_TYPED_ARRAY(h->list_counts, big_mb_num) ||
+ !FF_ALLOCZ_TYPED_ARRAY(h->mb2b_xy, big_mb_num) ||
+ !FF_ALLOCZ_TYPED_ARRAY(h->mb2br_xy, big_mb_num))
return AVERROR(ENOMEM);
h->slice_ctx[0].intra4x4_pred_mode = h->intra4x4_pred_mode;
h->slice_ctx[0].mvd_table[0] = h->mvd_table[0];
@@ -253,10 +253,10 @@ int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl)
er->b8_stride = h->mb_width * 2 + 1;
// error resilience code looks cleaner with this
- if (!(er->mb_index2xy = av_mallocz_array(h->mb_num + 1, sizeof(*er->mb_index2xy))) ||
- !(er->error_status_table = av_mallocz_array(mb_array_size, sizeof(*er->error_status_table))) ||
- !(er->er_temp_buffer = av_mallocz_array(er_size, sizeof(*er->er_temp_buffer))) ||
- !(sl->dc_val_base = av_mallocz_array(yc_size, sizeof(*sl->dc_val_base))))
+ 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(sl->dc_val_base, yc_size))
return AVERROR(ENOMEM); // ff_h264_free_tables will clean up for us
for (y = 0; y < h->mb_height; y++)
diff --git a/libavutil/internal.h b/libavutil/internal.h
index 4acbcf56cb..00f1a578c0 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -137,6 +137,9 @@
# define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_A(32, t, v, __VA_ARGS__,,))
#endif
+#define FF_ALLOC_TYPED_ARRAY(p, nelem) (p = av_malloc_array(nelem, sizeof(*p)))
+#define FF_ALLOCZ_TYPED_ARRAY(p, nelem) (p = av_mallocz_array(nelem, sizeof(*p)))
+
#define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
{\
p = av_malloc(size);\
--
2.21.0
More information about the ffmpeg-devel
mailing list