[FFmpeg-devel] [PATCH 5/7] avcodec/h264dec: define and use FF_ALLOCZ_TYPED_ARRAY helper macro
lance.lmwang at gmail.com
lance.lmwang at gmail.com
Thu May 28 16:57:28 EEST 2020
From: Limin Wang <lance.lmwang at gmail.com>
The macro will help to short the long lines and avoid split them.
Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
---
libavcodec/h264dec.c | 30 +++++++++++++++---------------
libavutil/internal.h | 2 ++
2 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index d5b3df3..b797c79 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -185,17 +185,17 @@ int ff_h264_alloc_tables(H264Context *h)
const int slice_tsize = 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(slice_tsize, 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 * 8, sizeof(*h->mvd_table[0]))) ||
- !(h->mvd_table[1] = av_mallocz_array(row_mb_num * 8, 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, slice_tsize) ||
+ !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 * 8) ||
+ !FF_ALLOCZ_TYPED_ARRAY(h->mvd_table[1], row_mb_num * 8) ||
+ !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];
@@ -252,10 +252,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(h->mb_height * h->mb_stride + 1, 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, h->mb_height * h->mb_stride + 1) ||
+ !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 4acbcf5..9c4499e 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -137,6 +137,8 @@
# define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_A(32, t, v, __VA_ARGS__,,))
#endif
+#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);\
--
1.8.3.1
More information about the ffmpeg-devel
mailing list