Commit 70211539 authored by Anton Khirnov's avatar Anton Khirnov

hevc: deobfuscate slice/tile boundary handling for DBF

Use named constants instead of magic numbers, avoid using variables with
inverse meaning from what their name implies.
parent 55019715
...@@ -1420,9 +1420,7 @@ do { ...@@ -1420,9 +1420,7 @@ do {
} }
} }
if (!s->sh.disable_deblocking_filter_flag) { if (!s->sh.disable_deblocking_filter_flag) {
ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_trafo_size, ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_trafo_size);
lc->slice_or_tiles_up_boundary,
lc->slice_or_tiles_left_boundary);
if (s->pps->transquant_bypass_enable_flag && if (s->pps->transquant_bypass_enable_flag &&
lc->cu.cu_transquant_bypass_flag) lc->cu.cu_transquant_bypass_flag)
set_deblocking_bypass(s, x0, y0, log2_trafo_size); set_deblocking_bypass(s, x0, y0, log2_trafo_size);
...@@ -1448,11 +1446,8 @@ static int hls_pcm_sample(HEVCContext *s, int x0, int y0, int log2_cb_size) ...@@ -1448,11 +1446,8 @@ static int hls_pcm_sample(HEVCContext *s, int x0, int y0, int log2_cb_size)
const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3); const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3);
int ret; int ret;
if (!s->sh.disable_deblocking_filter_flag) { if (!s->sh.disable_deblocking_filter_flag)
ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size, ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size);
lc->slice_or_tiles_up_boundary,
lc->slice_or_tiles_left_boundary);
}
ret = init_get_bits(&gb, pcm, length); ret = init_get_bits(&gb, pcm, length);
if (ret < 0) if (ret < 0)
...@@ -2100,9 +2095,7 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size) ...@@ -2100,9 +2095,7 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size)
intra_prediction_unit_default_value(s, x0, y0, log2_cb_size); intra_prediction_unit_default_value(s, x0, y0, log2_cb_size);
if (!s->sh.disable_deblocking_filter_flag) if (!s->sh.disable_deblocking_filter_flag)
ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size, ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size);
lc->slice_or_tiles_up_boundary,
lc->slice_or_tiles_left_boundary);
} else { } else {
if (s->sh.slice_type != I_SLICE) if (s->sh.slice_type != I_SLICE)
lc->cu.pred_mode = ff_hevc_pred_mode_decode(s); lc->cu.pred_mode = ff_hevc_pred_mode_decode(s);
...@@ -2185,9 +2178,7 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size) ...@@ -2185,9 +2178,7 @@ static int hls_coding_unit(HEVCContext *s, int x0, int y0, int log2_cb_size)
return ret; return ret;
} else { } else {
if (!s->sh.disable_deblocking_filter_flag) if (!s->sh.disable_deblocking_filter_flag)
ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size, ff_hevc_deblocking_boundary_strengths(s, x0, y0, log2_cb_size);
lc->slice_or_tiles_up_boundary,
lc->slice_or_tiles_left_boundary);
} }
} }
} }
...@@ -2265,9 +2256,6 @@ static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb, ...@@ -2265,9 +2256,6 @@ static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb,
int ctb_addr_rs = s->pps->ctb_addr_ts_to_rs[ctb_addr_ts]; int ctb_addr_rs = s->pps->ctb_addr_ts_to_rs[ctb_addr_ts];
int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr; int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr;
int tile_left_boundary, tile_up_boundary;
int slice_left_boundary, slice_up_boundary;
s->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr; s->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr;
if (s->pps->entropy_coding_sync_enabled_flag) { if (s->pps->entropy_coding_sync_enabled_flag) {
...@@ -2287,25 +2275,25 @@ static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb, ...@@ -2287,25 +2275,25 @@ static void hls_decode_neighbour(HEVCContext *s, int x_ctb, int y_ctb,
lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, s->sps->height); lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, s->sps->height);
lc->boundary_flags = 0;
if (s->pps->tiles_enabled_flag) { if (s->pps->tiles_enabled_flag) {
tile_left_boundary = x_ctb > 0 && if (x_ctb > 0 && s->pps->tile_id[ctb_addr_ts] != s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]])
s->pps->tile_id[ctb_addr_ts] == s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]]; lc->boundary_flags |= BOUNDARY_LEFT_TILE;
slice_left_boundary = x_ctb > 0 && if (x_ctb > 0 && s->tab_slice_address[ctb_addr_rs] != s->tab_slice_address[ctb_addr_rs - 1])
s->tab_slice_address[ctb_addr_rs] == s->tab_slice_address[ctb_addr_rs - 1]; lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
tile_up_boundary = y_ctb > 0 && if (y_ctb > 0 && s->pps->tile_id[ctb_addr_ts] != s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs - s->sps->ctb_width]])
s->pps->tile_id[ctb_addr_ts] == s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs - s->sps->ctb_width]]; lc->boundary_flags |= BOUNDARY_UPPER_TILE;
slice_up_boundary = y_ctb > 0 && if (y_ctb > 0 && s->tab_slice_address[ctb_addr_rs] != s->tab_slice_address[ctb_addr_rs - s->sps->ctb_width])
s->tab_slice_address[ctb_addr_rs] == s->tab_slice_address[ctb_addr_rs - s->sps->ctb_width]; lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
} else { } else {
tile_left_boundary = if (!ctb_addr_in_slice > 0)
tile_up_boundary = 1; lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
slice_left_boundary = ctb_addr_in_slice > 0; if (ctb_addr_in_slice < s->sps->ctb_width)
slice_up_boundary = ctb_addr_in_slice >= s->sps->ctb_width; lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
} }
lc->slice_or_tiles_left_boundary = (!slice_left_boundary) + (!tile_left_boundary << 1);
lc->slice_or_tiles_up_boundary = (!slice_up_boundary + (!tile_up_boundary << 1)); lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE));
lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && tile_left_boundary); lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= s->sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE));
lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= s->sps->ctb_width) && tile_up_boundary);
lc->ctb_up_right_flag = ((y_ctb > 0) && (ctb_addr_in_slice+1 >= s->sps->ctb_width) && (s->pps->tile_id[ctb_addr_ts] == s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs+1 - s->sps->ctb_width]])); lc->ctb_up_right_flag = ((y_ctb > 0) && (ctb_addr_in_slice+1 >= s->sps->ctb_width) && (s->pps->tile_id[ctb_addr_ts] == s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs+1 - s->sps->ctb_width]]));
lc->ctb_up_left_flag = ((x_ctb > 0) && (y_ctb > 0) && (ctb_addr_in_slice-1 >= s->sps->ctb_width) && (s->pps->tile_id[ctb_addr_ts] == s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs-1 - s->sps->ctb_width]])); lc->ctb_up_left_flag = ((x_ctb > 0) && (y_ctb > 0) && (ctb_addr_in_slice-1 >= s->sps->ctb_width) && (s->pps->tile_id[ctb_addr_ts] == s->pps->tile_id[s->pps->ctb_addr_rs_to_ts[ctb_addr_rs-1 - s->sps->ctb_width]]));
} }
......
...@@ -740,8 +740,13 @@ typedef struct HEVCLocalContext { ...@@ -740,8 +740,13 @@ typedef struct HEVCLocalContext {
PredictionUnit pu; PredictionUnit pu;
NeighbourAvailable na; NeighbourAvailable na;
uint8_t slice_or_tiles_left_boundary; #define BOUNDARY_LEFT_SLICE (1 << 0)
uint8_t slice_or_tiles_up_boundary; #define BOUNDARY_LEFT_TILE (1 << 1)
#define BOUNDARY_UPPER_SLICE (1 << 2)
#define BOUNDARY_UPPER_TILE (1 << 3)
/* properties of the boundary of the current CTB for the purposes
* of the deblocking filter */
int boundary_flags;
} HEVCLocalContext; } HEVCLocalContext;
typedef struct HEVCContext { typedef struct HEVCContext {
...@@ -970,9 +975,7 @@ void ff_hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0, ...@@ -970,9 +975,7 @@ void ff_hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0,
void ff_hevc_set_qPy(HEVCContext *s, int xC, int yC, int xBase, int yBase, void ff_hevc_set_qPy(HEVCContext *s, int xC, int yC, int xBase, int yBase,
int log2_cb_size); int log2_cb_size);
void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0,
int log2_trafo_size, int log2_trafo_size);
int slice_or_tiles_up_boundary,
int slice_or_tiles_left_boundary);
int ff_hevc_cu_qp_delta_sign_flag(HEVCContext *s); int ff_hevc_cu_qp_delta_sign_flag(HEVCContext *s);
int ff_hevc_cu_qp_delta_abs(HEVCContext *s); int ff_hevc_cu_qp_delta_abs(HEVCContext *s);
void ff_hevc_hls_filter(HEVCContext *s, int x, int y); void ff_hevc_hls_filter(HEVCContext *s, int x, int y);
......
...@@ -584,10 +584,9 @@ static int boundary_strength(HEVCContext *s, MvField *curr, ...@@ -584,10 +584,9 @@ static int boundary_strength(HEVCContext *s, MvField *curr,
} }
void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0,
int log2_trafo_size, int log2_trafo_size)
int slice_or_tiles_up_boundary,
int slice_or_tiles_left_boundary)
{ {
HEVCLocalContext *lc = &s->HEVClc;
MvField *tab_mvf = s->ref->tab_mvf; MvField *tab_mvf = s->ref->tab_mvf;
int log2_min_pu_size = s->sps->log2_min_pu_size; int log2_min_pu_size = s->sps->log2_min_pu_size;
int log2_min_tu_size = s->sps->log2_min_tb_size; int log2_min_tu_size = s->sps->log2_min_tb_size;
...@@ -616,11 +615,11 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, ...@@ -616,11 +615,11 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0,
bs = boundary_strength(s, curr, curr_cbf_luma, bs = boundary_strength(s, curr, curr_cbf_luma,
top, top_cbf_luma, top_refPicList, 1); top, top_cbf_luma, top_refPicList, 1);
if (!s->sh.slice_loop_filter_across_slices_enabled_flag && if (!s->sh.slice_loop_filter_across_slices_enabled_flag &&
(slice_or_tiles_up_boundary & 1) && lc->boundary_flags & BOUNDARY_UPPER_SLICE &&
(y0 % (1 << s->sps->log2_ctb_size)) == 0) (y0 % (1 << s->sps->log2_ctb_size)) == 0)
bs = 0; bs = 0;
else if (!s->pps->loop_filter_across_tiles_enabled_flag && else if (!s->pps->loop_filter_across_tiles_enabled_flag &&
(slice_or_tiles_up_boundary & 2) && lc->boundary_flags & BOUNDARY_UPPER_TILE &&
(y0 % (1 << s->sps->log2_ctb_size)) == 0) (y0 % (1 << s->sps->log2_ctb_size)) == 0)
bs = 0; bs = 0;
if (bs) if (bs)
...@@ -675,11 +674,11 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, ...@@ -675,11 +674,11 @@ void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0,
bs = boundary_strength(s, curr, curr_cbf_luma, bs = boundary_strength(s, curr, curr_cbf_luma,
left, left_cbf_luma, left_refPicList, 1); left, left_cbf_luma, left_refPicList, 1);
if (!s->sh.slice_loop_filter_across_slices_enabled_flag && if (!s->sh.slice_loop_filter_across_slices_enabled_flag &&
(slice_or_tiles_left_boundary & 1) && lc->boundary_flags & BOUNDARY_LEFT_SLICE &&
(x0 % (1 << s->sps->log2_ctb_size)) == 0) (x0 % (1 << s->sps->log2_ctb_size)) == 0)
bs = 0; bs = 0;
else if (!s->pps->loop_filter_across_tiles_enabled_flag && else if (!s->pps->loop_filter_across_tiles_enabled_flag &&
(slice_or_tiles_left_boundary & 2) && lc->boundary_flags & BOUNDARY_LEFT_TILE &&
(x0 % (1 << s->sps->log2_ctb_size)) == 0) (x0 % (1 << s->sps->log2_ctb_size)) == 0)
bs = 0; bs = 0;
if (bs) if (bs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment