aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/hevc_cabac.c
diff options
context:
space:
mode:
authorMickaƫl Raulet <mraulet@insa-rennes.fr>2013-10-11 22:07:00 +0200
committerMichael Niedermayer <michaelni@gmx.at>2013-10-17 02:41:51 +0200
commitb4948943904a5e496e31c5e7778364fa0b03253c (patch)
tree0448ef136bfae4d01cad54adf2201e213d8e4cb8 /libavcodec/hevc_cabac.c
parent3ed65d98c616d52e2544c8b81aa3997f28bb88f5 (diff)
downloadffmpeg-b4948943904a5e496e31c5e7778364fa0b03253c.tar.gz
hevc: optimize residual coding(cherry picked from commit 70692a44708157b4dfa50e402e446bfa2b27f55e)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/hevc_cabac.c')
-rw-r--r--libavcodec/hevc_cabac.c80
1 files changed, 15 insertions, 65 deletions
diff --git a/libavcodec/hevc_cabac.c b/libavcodec/hevc_cabac.c
index 8468d560b9..ef3a94bc3e 100644
--- a/libavcodec/hevc_cabac.c
+++ b/libavcodec/hevc_cabac.c
@@ -764,24 +764,17 @@ int ff_hevc_last_significant_coeff_suffix_decode(HEVCContext *s,
return value;
}
-int ff_hevc_significant_coeff_group_flag_decode(HEVCContext *s, int c_idx, int x_cg,
- int y_cg, int log2_trafo_size)
+int ff_hevc_significant_coeff_group_flag_decode(HEVCContext *s, int c_idx, int ctx_cg)
{
- int ctx_cg = 0;
int inc;
- if (x_cg < (1 << (log2_trafo_size - 2)) - 1)
- ctx_cg += s->HEVClc.rc.significant_coeff_group_flag[x_cg + 1][y_cg];
- if (y_cg < (1 << (log2_trafo_size - 2)) - 1)
- ctx_cg += s->HEVClc.rc.significant_coeff_group_flag[x_cg][y_cg + 1];
-
inc = FFMIN(ctx_cg, 1) + (c_idx>0 ? 2 : 0);
return GET_CABAC(elem_offset[SIGNIFICANT_COEFF_GROUP_FLAG] + inc);
}
int ff_hevc_significant_coeff_flag_decode(HEVCContext *s, int c_idx, int x_c, int y_c,
- int log2_trafo_size, int scan_idx)
+ int log2_trafo_size, int scan_idx, int prev_sig)
{
static const uint8_t ctx_idx_map[] = {
0, 1, 4, 5, 2, 3, 4, 5, 6, 6, 8, 8, 7, 7, 8, 8
@@ -796,13 +789,6 @@ int ff_hevc_significant_coeff_flag_decode(HEVCContext *s, int c_idx, int x_c, in
} else if (log2_trafo_size == 2) {
sig_ctx = ctx_idx_map[(y_c << 2) + x_c];
} else {
- int prev_sig = 0;
-
- if (x_cg < ((1 << log2_trafo_size) - 1) >> 2)
- prev_sig += s->HEVClc.rc.significant_coeff_group_flag[x_cg + 1][y_cg];
- if (y_cg < ((1 << log2_trafo_size) - 1) >> 2)
- prev_sig += (s->HEVClc.rc.significant_coeff_group_flag[x_cg][y_cg + 1] << 1);
-
switch (prev_sig) {
case 0: {
int x_off = x_c & 3;
@@ -839,82 +825,46 @@ int ff_hevc_significant_coeff_flag_decode(HEVCContext *s, int c_idx, int x_c, in
return GET_CABAC(elem_offset[SIGNIFICANT_COEFF_FLAG] + inc);
}
-int ff_hevc_coeff_abs_level_greater1_flag_decode(HEVCContext *s, int c_idx,
- int i, int n,
- int first_elem,
- int first_subset)
+int ff_hevc_coeff_abs_level_greater1_flag_decode(HEVCContext *s, int c_idx, int inc)
{
- int inc;
-
- if (first_elem) {
- s->HEVClc.ctx_set = (i > 0 && c_idx == 0) ? 2 : 0;
-
- if (!first_subset && s->HEVClc.greater1_ctx == 0)
- s->HEVClc.ctx_set++;
- s->HEVClc.greater1_ctx = 1;
- }
-
- inc = (s->HEVClc.ctx_set << 2) + s->HEVClc.greater1_ctx;
if (c_idx > 0)
inc += 16;
- s->HEVClc.last_coeff_abs_level_greater1_flag =
- GET_CABAC(elem_offset[COEFF_ABS_LEVEL_GREATER1_FLAG] + inc);
-
- if (s->HEVClc.last_coeff_abs_level_greater1_flag) {
- s->HEVClc.greater1_ctx = 0;
- } else if (s->HEVClc.greater1_ctx > 0 && s->HEVClc.greater1_ctx < 3) {
- s->HEVClc.greater1_ctx++;
- }
-
- return s->HEVClc.last_coeff_abs_level_greater1_flag;
+ return GET_CABAC(elem_offset[COEFF_ABS_LEVEL_GREATER1_FLAG] + inc);
}
-int ff_hevc_coeff_abs_level_greater2_flag_decode(HEVCContext *s, int c_idx,
- int i, int n)
+int ff_hevc_coeff_abs_level_greater2_flag_decode(HEVCContext *s, int c_idx, int inc)
{
- int inc;
-
- inc = s->HEVClc.ctx_set;
if (c_idx > 0)
inc += 4;
return GET_CABAC(elem_offset[COEFF_ABS_LEVEL_GREATER2_FLAG] + inc);
}
-int ff_hevc_coeff_abs_level_remaining(HEVCContext *s, int first_elem, int base_level)
+int ff_hevc_coeff_abs_level_remaining(HEVCContext *s, int base_level, int rc_rice_param)
{
- int i;
- HEVCLocalContext *lc = &s->HEVClc;
int prefix = 0;
int suffix = 0;
-
- if (first_elem) {
- lc->c_rice_param = 0;
- lc->last_coeff_abs_level_remaining = 0;
- }
+ int last_coeff_abs_level_remaining;
+ int i;
while (prefix < CABAC_MAX_BIN && get_cabac_bypass(&s->HEVClc.cc))
prefix++;
if (prefix == CABAC_MAX_BIN)
av_log(s->avctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", prefix);
if (prefix < 3) {
- for (i = 0; i < lc->c_rice_param; i++)
+ for (i = 0; i < rc_rice_param; i++)
suffix = (suffix << 1) | get_cabac_bypass(&s->HEVClc.cc);
- lc->last_coeff_abs_level_remaining = (prefix << lc->c_rice_param) + suffix;
+ last_coeff_abs_level_remaining = (prefix << rc_rice_param) + suffix;
} else {
- for (i = 0; i < prefix - 3 + lc->c_rice_param; i++)
+ int prefix_minus3 = prefix - 3;
+ for (i = 0; i < prefix_minus3 + rc_rice_param; i++)
suffix = (suffix << 1) | get_cabac_bypass(&s->HEVClc.cc);
- lc->last_coeff_abs_level_remaining = (((1 << (prefix - 3)) + 3 - 1)
- << lc->c_rice_param) + suffix;
+ last_coeff_abs_level_remaining = (((1 << prefix_minus3) + 3 - 1)
+ << rc_rice_param) + suffix;
}
-
- lc->c_rice_param = FFMIN(lc->c_rice_param +
- ((base_level + lc->last_coeff_abs_level_remaining) >
- (3 * (1 << lc->c_rice_param))), 4);
-
- return lc->last_coeff_abs_level_remaining;
+ return last_coeff_abs_level_remaining;
}
int ff_hevc_coeff_sign_flag(HEVCContext *s, uint8_t nb)