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

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
45 av_buffer_unref(&frame->tab_mvf_buf);45 av_buffer_unref(&frame->tab_mvf_buf);
46 frame->tab_mvf = NULL;46 frame->tab_mvf = NULL;
47 47
48 av_buffer_unref(&frame->rpl_buf);48 ff_refstruct_unref(&frame->rpl);
49 frame->nb_rpl_elems = 0;
49 av_buffer_unref(&frame->rpl_tab_buf);50 av_buffer_unref(&frame->rpl_tab_buf);
50 frame->rpl_tab = NULL;51 frame->rpl_tab = NULL;
51 frame->refPicList = NULL;52 frame->refPicList = NULL;
@@ -95,9 +96,10 @@ static HEVCFrame *alloc_frame(HEVCContext *s) · 43 unmodified lines
95 if (ret < 0)96 if (ret < 0)
96 return NULL;97 return NULL;
97 98
98 frame->rpl_buf = av_buffer_allocz(s->pkt.nb_nals * sizeof(RefPicListTab));99 frame->rpl = ff_refstruct_allocz(s->pkt.nb_nals * sizeof(*frame->rpl));
99 if (!frame->rpl_buf)100 if (!frame->rpl)
100 goto fail;101 goto fail;
102 frame->nb_rpl_elems = s->pkt.nb_nals;
101 103
102 frame->tab_mvf_buf = av_buffer_pool_get(s->tab_mvf_pool);104 frame->tab_mvf_buf = av_buffer_pool_get(s->tab_mvf_pool);
103 if (!frame->tab_mvf_buf)105 if (!frame->tab_mvf_buf)
@@ -110,7 +112,7 @@ static HEVCFrame *alloc_frame(HEVCContext *s) · 6 unmodified lines
110 frame->rpl_tab = (RefPicListTab **)frame->rpl_tab_buf->data;112 frame->rpl_tab = (RefPicListTab **)frame->rpl_tab_buf->data;
111 frame->ctb_count = s->ps.sps->ctb_width * s->ps.sps->ctb_height;113 frame->ctb_count = s->ps.sps->ctb_width * s->ps.sps->ctb_height;
112 for (j = 0; j < frame->ctb_count; j++)114 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;
114 116
115 if (s->sei.picture_timing.picture_struct == AV_PICTURE_STRUCTURE_TOP_FIELD)117 if (s->sei.picture_timing.picture_struct == AV_PICTURE_STRUCTURE_TOP_FIELD)
116 frame->frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;118 frame->frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
@@ -295,11 +297,11 @@ static int init_slice_rpl(HEVCContext *s) · 178 unmodified lines
295 int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_segment_addr];297 int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_segment_addr];
296 int i;298 int i;
297 299
298 if (s->slice_idx >= frame->rpl_buf->size / sizeof(RefPicListTab))300 if (s->slice_idx >= frame->nb_rpl_elems)
299 return AVERROR_INVALIDDATA;301 return AVERROR_INVALIDDATA;
300 302
301 for (i = ctb_addr_ts; i < ctb_count; i++)303 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;
303 305
304 frame->refPicList = (RefPicList *)frame->rpl_tab[ctb_addr_ts];306 frame->refPicList = (RefPicList *)frame->rpl_tab[ctb_addr_ts];
305 307
libavcodec/hevcdec.c+2−3
@@ -3414,9 +3414,8 @@ static int hevc_ref_frame(HEVCContext *s, HEVCFrame *dst, HEVCFrame *src) · 3413 unmodified lines
3414 goto fail;3414 goto fail;
3415 dst->rpl_tab = src->rpl_tab;3415 dst->rpl_tab = src->rpl_tab;
3416 3416
3417 dst->rpl_buf = av_buffer_ref(src->rpl_buf);3417 dst->rpl = ff_refstruct_ref(src->rpl);
3418 if (!dst->rpl_buf)3418 dst->nb_rpl_elems = src->nb_rpl_elems;
3419 goto fail;
3420 3419
3421 dst->poc = src->poc;3420 dst->poc = src->poc;
3422 dst->ctb_count = src->ctb_count;3421 dst->ctb_count = src->ctb_count;
libavcodec/hevcdec.h+2−1
@@ -417,7 +417,8 @@ typedef struct HEVCFrame { · 416 unmodified lines
417 417
418 AVBufferRef *tab_mvf_buf;418 AVBufferRef *tab_mvf_buf;
419 AVBufferRef *rpl_tab_buf;419 AVBufferRef *rpl_tab_buf;
420 AVBufferRef *rpl_buf;420 RefPicListTab *rpl; ///< RefStruct reference
421 int nb_rpl_elems;
421 422
422 void *hwaccel_picture_private; ///< RefStruct reference423 void *hwaccel_picture_private; ///< RefStruct reference
423 424

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