diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-08-05 21:42:58 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2023-11-01 20:07:56 +0100 |
commit | 736b510fcc386df89a403a3ed11c4d1dec599cd1 (patch) | |
tree | 7727f2a5c55efb963c3f9f09d43faeaded1c309c /libavcodec/h264dec.c | |
parent | 26c0a7321fdef730050156fcef0b986ac4373b6c (diff) | |
download | ffmpeg-736b510fcc386df89a403a3ed11c4d1dec599cd1.tar.gz |
avcodec/h264dec: Use RefStruct-pool API instead of AVBufferPool API
It involves less allocations and therefore has the nice property
that deriving a reference from a reference can't fail.
This allows for considerable simplifications in
ff_h264_(ref|replace)_picture().
Switching to the RefStruct API also allows to make H264Picture
smaller, because some AVBufferRef* pointers could be removed
without replacement.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/h264dec.c')
-rw-r--r-- | libavcodec/h264dec.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index f346c65b20..ef9e60bbf3 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -51,6 +51,7 @@ #include "mpegutils.h" #include "profiles.h" #include "rectangle.h" +#include "refstruct.h" #include "thread.h" #include "threadframe.h" @@ -151,10 +152,10 @@ void ff_h264_free_tables(H264Context *h) av_freep(&h->mb2b_xy); av_freep(&h->mb2br_xy); - av_buffer_pool_uninit(&h->qscale_table_pool); - av_buffer_pool_uninit(&h->mb_type_pool); - av_buffer_pool_uninit(&h->motion_val_pool); - av_buffer_pool_uninit(&h->ref_index_pool); + ff_refstruct_pool_uninit(&h->qscale_table_pool); + ff_refstruct_pool_uninit(&h->mb_type_pool); + ff_refstruct_pool_uninit(&h->motion_val_pool); + ff_refstruct_pool_uninit(&h->ref_index_pool); #if CONFIG_ERROR_RESILIENCE av_freep(&h->er.mb_index2xy); @@ -308,7 +309,7 @@ static int h264_init_context(AVCodecContext *avctx, H264Context *h) ff_h264_sei_uninit(&h->sei); if (avctx->active_thread_type & FF_THREAD_FRAME) { - h->decode_error_flags_pool = av_buffer_pool_init(sizeof(atomic_int), NULL); + h->decode_error_flags_pool = ff_refstruct_pool_alloc(sizeof(atomic_int), 0); if (!h->decode_error_flags_pool) return AVERROR(ENOMEM); } @@ -359,7 +360,7 @@ static av_cold int h264_decode_end(AVCodecContext *avctx) h->cur_pic_ptr = NULL; - av_buffer_pool_uninit(&h->decode_error_flags_pool); + ff_refstruct_pool_uninit(&h->decode_error_flags_pool); av_freep(&h->slice_ctx); h->nb_slice_ctx = 0; @@ -749,7 +750,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size) if ((ret < 0 || h->er.error_occurred) && h->cur_pic_ptr) { if (h->cur_pic_ptr->decode_error_flags) { /* Frame-threading in use */ - atomic_int *decode_error = (atomic_int*)h->cur_pic_ptr->decode_error_flags->data; + atomic_int *decode_error = h->cur_pic_ptr->decode_error_flags; /* Using atomics here is not supposed to provide syncronisation; * they are merely used to allow to set decode_error from both * decoding threads in case of coded slices. */ @@ -800,7 +801,7 @@ end: ff_er_frame_end(&h->er, &decode_error_flags); if (decode_error_flags) { if (h->cur_pic_ptr->decode_error_flags) { - atomic_int *decode_error = (atomic_int*)h->cur_pic_ptr->decode_error_flags->data; + atomic_int *decode_error = h->cur_pic_ptr->decode_error_flags; atomic_fetch_or_explicit(decode_error, decode_error_flags, memory_order_relaxed); } else @@ -878,7 +879,7 @@ static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp) return ret; if (srcp->decode_error_flags) { - atomic_int *decode_error = (atomic_int*)srcp->decode_error_flags->data; + atomic_int *decode_error = srcp->decode_error_flags; /* The following is not supposed to provide synchronisation at all: * given that srcp has already finished decoding, decode_error * has already been set to its final value. */ |