History

lavc/hevcdec: move HEVCContext.sao to HEVCLayerContext

Anton Khirnov committed 2 years ago

Commit 3d4294e1 parent 747609e3 files · +32 −29Browse files

Unified · Split

3 files
  1. libavcodec/hevc/filter.c +15 −14
  2. libavcodec/hevc/hevcdec.c +15 −14
  3. libavcodec/hevc/hevcdec.h +2 −1
libavcodec/hevc/filter.c+15−14
@@ -264,7 +264,8 @@ static void restore_tqb_pixels(const HEVCContext *s, · 263 unmodified lines
264264
265265 #define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)])
266266
267−static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s,
267+static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCLayerContext *l,
268+ const HEVCContext *s,
268269 const HEVCPPS *pps, const HEVCSPS *sps,
269270 int x, int y)
270271 {
@@ -275,7 +276,7 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s, · 4 unmodified lines
275276 int y_ctb = y >> sps->log2_ctb_size;
276277 int ctb_addr_rs = y_ctb * sps->ctb_width + x_ctb;
277278 int ctb_addr_ts = pps->ctb_addr_rs_to_ts[ctb_addr_rs];
278− SAOParams *sao = &CTB(s->sao, x_ctb, y_ctb);
279+ SAOParams *sao = &CTB(l->sao, x_ctb, y_ctb);
279280 // flags indicating unfilterable edges
280281 uint8_t vert_edge[] = { 0, 0 };
281282 uint8_t horiz_edge[] = { 0, 0 };
@@ -385,17 +386,17 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s, · 103 unmodified lines
385386 src1[1] = s->sao_pixel_buffer_h[c_idx] + (((2 * y_ctb - 1) * w + x0 - left) << sh);
386387 pos = 0;
387388 if (left) {
388− src_idx = (CTB(s->sao, x_ctb-1, y_ctb-1).type_idx[c_idx] ==
389+ src_idx = (CTB(l->sao, x_ctb-1, y_ctb-1).type_idx[c_idx] ==
389390 SAO_APPLIED);
390391 copy_pixel(dst1, src1[src_idx], sh);
391392 pos += (1 << sh);
392393 }
393− src_idx = (CTB(s->sao, x_ctb, y_ctb-1).type_idx[c_idx] ==
394+ src_idx = (CTB(l->sao, x_ctb, y_ctb-1).type_idx[c_idx] ==
394395 SAO_APPLIED);
395396 memcpy(dst1 + pos, src1[src_idx] + pos, width << sh);
396397 if (right) {
397398 pos += width << sh;
398− src_idx = (CTB(s->sao, x_ctb+1, y_ctb-1).type_idx[c_idx] ==
399+ src_idx = (CTB(l->sao, x_ctb+1, y_ctb-1).type_idx[c_idx] ==
399400 SAO_APPLIED);
400401 copy_pixel(dst1 + pos, src1[src_idx] + pos, sh);
401402 }
@@ -412,24 +413,24 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s, · 10 unmodified lines
412413 src1[1] = s->sao_pixel_buffer_h[c_idx] + (((2 * y_ctb + 2) * w + x0 - left) << sh);
413414 pos = 0;
414415 if (left) {
415− src_idx = (CTB(s->sao, x_ctb-1, y_ctb+1).type_idx[c_idx] ==
416+ src_idx = (CTB(l->sao, x_ctb-1, y_ctb+1).type_idx[c_idx] ==
416417 SAO_APPLIED);
417418 copy_pixel(dst1, src1[src_idx], sh);
418419 pos += (1 << sh);
419420 }
420− src_idx = (CTB(s->sao, x_ctb, y_ctb+1).type_idx[c_idx] ==
421+ src_idx = (CTB(l->sao, x_ctb, y_ctb+1).type_idx[c_idx] ==
421422 SAO_APPLIED);
422423 memcpy(dst1 + pos, src1[src_idx] + pos, width << sh);
423424 if (right) {
424425 pos += width << sh;
425− src_idx = (CTB(s->sao, x_ctb+1, y_ctb+1).type_idx[c_idx] ==
426+ src_idx = (CTB(l->sao, x_ctb+1, y_ctb+1).type_idx[c_idx] ==
426427 SAO_APPLIED);
427428 copy_pixel(dst1 + pos, src1[src_idx] + pos, sh);
428429 }
429430 }
430431 left_pixels = 0;
431432 if (!left_edge) {
432− if (CTB(s->sao, x_ctb-1, y_ctb).type_idx[c_idx] == SAO_APPLIED) {
433+ if (CTB(l->sao, x_ctb-1, y_ctb).type_idx[c_idx] == SAO_APPLIED) {
433434 copy_vert(dst - (1 << sh),
434435 s->sao_pixel_buffer_v[c_idx] + (((2 * x_ctb - 1) * h + y0) << sh),
435436 sh, height, stride_dst, 1 << sh);
@@ -439,7 +440,7 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s, · 3 unmodified lines
439440 }
440441 right_pixels = 0;
441442 if (!right_edge) {
442− if (CTB(s->sao, x_ctb+1, y_ctb).type_idx[c_idx] == SAO_APPLIED) {
443+ if (CTB(l->sao, x_ctb+1, y_ctb).type_idx[c_idx] == SAO_APPLIED) {
443444 copy_vert(dst + (width << sh),
444445 s->sao_pixel_buffer_v[c_idx] + (((2 * x_ctb + 2) * h + y0) << sh),
445446 sh, height, stride_dst, 1 << sh);
@@ -889,16 +890,16 @@ void ff_hevc_hls_filter(HEVCLocalContext *lc, const HEVCLayerContext *l, · 443 unmodified lines
889890 if (sps->sao_enabled && !skip) {
890891 int y_end = y >= sps->height - ctb_size;
891892 if (y && x)
892− sao_filter_CTB(lc, s, pps, sps, x - ctb_size, y - ctb_size);
893+ sao_filter_CTB(lc, l, s, pps, sps, x - ctb_size, y - ctb_size);
893894 if (x && y_end)
894− sao_filter_CTB(lc, s, pps, sps, x - ctb_size, y);
895+ sao_filter_CTB(lc, l, s, pps, sps, x - ctb_size, y);
895896 if (y && x_end) {
896− sao_filter_CTB(lc, s, pps, sps, x, y - ctb_size);
897+ sao_filter_CTB(lc, l, s, pps, sps, x, y - ctb_size);
897898 if (s->avctx->active_thread_type & FF_THREAD_FRAME )
898899 ff_progress_frame_report(&s->cur_frame->tf, y);
899900 }
900901 if (x_end && y_end) {
901− sao_filter_CTB(lc, s, pps, sps, x , y);
902+ sao_filter_CTB(lc, l, s, pps, sps, x , y);
902903 if (s->avctx->active_thread_type & FF_THREAD_FRAME )
903904 ff_progress_frame_report(&s->cur_frame->tf, y + ctb_size);
904905 }
libavcodec/hevc/hevcdec.c+15−14
@@ -66,9 +66,9 @@ static const uint8_t hevc_pel_weight[65] = { [2] = 0, [4] = 1, [6] = 2, [8] = 3, · 65 unmodified lines
6666 */
6767
6868 /* free everything allocated by pic_arrays_init() */
69−static void pic_arrays_free(HEVCContext *s)
69+static void pic_arrays_free(HEVCContext *s, HEVCLayerContext *l)
7070 {
71− av_freep(&s->sao);
71+ av_freep(&l->sao);
7272 av_freep(&s->deblock);
7373
7474 av_freep(&s->skip_flag);
@@ -103,9 +103,9 @@ static int pic_arrays_init(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *s · 28 unmodified lines
103103 l->bs_width = (width >> 2) + 1;
104104 l->bs_height = (height >> 2) + 1;
105105
106− s->sao = av_calloc(ctb_count, sizeof(*s->sao));
106+ l->sao = av_calloc(ctb_count, sizeof(*l->sao));
107107 s->deblock = av_calloc(ctb_count, sizeof(*s->deblock));
108− if (!s->sao || !s->deblock)
108+ if (!l->sao || !s->deblock)
109109 goto fail;
110110
111111 s->skip_flag = av_malloc_array(sps->min_cb_height, sps->min_cb_width);
@@ -140,7 +140,7 @@ static int pic_arrays_init(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *s · 28 unmodified lines
140140 return 0;
141141
142142 fail:
143− pic_arrays_free(s);
143+ pic_arrays_free(s, l);
144144 return AVERROR(ENOMEM);
145145 }
146146
@@ -531,7 +531,7 @@ static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps) · 384 unmodified lines
531531 {
532532 int ret, i;
533533
534− pic_arrays_free(s);
534+ pic_arrays_free(s, l);
535535 s->ps.sps = NULL;
536536 ff_refstruct_unref(&s->vps);
537537
@@ -576,7 +576,7 @@ static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps) · 38 unmodified lines
576576 return 0;
577577
578578 fail:
579− pic_arrays_free(s);
579+ pic_arrays_free(s, l);
580580 for (i = 0; i < 3; i++) {
581581 av_freep(&s->sao_pixel_buffer_h[i]);
582582 av_freep(&s->sao_pixel_buffer_v[i]);
@@ -990,21 +990,21 @@ do { \ · 407 unmodified lines
990990 if (!sao_merge_up_flag && !sao_merge_left_flag) \
991991 sao->elem = value; \
992992 else if (sao_merge_left_flag) \
993− sao->elem = CTB(s->sao, rx-1, ry).elem; \
993+ sao->elem = CTB(l->sao, rx-1, ry).elem; \
994994 else if (sao_merge_up_flag) \
995− sao->elem = CTB(s->sao, rx, ry-1).elem; \
995+ sao->elem = CTB(l->sao, rx, ry-1).elem; \
996996 else \
997997 sao->elem = 0; \
998998 } while (0)
999999
1000−static void hls_sao_param(HEVCLocalContext *lc,
1000+static void hls_sao_param(HEVCLocalContext *lc, const HEVCLayerContext *l,
10011001 const HEVCPPS *pps, const HEVCSPS *sps,
10021002 int rx, int ry)
10031003 {
10041004 const HEVCContext *const s = lc->parent;
10051005 int sao_merge_left_flag = 0;
10061006 int sao_merge_up_flag = 0;
1007− SAOParams *sao = &CTB(s->sao, rx, ry);
1007+ SAOParams *sao = &CTB(l->sao, rx, ry);
10081008 int c_idx, i;
10091009
10101010 if (s->sh.slice_sample_adaptive_offset_flag[0] ||
@@ -2556,7 +2556,7 @@ static int hls_decode_entry(HEVCContext *s, GetBitContext *gb) · 1545 unmodified lines
25562556 return ret;
25572557 }
25582558
2559− hls_sao_param(lc, pps, sps,
2559+ hls_sao_param(lc, l, pps, sps,
25602560 x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size);
25612561
25622562 s->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset;
@@ -2624,7 +2624,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctx, void *hevc_lclist, · 61 unmodified lines
26242624 ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, data, data_size, 1);
26252625 if (ret < 0)
26262626 goto error;
2627− hls_sao_param(lc, pps, sps,
2627+ hls_sao_param(lc, l, pps, sps,
26282628 x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size);
26292629 more_data = hls_coding_quadtree(lc, l, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0);
26302630
@@ -3518,7 +3518,8 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx) · 887 unmodified lines
35183518 HEVCContext *s = avctx->priv_data;
35193519 int i;
35203520
3521− pic_arrays_free(s);
3521+ for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++)
3522+ pic_arrays_free(s, &s->layers[i]);
35223523
35233524 ff_refstruct_unref(&s->vps);
35243525 ff_refstruct_unref(&s->pps);
libavcodec/hevc/hevcdec.h+2−1
@@ -443,6 +443,8 @@ typedef struct HEVCLayerContext { · 442 unmodified lines
443443
444444 int bs_width;
445445 int bs_height;
446+
447+ SAOParams *sao;
446448 } HEVCLayerContext;
447449
448450 typedef struct HEVCContext {
@@ -476,7 +478,6 @@ typedef struct HEVCContext { · 27 unmodified lines
476478 const HEVCVPS *vps; ///< RefStruct reference
477479 const HEVCPPS *pps; ///< RefStruct reference
478480 SliceHeader sh;
479− SAOParams *sao;
480481 DBParams *deblock;
481482 enum HEVCNALUnitType nal_unit_type;
482483 int temporal_id; ///< temporal_id_plus1 - 1

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