[FFmpeg-cvslog] avcodec/vp56: Move VP8/9-only rac functions to a header of their own
Andreas Rheinhardt
git at videolan.org
Thu Jul 28 05:01:06 EEST 2022
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sat Jul 23 00:04:29 2022 +0200| [80ad06ab1b33bfea25be618a64742d90468b36e6] | committer: Andreas Rheinhardt
avcodec/vp56: Move VP8/9-only rac functions to a header of their own
Also rename these functions from vp8_rac_* to vp89_rac_*.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=80ad06ab1b33bfea25be618a64742d90468b36e6
---
libavcodec/vp56.h | 31 ----------
libavcodec/vp8.c | 166 +++++++++++++++++++++++++-------------------------
libavcodec/vp89_rac.h | 66 ++++++++++++++++++++
libavcodec/vp9.c | 49 +++++++--------
libavcodec/vp9block.c | 84 ++++++++++++-------------
libavcodec/vp9mvs.c | 21 ++++---
6 files changed, 229 insertions(+), 188 deletions(-)
diff --git a/libavcodec/vp56.h b/libavcodec/vp56.h
index 08172e1987..174f126309 100644
--- a/libavcodec/vp56.h
+++ b/libavcodec/vp56.h
@@ -322,12 +322,6 @@ static av_always_inline int vp56_rac_get(VP56RangeCoder *c)
return bit;
}
-// rounding is different than vp56_rac_get, is vp56_rac_get wrong?
-static av_always_inline int vp8_rac_get(VP56RangeCoder *c)
-{
- return vp56_rac_get_prob(c, 128);
-}
-
static int vp56_rac_gets(VP56RangeCoder *c, int bits)
{
int value = 0;
@@ -339,17 +333,6 @@ static int vp56_rac_gets(VP56RangeCoder *c, int bits)
return value;
}
-static av_unused int vp8_rac_get_uint(VP56RangeCoder *c, int bits)
-{
- int value = 0;
-
- while (bits--) {
- value = (value << 1) | vp8_rac_get(c);
- }
-
- return value;
-}
-
// P(7)
static av_unused int vp56_rac_gets_nn(VP56RangeCoder *c, int bits)
{
@@ -371,18 +354,4 @@ int vp56_rac_get_tree(VP56RangeCoder *c,
return -tree->val;
}
-// how probabilities are associated with decisions is different I think
-// well, the new scheme fits in the old but this way has one fewer branches per decision
-static av_always_inline int vp8_rac_get_tree(VP56RangeCoder *c, const int8_t (*tree)[2],
- const uint8_t *probs)
-{
- int i = 0;
-
- do {
- i = tree[i][vp56_rac_get_prob(c, probs[i])];
- } while (i > 0);
-
- return -i;
-}
-
#endif /* AVCODEC_VP56_H */
diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index 9e7616990f..ade7769943 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -38,6 +38,7 @@
#include "thread.h"
#include "threadframe.h"
#include "vp8.h"
+#include "vp89_rac.h"
#include "vp8data.h"
#if ARCH_ARM
@@ -57,12 +58,12 @@ static int vp8_rac_get_sint(VP56RangeCoder *c, int bits)
{
int v;
- if (!vp8_rac_get(c))
+ if (!vp89_rac_get(c))
return 0;
- v = vp8_rac_get_uint(c, bits);
+ v = vp89_rac_get_uint(c, bits);
- if (vp8_rac_get(c))
+ if (vp89_rac_get(c))
v = -v;
return v;
@@ -70,7 +71,7 @@ static int vp8_rac_get_sint(VP56RangeCoder *c, int bits)
static int vp8_rac_get_nn(VP56RangeCoder *c)
{
- int v = vp8_rac_get_uint(c, 7) << 1;
+ int v = vp89_rac_get_uint(c, 7) << 1;
return v + !v;
}
@@ -303,11 +304,11 @@ static void parse_segment_info(VP8Context *s)
VP56RangeCoder *c = &s->c;
int i;
- s->segmentation.update_map = vp8_rac_get(c);
- s->segmentation.update_feature_data = vp8_rac_get(c);
+ s->segmentation.update_map = vp89_rac_get(c);
+ s->segmentation.update_feature_data = vp89_rac_get(c);
if (s->segmentation.update_feature_data) {
- s->segmentation.absolute_vals = vp8_rac_get(c);
+ s->segmentation.absolute_vals = vp89_rac_get(c);
for (i = 0; i < 4; i++)
s->segmentation.base_quant[i] = vp8_rac_get_sint(c, 7);
@@ -317,7 +318,7 @@ static void parse_segment_info(VP8Context *s)
}
if (s->segmentation.update_map)
for (i = 0; i < 3; i++)
- s->prob->segmentid[i] = vp8_rac_get(c) ? vp8_rac_get_uint(c, 8) : 255;
+ s->prob->segmentid[i] = vp89_rac_get(c) ? vp89_rac_get_uint(c, 8) : 255;
}
static void update_lf_deltas(VP8Context *s)
@@ -326,19 +327,19 @@ static void update_lf_deltas(VP8Context *s)
int i;
for (i = 0; i < 4; i++) {
- if (vp8_rac_get(c)) {
- s->lf_delta.ref[i] = vp8_rac_get_uint(c, 6);
+ if (vp89_rac_get(c)) {
+ s->lf_delta.ref[i] = vp89_rac_get_uint(c, 6);
- if (vp8_rac_get(c))
+ if (vp89_rac_get(c))
s->lf_delta.ref[i] = -s->lf_delta.ref[i];
}
}
for (i = MODE_I4x4; i <= VP8_MVMODE_SPLIT; i++) {
- if (vp8_rac_get(c)) {
- s->lf_delta.mode[i] = vp8_rac_get_uint(c, 6);
+ if (vp89_rac_get(c)) {
+ s->lf_delta.mode[i] = vp89_rac_get_uint(c, 6);
- if (vp8_rac_get(c))
+ if (vp89_rac_get(c))
s->lf_delta.mode[i] = -s->lf_delta.mode[i];
}
}
@@ -350,7 +351,7 @@ static int setup_partitions(VP8Context *s, const uint8_t *buf, int buf_size)
int i;
int ret;
- s->num_coeff_partitions = 1 << vp8_rac_get_uint(&s->c, 2);
+ s->num_coeff_partitions = 1 << vp89_rac_get_uint(&s->c, 2);
buf += 3 * (s->num_coeff_partitions - 1);
buf_size -= 3 * (s->num_coeff_partitions - 1);
@@ -380,12 +381,12 @@ static void vp7_get_quants(VP8Context *s)
{
VP56RangeCoder *c = &s->c;
- int yac_qi = vp8_rac_get_uint(c, 7);
- int ydc_qi = vp8_rac_get(c) ? vp8_rac_get_uint(c, 7) : yac_qi;
- int y2dc_qi = vp8_rac_get(c) ? vp8_rac_get_uint(c, 7) : yac_qi;
- int y2ac_qi = vp8_rac_get(c) ? vp8_rac_get_uint(c, 7) : yac_qi;
- int uvdc_qi = vp8_rac_get(c) ? vp8_rac_get_uint(c, 7) : yac_qi;
- int uvac_qi = vp8_rac_get(c) ? vp8_rac_get_uint(c, 7) : yac_qi;
+ int yac_qi = vp89_rac_get_uint(c, 7);
+ int ydc_qi = vp89_rac_get(c) ? vp89_rac_get_uint(c, 7) : yac_qi;
+ int y2dc_qi = vp89_rac_get(c) ? vp89_rac_get_uint(c, 7) : yac_qi;
+ int y2ac_qi = vp89_rac_get(c) ? vp89_rac_get_uint(c, 7) : yac_qi;
+ int uvdc_qi = vp89_rac_get(c) ? vp89_rac_get_uint(c, 7) : yac_qi;
+ int uvac_qi = vp89_rac_get(c) ? vp89_rac_get_uint(c, 7) : yac_qi;
s->qmat[0].luma_qmul[0] = vp7_ydc_qlookup[ydc_qi];
s->qmat[0].luma_qmul[1] = vp7_yac_qlookup[yac_qi];
@@ -400,7 +401,7 @@ static void vp8_get_quants(VP8Context *s)
VP56RangeCoder *c = &s->c;
int i, base_qi;
- s->quant.yac_qi = vp8_rac_get_uint(c, 7);
+ s->quant.yac_qi = vp89_rac_get_uint(c, 7);
s->quant.ydc_delta = vp8_rac_get_sint(c, 4);
s->quant.y2dc_delta = vp8_rac_get_sint(c, 4);
s->quant.y2ac_delta = vp8_rac_get_sint(c, 4);
@@ -448,7 +449,7 @@ static VP56Frame ref_to_update(VP8Context *s, int update, VP56Frame ref)
if (update)
return VP56_FRAME_CURRENT;
- switch (vp8_rac_get_uint(c, 2)) {
+ switch (vp89_rac_get_uint(c, 2)) {
case 1:
return VP56_FRAME_PREVIOUS;
case 2:
@@ -476,7 +477,7 @@ static void vp78_update_probability_tables(VP8Context *s)
for (k = 0; k < 3; k++)
for (l = 0; l < NUM_DCT_TOKENS-1; l++)
if (vp56_rac_get_prob_branchy(c, vp8_token_update_probs[i][j][k][l])) {
- int prob = vp8_rac_get_uint(c, 8);
+ int prob = vp89_rac_get_uint(c, 8);
for (m = 0; vp8_coeff_band_indexes[j][m] >= 0; m++)
s->prob->token[i][vp8_coeff_band_indexes[j][m]][k][l] = prob;
}
@@ -491,12 +492,12 @@ static void vp78_update_pred16x16_pred8x8_mvc_probabilities(VP8Context *s,
VP56RangeCoder *c = &s->c;
int i, j;
- if (vp8_rac_get(c))
+ if (vp89_rac_get(c))
for (i = 0; i < 4; i++)
- s->prob->pred16x16[i] = vp8_rac_get_uint(c, 8);
- if (vp8_rac_get(c))
+ s->prob->pred16x16[i] = vp89_rac_get_uint(c, 8);
+ if (vp89_rac_get(c))
for (i = 0; i < 3; i++)
- s->prob->pred8x8c[i] = vp8_rac_get_uint(c, 8);
+ s->prob->pred8x8c[i] = vp89_rac_get_uint(c, 8);
// 17.2 MV probability update
for (i = 0; i < 2; i++)
@@ -509,8 +510,8 @@ static void update_refs(VP8Context *s)
{
VP56RangeCoder *c = &s->c;
- int update_golden = vp8_rac_get(c);
- int update_altref = vp8_rac_get(c);
+ int update_golden = vp89_rac_get(c);
+ int update_altref = vp89_rac_get(c);
s->update_golden = ref_to_update(s, update_golden, VP56_FRAME_GOLDEN);
s->update_altref = ref_to_update(s, update_altref, VP56_FRAME_GOLDEN2);
@@ -621,10 +622,10 @@ static int vp7_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_si
/* A. Dimension information (keyframes only) */
if (s->keyframe) {
- width = vp8_rac_get_uint(c, 12);
- height = vp8_rac_get_uint(c, 12);
- hscale = vp8_rac_get_uint(c, 2);
- vscale = vp8_rac_get_uint(c, 2);
+ width = vp89_rac_get_uint(c, 12);
+ height = vp89_rac_get_uint(c, 12);
+ hscale = vp89_rac_get_uint(c, 2);
+ vscale = vp89_rac_get_uint(c, 2);
if (hscale || vscale)
avpriv_request_sample(s->avctx, "Upscaling");
@@ -647,18 +648,18 @@ static int vp7_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_si
/* B. Decoding information for all four macroblock-level features */
for (i = 0; i < 4; i++) {
- s->feature_enabled[i] = vp8_rac_get(c);
+ s->feature_enabled[i] = vp89_rac_get(c);
if (s->feature_enabled[i]) {
- s->feature_present_prob[i] = vp8_rac_get_uint(c, 8);
+ s->feature_present_prob[i] = vp89_rac_get_uint(c, 8);
for (j = 0; j < 3; j++)
s->feature_index_prob[i][j] =
- vp8_rac_get(c) ? vp8_rac_get_uint(c, 8) : 255;
+ vp89_rac_get(c) ? vp89_rac_get_uint(c, 8) : 255;
if (vp7_feature_value_size[s->profile][i])
for (j = 0; j < 4; j++)
s->feature_value[i][j] =
- vp8_rac_get(c) ? vp8_rac_get_uint(c, vp7_feature_value_size[s->profile][i]) : 0;
+ vp89_rac_get(c) ? vp89_rac_get_uint(c, vp7_feature_value_size[s->profile][i]) : 0;
}
}
@@ -683,7 +684,7 @@ static int vp7_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_si
/* D. Golden frame update flag (a Flag) for interframes only */
if (!s->keyframe) {
- s->update_golden = vp8_rac_get(c) ? VP56_FRAME_CURRENT : VP56_FRAME_NONE;
+ s->update_golden = vp89_rac_get(c) ? VP56_FRAME_CURRENT : VP56_FRAME_NONE;
s->sign_bias[VP56_FRAME_GOLDEN] = 0;
}
@@ -692,36 +693,36 @@ static int vp7_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_si
s->fade_present = 1;
if (s->profile > 0) {
- s->update_probabilities = vp8_rac_get(c);
+ s->update_probabilities = vp89_rac_get(c);
if (!s->update_probabilities)
s->prob[1] = s->prob[0];
if (!s->keyframe)
- s->fade_present = vp8_rac_get(c);
+ s->fade_present = vp89_rac_get(c);
}
if (vpX_rac_is_end(c))
return AVERROR_INVALIDDATA;
/* E. Fading information for previous frame */
- if (s->fade_present && vp8_rac_get(c)) {
- alpha = (int8_t) vp8_rac_get_uint(c, 8);
- beta = (int8_t) vp8_rac_get_uint(c, 8);
+ if (s->fade_present && vp89_rac_get(c)) {
+ alpha = (int8_t) vp89_rac_get_uint(c, 8);
+ beta = (int8_t) vp89_rac_get_uint(c, 8);
}
/* F. Loop filter type */
if (!s->profile)
- s->filter.simple = vp8_rac_get(c);
+ s->filter.simple = vp89_rac_get(c);
/* G. DCT coefficient ordering specification */
- if (vp8_rac_get(c))
+ if (vp89_rac_get(c))
for (i = 1; i < 16; i++)
- s->prob[0].scan[i] = ff_zigzag_scan[vp8_rac_get_uint(c, 4)];
+ s->prob[0].scan[i] = ff_zigzag_scan[vp89_rac_get_uint(c, 4)];
/* H. Loop filter levels */
if (s->profile > 0)
- s->filter.simple = vp8_rac_get(c);
- s->filter.level = vp8_rac_get_uint(c, 6);
- s->filter.sharpness = vp8_rac_get_uint(c, 3);
+ s->filter.simple = vp89_rac_get(c);
+ s->filter.level = vp89_rac_get_uint(c, 6);
+ s->filter.sharpness = vp89_rac_get_uint(c, 3);
/* I. DCT coefficient probability update; 13.3 Token Probability Updates */
vp78_update_probability_tables(s);
@@ -730,8 +731,8 @@ static int vp7_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_si
/* J. The remaining frame header data occurs ONLY FOR INTERFRAMES */
if (!s->keyframe) {
- s->prob->intra = vp8_rac_get_uint(c, 8);
- s->prob->last = vp8_rac_get_uint(c, 8);
+ s->prob->intra = vp89_rac_get_uint(c, 8);
+ s->prob->last = vp89_rac_get_uint(c, 8);
vp78_update_pred16x16_pred8x8_mvc_probabilities(s, VP7_MVC_SIZE);
}
@@ -815,23 +816,23 @@ static int vp8_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_si
buf_size -= header_size;
if (s->keyframe) {
- s->colorspace = vp8_rac_get(c);
+ s->colorspace = vp89_rac_get(c);
if (s->colorspace)
av_log(s->avctx, AV_LOG_WARNING, "Unspecified colorspace\n");
- s->fullrange = vp8_rac_get(c);
+ s->fullrange = vp89_rac_get(c);
}
- if ((s->segmentation.enabled = vp8_rac_get(c)))
+ if ((s->segmentation.enabled = vp89_rac_get(c)))
parse_segment_info(s);
else
s->segmentation.update_map = 0; // FIXME: move this to some init function?
- s->filter.simple = vp8_rac_get(c);
- s->filter.level = vp8_rac_get_uint(c, 6);
- s->filter.sharpness = vp8_rac_get_uint(c, 3);
+ s->filter.simple = vp89_rac_get(c);
+ s->filter.level = vp89_rac_get_uint(c, 6);
+ s->filter.sharpness = vp89_rac_get_uint(c, 3);
- if ((s->lf_delta.enabled = vp8_rac_get(c))) {
- s->lf_delta.update = vp8_rac_get(c);
+ if ((s->lf_delta.enabled = vp89_rac_get(c))) {
+ s->lf_delta.update = vp89_rac_get(c);
if (s->lf_delta.update)
update_lf_deltas(s);
}
@@ -851,26 +852,26 @@ static int vp8_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_si
if (!s->keyframe) {
update_refs(s);
- s->sign_bias[VP56_FRAME_GOLDEN] = vp8_rac_get(c);
- s->sign_bias[VP56_FRAME_GOLDEN2 /* altref */] = vp8_rac_get(c);
+ s->sign_bias[VP56_FRAME_GOLDEN] = vp89_rac_get(c);
+ s->sign_bias[VP56_FRAME_GOLDEN2 /* altref */] = vp89_rac_get(c);
}
// if we aren't saving this frame's probabilities for future frames,
// make a copy of the current probabilities
- if (!(s->update_probabilities = vp8_rac_get(c)))
+ if (!(s->update_probabilities = vp89_rac_get(c)))
s->prob[1] = s->prob[0];
- s->update_last = s->keyframe || vp8_rac_get(c);
+ s->update_last = s->keyframe || vp89_rac_get(c);
vp78_update_probability_tables(s);
- if ((s->mbskip_enabled = vp8_rac_get(c)))
- s->prob->mbskip = vp8_rac_get_uint(c, 8);
+ if ((s->mbskip_enabled = vp89_rac_get(c)))
+ s->prob->mbskip = vp89_rac_get_uint(c, 8);
if (!s->keyframe) {
- s->prob->intra = vp8_rac_get_uint(c, 8);
- s->prob->last = vp8_rac_get_uint(c, 8);
- s->prob->golden = vp8_rac_get_uint(c, 8);
+ s->prob->intra = vp89_rac_get_uint(c, 8);
+ s->prob->last = vp89_rac_get_uint(c, 8);
+ s->prob->golden = vp89_rac_get_uint(c, 8);
vp78_update_pred16x16_pred8x8_mvc_probabilities(s, VP8_MVC_SIZE);
}
@@ -1265,7 +1266,7 @@ void decode_intra4x4_modes(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb,
for (x = 0; x < 4; x++) {
const uint8_t *ctx;
ctx = vp8_pred4x4_prob_intra[top[x]][left[y]];
- *intra4x4 = vp8_rac_get_tree(c, vp8_pred4x4_tree, ctx);
+ *intra4x4 = vp89_rac_get_tree(c, vp8_pred4x4_tree, ctx);
left[y] = top[x] = *intra4x4;
intra4x4++;
}
@@ -1273,8 +1274,8 @@ void decode_intra4x4_modes(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb,
} else {
int i;
for (i = 0; i < 16; i++)
- intra4x4[i] = vp8_rac_get_tree(c, vp8_pred4x4_tree,
- vp8_pred4x4_prob_inter);
+ intra4x4[i] = vp89_rac_get_tree(c, vp8_pred4x4_tree,
+ vp8_pred4x4_prob_inter);
}
}
@@ -1294,8 +1295,8 @@ void decode_mb_mode(VP8Context *s, VP8mvbounds *mv_bounds,
for (i = 0; i < 4; i++) {
if (s->feature_enabled[i]) {
if (vp56_rac_get_prob_branchy(c, s->feature_present_prob[i])) {
- int index = vp8_rac_get_tree(c, vp7_feature_index_tree,
- s->feature_index_prob[i]);
+ int index = vp89_rac_get_tree(c, vp7_feature_index_tree,
+ s->feature_index_prob[i]);
av_log(s->avctx, AV_LOG_WARNING,
"Feature %s present in macroblock (value 0x%x)\n",
vp7_feature_name[i], s->feature_value[i][index]);
@@ -1312,8 +1313,8 @@ void decode_mb_mode(VP8Context *s, VP8mvbounds *mv_bounds,
mb->skip = s->mbskip_enabled ? vp56_rac_get_prob(c, s->prob->mbskip) : 0;
if (s->keyframe) {
- mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_intra,
- vp8_pred16x16_prob_intra);
+ mb->mode = vp89_rac_get_tree(c, vp8_pred16x16_tree_intra,
+ vp8_pred16x16_prob_intra);
if (mb->mode == MODE_I4x4) {
decode_intra4x4_modes(s, c, mb, mb_x, 1, layout);
@@ -1327,8 +1328,8 @@ void decode_mb_mode(VP8Context *s, VP8mvbounds *mv_bounds,
AV_WN32A(s->intra4x4_pred_mode_left, modes);
}
- mb->chroma_pred_mode = vp8_rac_get_tree(c, vp8_pred8x8c_tree,
- vp8_pred8x8c_prob_intra);
+ mb->chroma_pred_mode = vp89_rac_get_tree(c, vp8_pred8x8c_tree,
+ vp8_pred8x8c_prob_intra);
mb->ref_frame = VP56_FRAME_CURRENT;
} else if (vp56_rac_get_prob_branchy(c, s->prob->intra)) {
// inter MB, 16.2
@@ -1347,13 +1348,14 @@ void decode_mb_mode(VP8Context *s, VP8mvbounds *mv_bounds,
vp8_decode_mvs(s, mv_bounds, mb, mb_x, mb_y, layout);
} else {
// intra MB, 16.1
- mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_inter, s->prob->pred16x16);
+ mb->mode = vp89_rac_get_tree(c, vp8_pred16x16_tree_inter,
+ s->prob->pred16x16);
if (mb->mode == MODE_I4x4)
decode_intra4x4_modes(s, c, mb, mb_x, 0, layout);
- mb->chroma_pred_mode = vp8_rac_get_tree(c, vp8_pred8x8c_tree,
- s->prob->pred8x8c);
+ mb->chroma_pred_mode = vp89_rac_get_tree(c, vp8_pred8x8c_tree,
+ s->prob->pred8x8c);
mb->ref_frame = VP56_FRAME_CURRENT;
mb->partitioning = VP8_SPLITMVMODE_NONE;
AV_ZERO32(&mb->bmv[0]);
@@ -1423,7 +1425,7 @@ skip_eob:
}
token_prob = probs[i + 1][2];
}
- block[scan[i]] = (vp8_rac_get(&c) ? -coeff : coeff) * qmul[!!i];
+ block[scan[i]] = (vp89_rac_get(&c) ? -coeff : coeff) * qmul[!!i];
} while (++i < 16);
*r = c;
diff --git a/libavcodec/vp89_rac.h b/libavcodec/vp89_rac.h
new file mode 100644
index 0000000000..382c8ee64d
--- /dev/null
+++ b/libavcodec/vp89_rac.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2006 Aurelien Jacobs <aurel at gnuage.org>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Range decoder functions common to VP8 and VP9
+ */
+
+#ifndef AVCODEC_VP89_RAC_H
+#define AVCODEC_VP89_RAC_H
+
+#include <stdint.h>
+
+#include "libavutil/attributes.h"
+
+#include "vp56.h"
+
+// rounding is different than vp56_rac_get, is vp56_rac_get wrong?
+static av_always_inline int vp89_rac_get(VP56RangeCoder *c)
+{
+ return vp56_rac_get_prob(c, 128);
+}
+
+static av_unused int vp89_rac_get_uint(VP56RangeCoder *c, int bits)
+{
+ int value = 0;
+
+ while (bits--) {
+ value = (value << 1) | vp89_rac_get(c);
+ }
+
+ return value;
+}
+
+// how probabilities are associated with decisions is different I think
+// well, the new scheme fits in the old but this way has one fewer branches per decision
+static av_always_inline int vp89_rac_get_tree(VP56RangeCoder *c, const int8_t (*tree)[2],
+ const uint8_t *probs)
+{
+ int i = 0;
+
+ do {
+ i = tree[i][vp56_rac_get_prob(c, probs[i])];
+ } while (i > 0);
+
+ return -i;
+}
+
+#endif /* AVCODEC_VP89_RAC_H */
diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 12ec87992c..57ad8623a8 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -35,6 +35,7 @@
#include "videodsp.h"
#include "vp56.h"
+#include "vp89_rac.h"
#include "vp9.h"
#include "vp9data.h"
#include "vp9dec.h"
@@ -419,16 +420,16 @@ static int update_prob(VP56RangeCoder *c, int p)
* updates vs. the 'fine, exact' updates further down the range, which
* adds one extra dimension to this differential update model. */
- if (!vp8_rac_get(c)) {
- d = vp8_rac_get_uint(c, 4) + 0;
- } else if (!vp8_rac_get(c)) {
- d = vp8_rac_get_uint(c, 4) + 16;
- } else if (!vp8_rac_get(c)) {
- d = vp8_rac_get_uint(c, 5) + 32;
+ if (!vp89_rac_get(c)) {
+ d = vp89_rac_get_uint(c, 4) + 0;
+ } else if (!vp89_rac_get(c)) {
+ d = vp89_rac_get_uint(c, 4) + 16;
+ } else if (!vp89_rac_get(c)) {
+ d = vp89_rac_get_uint(c, 5) + 32;
} else {
- d = vp8_rac_get_uint(c, 7);
+ d = vp89_rac_get_uint(c, 7);
if (d >= 65)
- d = (d << 1) - 65 + vp8_rac_get(c);
+ d = (d << 1) - 65 + vp89_rac_get(c);
d += 64;
av_assert2(d < FF_ARRAY_ELEMS(inv_map_table));
}
@@ -905,9 +906,9 @@ static int decode_frame_header(AVCodecContext *avctx,
if (s->s.h.lossless) {
s->s.h.txfmmode = TX_4X4;
} else {
- s->s.h.txfmmode = vp8_rac_get_uint(&s->c, 2);
+ s->s.h.txfmmode = vp89_rac_get_uint(&s->c, 2);
if (s->s.h.txfmmode == 3)
- s->s.h.txfmmode += vp8_rac_get(&s->c);
+ s->s.h.txfmmode += vp89_rac_get(&s->c);
if (s->s.h.txfmmode == TX_SWITCHABLE) {
for (i = 0; i < 2; i++)
@@ -929,7 +930,7 @@ static int decode_frame_header(AVCodecContext *avctx,
// coef updates
for (i = 0; i < 4; i++) {
uint8_t (*ref)[2][6][6][3] = s->prob_ctx[c].coef[i];
- if (vp8_rac_get(&s->c)) {
+ if (vp89_rac_get(&s->c)) {
for (j = 0; j < 2; j++)
for (k = 0; k < 2; k++)
for (l = 0; l < 6; l++)
@@ -986,9 +987,9 @@ static int decode_frame_header(AVCodecContext *avctx,
s->prob.p.intra[i] = update_prob(&s->c, s->prob.p.intra[i]);
if (s->s.h.allowcompinter) {
- s->s.h.comppredmode = vp8_rac_get(&s->c);
+ s->s.h.comppredmode = vp89_rac_get(&s->c);
if (s->s.h.comppredmode)
- s->s.h.comppredmode += vp8_rac_get(&s->c);
+ s->s.h.comppredmode += vp89_rac_get(&s->c);
if (s->s.h.comppredmode == PRED_SWITCHABLE)
for (i = 0; i < 5; i++)
if (vp56_rac_get_prob_branchy(&s->c, 252))
@@ -1033,26 +1034,26 @@ static int decode_frame_header(AVCodecContext *avctx,
// mv fields don't use the update_prob subexp model for some reason
for (i = 0; i < 3; i++)
if (vp56_rac_get_prob_branchy(&s->c, 252))
- s->prob.p.mv_joint[i] = (vp8_rac_get_uint(&s->c, 7) << 1) | 1;
+ s->prob.p.mv_joint[i] = (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
for (i = 0; i < 2; i++) {
if (vp56_rac_get_prob_branchy(&s->c, 252))
s->prob.p.mv_comp[i].sign =
- (vp8_rac_get_uint(&s->c, 7) << 1) | 1;
+ (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
for (j = 0; j < 10; j++)
if (vp56_rac_get_prob_branchy(&s->c, 252))
s->prob.p.mv_comp[i].classes[j] =
- (vp8_rac_get_uint(&s->c, 7) << 1) | 1;
+ (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
if (vp56_rac_get_prob_branchy(&s->c, 252))
s->prob.p.mv_comp[i].class0 =
- (vp8_rac_get_uint(&s->c, 7) << 1) | 1;
+ (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
for (j = 0; j < 10; j++)
if (vp56_rac_get_prob_branchy(&s->c, 252))
s->prob.p.mv_comp[i].bits[j] =
- (vp8_rac_get_uint(&s->c, 7) << 1) | 1;
+ (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
}
for (i = 0; i < 2; i++) {
@@ -1060,23 +1061,23 @@ static int decode_frame_header(AVCodecContext *avctx,
for (k = 0; k < 3; k++)
if (vp56_rac_get_prob_branchy(&s->c, 252))
s->prob.p.mv_comp[i].class0_fp[j][k] =
- (vp8_rac_get_uint(&s->c, 7) << 1) | 1;
+ (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
for (j = 0; j < 3; j++)
if (vp56_rac_get_prob_branchy(&s->c, 252))
s->prob.p.mv_comp[i].fp[j] =
- (vp8_rac_get_uint(&s->c, 7) << 1) | 1;
+ (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
}
if (s->s.h.highprecisionmvs) {
for (i = 0; i < 2; i++) {
if (vp56_rac_get_prob_branchy(&s->c, 252))
s->prob.p.mv_comp[i].class0_hp =
- (vp8_rac_get_uint(&s->c, 7) << 1) | 1;
+ (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
if (vp56_rac_get_prob_branchy(&s->c, 252))
s->prob.p.mv_comp[i].hp =
- (vp8_rac_get_uint(&s->c, 7) << 1) | 1;
+ (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
}
}
}
@@ -1099,11 +1100,11 @@ static void decode_sb(VP9TileData *td, int row, int col, VP9Filter *lflvl,
int bytesperpixel = s->bytesperpixel;
if (bl == BL_8X8) {
- bp = vp8_rac_get_tree(td->c, ff_vp9_partition_tree, p);
+ bp = vp89_rac_get_tree(td->c, ff_vp9_partition_tree, p);
ff_vp9_decode_block(td, row, col, lflvl, yoff, uvoff, bl, bp);
} else if (col + hbs < s->cols) { // FIXME why not <=?
if (row + hbs < s->rows) { // FIXME why not <=?
- bp = vp8_rac_get_tree(td->c, ff_vp9_partition_tree, p);
+ bp = vp89_rac_get_tree(td->c, ff_vp9_partition_tree, p);
switch (bp) {
case PARTITION_NONE:
ff_vp9_decode_block(td, row, col, lflvl, yoff, uvoff, bl, bp);
diff --git a/libavcodec/vp9block.c b/libavcodec/vp9block.c
index 5fdda63545..f5088e3b59 100644
--- a/libavcodec/vp9block.c
+++ b/libavcodec/vp9block.c
@@ -25,6 +25,7 @@
#include "threadframe.h"
#include "vp56.h"
+#include "vp89_rac.h"
#include "vp9.h"
#include "vp9data.h"
#include "vp9dec.h"
@@ -100,7 +101,8 @@ static void decode_mode(VP9TileData *td)
b->seg_id = 0;
} else if (s->s.h.keyframe || s->s.h.intraonly) {
b->seg_id = !s->s.h.segmentation.update_map ? 0 :
- vp8_rac_get_tree(td->c, ff_vp9_segmentation_tree, s->s.h.segmentation.prob);
+ vp89_rac_get_tree(td->c, ff_vp9_segmentation_tree,
+ s->s.h.segmentation.prob);
} else if (!s->s.h.segmentation.update_map ||
(s->s.h.segmentation.temporal &&
vp56_rac_get_prob_branchy(td->c,
@@ -126,8 +128,8 @@ static void decode_mode(VP9TileData *td)
memset(&s->above_segpred_ctx[col], 1, w4);
memset(&td->left_segpred_ctx[row7], 1, h4);
} else {
- b->seg_id = vp8_rac_get_tree(td->c, ff_vp9_segmentation_tree,
- s->s.h.segmentation.prob);
+ b->seg_id = vp89_rac_get_tree(td->c, ff_vp9_segmentation_tree,
+ s->s.h.segmentation.prob);
memset(&s->above_segpred_ctx[col], 0, w4);
memset(&td->left_segpred_ctx[row7], 0, h4);
@@ -221,11 +223,11 @@ static void decode_mode(VP9TileData *td)
// necessary, they're just there to make the code slightly
// simpler for now
b->mode[0] =
- a[0] = vp8_rac_get_tree(td->c, ff_vp9_intramode_tree,
- ff_vp9_default_kf_ymode_probs[a[0]][l[0]]);
+ a[0] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
+ ff_vp9_default_kf_ymode_probs[a[0]][l[0]]);
if (b->bs != BS_8x4) {
- b->mode[1] = vp8_rac_get_tree(td->c, ff_vp9_intramode_tree,
- ff_vp9_default_kf_ymode_probs[a[1]][b->mode[0]]);
+ b->mode[1] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
+ ff_vp9_default_kf_ymode_probs[a[1]][b->mode[0]]);
l[0] =
a[1] = b->mode[1];
} else {
@@ -235,11 +237,11 @@ static void decode_mode(VP9TileData *td)
}
if (b->bs != BS_4x8) {
b->mode[2] =
- a[0] = vp8_rac_get_tree(td->c, ff_vp9_intramode_tree,
- ff_vp9_default_kf_ymode_probs[a[0]][l[1]]);
+ a[0] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
+ ff_vp9_default_kf_ymode_probs[a[0]][l[1]]);
if (b->bs != BS_8x4) {
- b->mode[3] = vp8_rac_get_tree(td->c, ff_vp9_intramode_tree,
- ff_vp9_default_kf_ymode_probs[a[1]][b->mode[2]]);
+ b->mode[3] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
+ ff_vp9_default_kf_ymode_probs[a[1]][b->mode[2]]);
l[1] =
a[1] = b->mode[3];
} else {
@@ -254,8 +256,8 @@ static void decode_mode(VP9TileData *td)
b->mode[3] = b->mode[1];
}
} else {
- b->mode[0] = vp8_rac_get_tree(td->c, ff_vp9_intramode_tree,
- ff_vp9_default_kf_ymode_probs[*a][*l]);
+ b->mode[0] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
+ ff_vp9_default_kf_ymode_probs[*a][*l]);
b->mode[3] =
b->mode[2] =
b->mode[1] = b->mode[0];
@@ -263,28 +265,28 @@ static void decode_mode(VP9TileData *td)
memset(a, b->mode[0], ff_vp9_bwh_tab[0][b->bs][0]);
memset(l, b->mode[0], ff_vp9_bwh_tab[0][b->bs][1]);
}
- b->uvmode = vp8_rac_get_tree(td->c, ff_vp9_intramode_tree,
- ff_vp9_default_kf_uvmode_probs[b->mode[3]]);
+ b->uvmode = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
+ ff_vp9_default_kf_uvmode_probs[b->mode[3]]);
} else if (b->intra) {
b->comp = 0;
if (b->bs > BS_8x8) {
- b->mode[0] = vp8_rac_get_tree(td->c, ff_vp9_intramode_tree,
- s->prob.p.y_mode[0]);
+ b->mode[0] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
+ s->prob.p.y_mode[0]);
td->counts.y_mode[0][b->mode[0]]++;
if (b->bs != BS_8x4) {
- b->mode[1] = vp8_rac_get_tree(td->c, ff_vp9_intramode_tree,
- s->prob.p.y_mode[0]);
+ b->mode[1] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
+ s->prob.p.y_mode[0]);
td->counts.y_mode[0][b->mode[1]]++;
} else {
b->mode[1] = b->mode[0];
}
if (b->bs != BS_4x8) {
- b->mode[2] = vp8_rac_get_tree(td->c, ff_vp9_intramode_tree,
- s->prob.p.y_mode[0]);
+ b->mode[2] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
+ s->prob.p.y_mode[0]);
td->counts.y_mode[0][b->mode[2]]++;
if (b->bs != BS_8x4) {
- b->mode[3] = vp8_rac_get_tree(td->c, ff_vp9_intramode_tree,
- s->prob.p.y_mode[0]);
+ b->mode[3] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
+ s->prob.p.y_mode[0]);
td->counts.y_mode[0][b->mode[3]]++;
} else {
b->mode[3] = b->mode[2];
@@ -299,15 +301,15 @@ static void decode_mode(VP9TileData *td)
};
int sz = size_group[b->bs];
- b->mode[0] = vp8_rac_get_tree(td->c, ff_vp9_intramode_tree,
- s->prob.p.y_mode[sz]);
+ b->mode[0] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
+ s->prob.p.y_mode[sz]);
b->mode[1] =
b->mode[2] =
b->mode[3] = b->mode[0];
td->counts.y_mode[sz][b->mode[3]]++;
}
- b->uvmode = vp8_rac_get_tree(td->c, ff_vp9_intramode_tree,
- s->prob.p.uv_mode[b->mode[3]]);
+ b->uvmode = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
+ s->prob.p.uv_mode[b->mode[3]]);
td->counts.uv_mode[b->mode[3]][b->uvmode]++;
} else {
static const uint8_t inter_mode_ctx_lut[14][14] = {
@@ -587,8 +589,8 @@ static void decode_mode(VP9TileData *td)
int c = inter_mode_ctx_lut[s->above_mode_ctx[col + off[b->bs]]]
[td->left_mode_ctx[row7 + off[b->bs]]];
- b->mode[0] = vp8_rac_get_tree(td->c, ff_vp9_inter_mode_tree,
- s->prob.p.mv_mode[c]);
+ b->mode[0] = vp89_rac_get_tree(td->c, ff_vp9_inter_mode_tree,
+ s->prob.p.mv_mode[c]);
b->mode[1] =
b->mode[2] =
b->mode[3] = b->mode[0];
@@ -612,8 +614,8 @@ static void decode_mode(VP9TileData *td)
c = 3;
}
- filter_id = vp8_rac_get_tree(td->c, ff_vp9_filter_tree,
- s->prob.p.filter[c]);
+ filter_id = vp89_rac_get_tree(td->c, ff_vp9_filter_tree,
+ s->prob.p.filter[c]);
td->counts.filter[c][filter_id]++;
b->filter = ff_vp9_filter_lut[filter_id];
} else {
@@ -623,14 +625,14 @@ static void decode_mode(VP9TileData *td)
if (b->bs > BS_8x8) {
int c = inter_mode_ctx_lut[s->above_mode_ctx[col]][td->left_mode_ctx[row7]];
- b->mode[0] = vp8_rac_get_tree(td->c, ff_vp9_inter_mode_tree,
- s->prob.p.mv_mode[c]);
+ b->mode[0] = vp89_rac_get_tree(td->c, ff_vp9_inter_mode_tree,
+ s->prob.p.mv_mode[c]);
td->counts.mv_mode[c][b->mode[0] - 10]++;
ff_vp9_fill_mv(td, b->mv[0], b->mode[0], 0);
if (b->bs != BS_8x4) {
- b->mode[1] = vp8_rac_get_tree(td->c, ff_vp9_inter_mode_tree,
- s->prob.p.mv_mode[c]);
+ b->mode[1] = vp89_rac_get_tree(td->c, ff_vp9_inter_mode_tree,
+ s->prob.p.mv_mode[c]);
td->counts.mv_mode[c][b->mode[1] - 10]++;
ff_vp9_fill_mv(td, b->mv[1], b->mode[1], 1);
} else {
@@ -640,14 +642,14 @@ static void decode_mode(VP9TileData *td)
}
if (b->bs != BS_4x8) {
- b->mode[2] = vp8_rac_get_tree(td->c, ff_vp9_inter_mode_tree,
- s->prob.p.mv_mode[c]);
+ b->mode[2] = vp89_rac_get_tree(td->c, ff_vp9_inter_mode_tree,
+ s->prob.p.mv_mode[c]);
td->counts.mv_mode[c][b->mode[2] - 10]++;
ff_vp9_fill_mv(td, b->mv[2], b->mode[2], 2);
if (b->bs != BS_8x4) {
- b->mode[3] = vp8_rac_get_tree(td->c, ff_vp9_inter_mode_tree,
- s->prob.p.mv_mode[c]);
+ b->mode[3] = vp89_rac_get_tree(td->c, ff_vp9_inter_mode_tree,
+ s->prob.p.mv_mode[c]);
td->counts.mv_mode[c][b->mode[3] - 10]++;
ff_vp9_fill_mv(td, b->mv[3], b->mode[3], 3);
} else {
@@ -909,9 +911,9 @@ skip_eob:
if (!--band_left)
band_left = band_counts[++band];
if (is_tx32x32)
- STORE_COEF(coef, rc, (int)((vp8_rac_get(c) ? -val : val) * (unsigned)qmul[!!i]) / 2);
+ STORE_COEF(coef, rc, (int)((vp89_rac_get(c) ? -val : val) * (unsigned)qmul[!!i]) / 2);
else
- STORE_COEF(coef, rc, (vp8_rac_get(c) ? -val : val) * (unsigned)qmul[!!i]);
+ STORE_COEF(coef, rc, (vp89_rac_get(c) ? -val : val) * (unsigned)qmul[!!i]);
nnz = (1 + cache[nb[i][0]] + cache[nb[i][1]]) >> 1;
tp = p[band][nnz];
} while (++i < n_coeffs);
diff --git a/libavcodec/vp9mvs.c b/libavcodec/vp9mvs.c
index ddce9b6c84..cee91dc34d 100644
--- a/libavcodec/vp9mvs.c
+++ b/libavcodec/vp9mvs.c
@@ -23,6 +23,7 @@
#include "threadframe.h"
#include "vp56.h"
+#include "vp89_rac.h"
#include "vp9.h"
#include "vp9data.h"
#include "vp9dec.h"
@@ -237,8 +238,8 @@ static av_always_inline int read_mv_component(VP9TileData *td, int idx, int hp)
{
VP9Context *s = td->s;
int bit, sign = vp56_rac_get_prob(td->c, s->prob.p.mv_comp[idx].sign);
- int n, c = vp8_rac_get_tree(td->c, ff_vp9_mv_class_tree,
- s->prob.p.mv_comp[idx].classes);
+ int n, c = vp89_rac_get_tree(td->c, ff_vp9_mv_class_tree,
+ s->prob.p.mv_comp[idx].classes);
td->counts.mv_comp[idx].sign[sign]++;
td->counts.mv_comp[idx].classes[c]++;
@@ -251,8 +252,8 @@ static av_always_inline int read_mv_component(VP9TileData *td, int idx, int hp)
td->counts.mv_comp[idx].bits[m][bit]++;
}
n <<= 3;
- bit = vp8_rac_get_tree(td->c, ff_vp9_mv_fp_tree,
- s->prob.p.mv_comp[idx].fp);
+ bit = vp89_rac_get_tree(td->c, ff_vp9_mv_fp_tree,
+ s->prob.p.mv_comp[idx].fp);
n |= bit << 1;
td->counts.mv_comp[idx].fp[bit]++;
if (hp) {
@@ -269,8 +270,8 @@ static av_always_inline int read_mv_component(VP9TileData *td, int idx, int hp)
} else {
n = vp56_rac_get_prob(td->c, s->prob.p.mv_comp[idx].class0);
td->counts.mv_comp[idx].class0[n]++;
- bit = vp8_rac_get_tree(td->c, ff_vp9_mv_fp_tree,
- s->prob.p.mv_comp[idx].class0_fp[n]);
+ bit = vp89_rac_get_tree(td->c, ff_vp9_mv_fp_tree,
+ s->prob.p.mv_comp[idx].class0_fp[n]);
td->counts.mv_comp[idx].class0_fp[n][bit]++;
n = (n << 3) | (bit << 1);
if (hp) {
@@ -319,8 +320,8 @@ void ff_vp9_fill_mv(VP9TileData *td, VP56mv *mv, int mode, int sb)
}
}
if (mode == NEWMV) {
- enum MVJoint j = vp8_rac_get_tree(td->c, ff_vp9_mv_joint_tree,
- s->prob.p.mv_joint);
+ enum MVJoint j = vp89_rac_get_tree(td->c, ff_vp9_mv_joint_tree,
+ s->prob.p.mv_joint);
td->counts.mv_joint[j]++;
if (j >= MV_JOINT_V)
@@ -350,8 +351,8 @@ void ff_vp9_fill_mv(VP9TileData *td, VP56mv *mv, int mode, int sb)
}
}
if (mode == NEWMV) {
- enum MVJoint j = vp8_rac_get_tree(td->c, ff_vp9_mv_joint_tree,
- s->prob.p.mv_joint);
+ enum MVJoint j = vp89_rac_get_tree(td->c, ff_vp9_mv_joint_tree,
+ s->prob.p.mv_joint);
td->counts.mv_joint[j]++;
if (j >= MV_JOINT_V)
More information about the ffmpeg-cvslog
mailing list