[FFmpeg-devel] [PATCH] avcodec/hevc_cabac: cabac_init_state, do not use magic number which not listed on the spec

Nuo Mi nuomi2021 at gmail.com
Sun Mar 21 07:06:11 EET 2021


Magic number 124 and ^= are not listed on the spec.
Strictly following the spec will make a reader's life much easier. See (9-6) for details
---
 libavcodec/hevc_cabac.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/libavcodec/hevc_cabac.c b/libavcodec/hevc_cabac.c
index 9b8c8e342d..7ac340f471 100644
--- a/libavcodec/hevc_cabac.c
+++ b/libavcodec/hevc_cabac.c
@@ -496,12 +496,10 @@ static void cabac_init_state(HEVCContext *s)
         int init_value = init_values[init_type][i];
         int m = (init_value >> 4) * 5 - 45;
         int n = ((init_value & 15) << 3) - 16;
-        int pre = 2 * (((m * av_clip(s->sh.slice_qp, 0, 51)) >> 4) + n) - 127;
-
-        pre ^= pre >> 31;
-        if (pre > 124)
-            pre = 124 + (pre & 1);
-        s->HEVClc->cabac_state[i] = pre;
+        int pre = av_clip(((m * av_clip(s->sh.slice_qp, 0, 51)) >> 4) + n, 1, 126);
+        int val_mps = (pre <= 63 ) ? 0 : 1;
+        int state = val_mps ? (pre - 64) : (63 - pre);
+        s->HEVClc->cabac_state[i] = (state << 1) + val_mps;
     }
 
     for (i = 0; i < 4; i++)
-- 
2.25.1



More information about the ffmpeg-devel mailing list