History

avcodec/hevcdec: Use RefStruct API for RefPicListTab buffer

Given that the RefStruct API relies on the user to know the size of the objects and does not provide a way to get it, we need to store the number of elements allocated ourselves; but this is actually better than deriving it from the size in bytes.

Andreas Rheinhardt committed 4 years ago

Commit 452089e1 parent 6695c0a3 files · +12 −10Browse files

Showing the changes to libavcodec (3 of 3 files). Show all

Unified · Split

3 files
  1. libavcodec/hevc_refs.c +8 −6
  2. libavcodec/hevcdec.c +2 −3
  3. libavcodec/hevcdec.h +2 −1
libavcodec/hevc_refs.c+8−6
@@ -45,7 +45,8 @@ void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame *frame, int flags) · 44 unmodified lines
4545 av_buffer_unref(&frame->tab_mvf_buf);
4646 frame->tab_mvf = NULL;
4747
48− av_buffer_unref(&frame->rpl_buf);
48+ ff_refstruct_unref(&frame->rpl);
49+ frame->nb_rpl_elems = 0;
4950 av_buffer_unref(&frame->rpl_tab_buf);
5051 frame->rpl_tab = NULL;
5152 frame->refPicList = NULL;
@@ -95,9 +96,10 @@ static HEVCFrame *alloc_frame(HEVCContext *s) · 43 unmodified lines
9596 if (ret < 0)
9697 return NULL;
9798
98− frame->rpl_buf = av_buffer_allocz(s->pkt.nb_nals * sizeof(RefPicListTab));
99− if (!frame->rpl_buf)
99+ frame->rpl = ff_refstruct_allocz(s->pkt.nb_nals * sizeof(*frame->rpl));
100+ if (!frame->rpl)
100101 goto fail;
102+ frame->nb_rpl_elems = s->pkt.nb_nals;
101103
102104 frame->tab_mvf_buf = av_buffer_pool_get(s->tab_mvf_pool);
103105 if (!frame->tab_mvf_buf)
@@ -110,7 +112,7 @@ static HEVCFrame *alloc_frame(HEVCContext *s) · 6 unmodified lines
110112 frame->rpl_tab = (RefPicListTab **)frame->rpl_tab_buf->data;
111113 frame->ctb_count = s->ps.sps->ctb_width * s->ps.sps->ctb_height;
112114 for (j = 0; j < frame->ctb_count; j++)
113− frame->rpl_tab[j] = (RefPicListTab *)frame->rpl_buf->data;
115+ frame->rpl_tab[j] = frame->rpl;
114116
115117 if (s->sei.picture_timing.picture_struct == AV_PICTURE_STRUCTURE_TOP_FIELD)
116118 frame->frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
@@ -295,11 +297,11 @@ static int init_slice_rpl(HEVCContext *s) · 178 unmodified lines
295297 int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_segment_addr];
296298 int i;
297299
298− if (s->slice_idx >= frame->rpl_buf->size / sizeof(RefPicListTab))
300+ if (s->slice_idx >= frame->nb_rpl_elems)
299301 return AVERROR_INVALIDDATA;
300302
301303 for (i = ctb_addr_ts; i < ctb_count; i++)
302− frame->rpl_tab[i] = (RefPicListTab *)frame->rpl_buf->data + s->slice_idx;
304+ frame->rpl_tab[i] = frame->rpl + s->slice_idx;
303305
304306 frame->refPicList = (RefPicList *)frame->rpl_tab[ctb_addr_ts];
305307
libavcodec/hevcdec.c+2−3
@@ -3414,9 +3414,8 @@ static int hevc_ref_frame(HEVCContext *s, HEVCFrame *dst, HEVCFrame *src) · 3413 unmodified lines
34143414 goto fail;
34153415 dst->rpl_tab = src->rpl_tab;
34163416
3417− dst->rpl_buf = av_buffer_ref(src->rpl_buf);
3418− if (!dst->rpl_buf)
3419− goto fail;
3417+ dst->rpl = ff_refstruct_ref(src->rpl);
3418+ dst->nb_rpl_elems = src->nb_rpl_elems;
34203419
34213420 dst->poc = src->poc;
34223421 dst->ctb_count = src->ctb_count;
libavcodec/hevcdec.h+2−1
@@ -417,7 +417,8 @@ typedef struct HEVCFrame { · 416 unmodified lines
417417
418418 AVBufferRef *tab_mvf_buf;
419419 AVBufferRef *rpl_tab_buf;
420− AVBufferRef *rpl_buf;
420+ RefPicListTab *rpl; ///< RefStruct reference
421+ int nb_rpl_elems;
421422
422423 void *hwaccel_picture_private; ///< RefStruct reference
423424

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t