[FFmpeg-devel] [PATCH 4/5] avcodec/vp56: Move VP5-9 range coder functions to a header of their own

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Sat Jul 23 08:16:09 EEST 2022


Also use a vpx prefix for them.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/Makefile                          |  12 +-
 libavcodec/arm/vp8.h                         |   4 +-
 libavcodec/arm/vp8_armv6.S                   |   2 +-
 libavcodec/arm/{vp56_arith.h => vpx_arith.h} |  18 +-
 libavcodec/vp5.c                             |  63 +++----
 libavcodec/vp56.c                            |  15 +-
 libavcodec/vp56.h                            | 118 +------------
 libavcodec/vp6.c                             |  77 ++++-----
 libavcodec/vp8.c                             | 171 ++++++++++---------
 libavcodec/vp8.h                             |   5 +-
 libavcodec/vp89_rac.h                        |  14 +-
 libavcodec/vp9.c                             |  73 ++++----
 libavcodec/vp9block.c                        | 117 ++++++-------
 libavcodec/vp9dec.h                          |   7 +-
 libavcodec/vp9mvs.c                          |  12 +-
 libavcodec/{vp56rac.c => vpx_rac.c}          |   6 +-
 libavcodec/vpx_rac.h                         | 135 +++++++++++++++
 libavcodec/x86/{vp56_arith.h => vpx_arith.h} |  14 +-
 18 files changed, 454 insertions(+), 409 deletions(-)
 rename libavcodec/arm/{vp56_arith.h => vpx_arith.h} (88%)
 rename libavcodec/{vp56rac.c => vpx_rac.c} (92%)
 create mode 100644 libavcodec/vpx_rac.h
 rename libavcodec/x86/{vp56_arith.h => vpx_arith.h} (83%)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index ef2318438b..a4fab108d6 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -737,11 +737,11 @@ OBJS-$(CONFIG_VORBIS_DECODER)          += vorbisdec.o vorbisdsp.o vorbis.o \
 OBJS-$(CONFIG_VORBIS_ENCODER)          += vorbisenc.o vorbis.o \
                                           vorbis_data.o
 OBJS-$(CONFIG_VP3_DECODER)             += vp3.o
-OBJS-$(CONFIG_VP5_DECODER)             += vp5.o vp56.o vp56data.o vp56rac.o
+OBJS-$(CONFIG_VP5_DECODER)             += vp5.o vp56.o vp56data.o vpx_rac.o
 OBJS-$(CONFIG_VP6_DECODER)             += vp6.o vp56.o vp56data.o \
-                                          vp6dsp.o vp56rac.o
-OBJS-$(CONFIG_VP7_DECODER)             += vp8.o vp56rac.o
-OBJS-$(CONFIG_VP8_DECODER)             += vp8.o vp56rac.o
+                                          vp6dsp.o vpx_rac.o
+OBJS-$(CONFIG_VP7_DECODER)             += vp8.o vpx_rac.o
+OBJS-$(CONFIG_VP8_DECODER)             += vp8.o vpx_rac.o
 OBJS-$(CONFIG_VP8_CUVID_DECODER)       += cuviddec.o
 OBJS-$(CONFIG_VP8_MEDIACODEC_DECODER)  += mediacodecdec.o
 OBJS-$(CONFIG_VP8_QSV_DECODER)         += qsvdec.o
@@ -750,7 +750,7 @@ OBJS-$(CONFIG_VP8_VAAPI_ENCODER)       += vaapi_encode_vp8.o
 OBJS-$(CONFIG_VP8_V4L2M2M_DECODER)     += v4l2_m2m_dec.o
 OBJS-$(CONFIG_VP8_V4L2M2M_ENCODER)     += v4l2_m2m_enc.o
 OBJS-$(CONFIG_VP9_DECODER)             += vp9.o vp9data.o vp9dsp.o vp9lpf.o vp9recon.o \
-                                          vp9block.o vp9prob.o vp9mvs.o vp56rac.o \
+                                          vp9block.o vp9prob.o vp9mvs.o vpx_rac.o \
                                           vp9dsp_8bpp.o vp9dsp_10bpp.o vp9dsp_12bpp.o
 OBJS-$(CONFIG_VP9_CUVID_DECODER)       += cuviddec.o
 OBJS-$(CONFIG_VP9_MEDIACODEC_DECODER)  += mediacodecdec.o
@@ -1234,7 +1234,7 @@ SKIPHEADERS                            += %_tablegen.h                  \
                                           aaccoder_trellis.h            \
                                           aacenc_quantization.h         \
                                           aacenc_quantization_misc.h    \
-                                          $(ARCH)/vp56_arith.h          \
+                                          $(ARCH)/vpx_arith.h          \
 
 SKIPHEADERS-$(CONFIG_AMF)              += amfenc.h
 SKIPHEADERS-$(CONFIG_D3D11VA)          += d3d11va.h dxva2_internal.h
diff --git a/libavcodec/arm/vp8.h b/libavcodec/arm/vp8.h
index 965342d93b..7c59a7d63d 100644
--- a/libavcodec/arm/vp8.h
+++ b/libavcodec/arm/vp8.h
@@ -22,12 +22,12 @@
 #include <stdint.h>
 
 #include "config.h"
-#include "libavcodec/vp56.h"
+#include "libavcodec/vpx_rac.h"
 #include "libavcodec/vp8.h"
 
 #if HAVE_ARMV6_EXTERNAL
 #define vp8_decode_block_coeffs_internal ff_decode_block_coeffs_armv6
-int ff_decode_block_coeffs_armv6(VP56RangeCoder *rc, int16_t block[16],
+int ff_decode_block_coeffs_armv6(VPXRangeCoder *rc, int16_t block[16],
                                  uint8_t probs[8][3][NUM_DCT_TOKENS-1],
                                  int i, uint8_t *token_prob, int16_t qmul[2]);
 #endif
diff --git a/libavcodec/arm/vp8_armv6.S b/libavcodec/arm/vp8_armv6.S
index e7d25a45c1..7ecf2641fb 100644
--- a/libavcodec/arm/vp8_armv6.S
+++ b/libavcodec/arm/vp8_armv6.S
@@ -65,7 +65,7 @@ T       orrcs           \cw, \cw, \t1
 
 function ff_decode_block_coeffs_armv6, export=1
         push            {r0,r1,r4-r11,lr}
-        movrelx         lr,  X(ff_vp56_norm_shift)
+        movrelx         lr,  X(ff_vpx_norm_shift)
         ldrd            r4,  r5,  [sp, #44]             @ token_prob, qmul
         cmp             r3,  #0
         ldr             r11, [r5]
diff --git a/libavcodec/arm/vp56_arith.h b/libavcodec/arm/vpx_arith.h
similarity index 88%
rename from libavcodec/arm/vp56_arith.h
rename to libavcodec/arm/vpx_arith.h
index feb1247916..1ead2284c3 100644
--- a/libavcodec/arm/vp56_arith.h
+++ b/libavcodec/arm/vpx_arith.h
@@ -18,8 +18,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#ifndef AVCODEC_ARM_VP56_ARITH_H
-#define AVCODEC_ARM_VP56_ARITH_H
+#ifndef AVCODEC_ARM_VPX_ARITH_H
+#define AVCODEC_ARM_VPX_ARITH_H
 
 #if CONFIG_THUMB
 #   define A(x)
@@ -39,10 +39,10 @@
 
 #if HAVE_ARMV6_INLINE
 
-#define vp56_rac_get_prob vp56_rac_get_prob_armv6
-static inline int vp56_rac_get_prob_armv6(VP56RangeCoder *c, int pr)
+#define vpx_rac_get_prob vp56_rac_get_prob_armv6
+static inline int vp56_rac_get_prob_armv6(VPXRangeCoder *c, int pr)
 {
-    unsigned shift     = ff_vp56_norm_shift[c->high];
+    unsigned shift     = ff_vpx_norm_shift[c->high];
     unsigned code_word = c->code_word << shift;
     unsigned high      = c->high << shift;
     unsigned bit;
@@ -76,10 +76,10 @@ static inline int vp56_rac_get_prob_armv6(VP56RangeCoder *c, int pr)
     return bit;
 }
 
-#define vp56_rac_get_prob_branchy vp56_rac_get_prob_branchy_armv6
-static inline int vp56_rac_get_prob_branchy_armv6(VP56RangeCoder *c, int pr)
+#define vpx_rac_get_prob_branchy vp56_rac_get_prob_branchy_armv6
+static inline int vp56_rac_get_prob_branchy_armv6(VPXRangeCoder *c, int pr)
 {
-    unsigned shift     = ff_vp56_norm_shift[c->high];
+    unsigned shift     = ff_vpx_norm_shift[c->high];
     unsigned code_word = c->code_word << shift;
     unsigned high      = c->high << shift;
     unsigned low;
@@ -118,4 +118,4 @@ static inline int vp56_rac_get_prob_branchy_armv6(VP56RangeCoder *c, int pr)
 
 #endif
 
-#endif /* AVCODEC_ARM_VP56_ARITH_H */
+#endif /* AVCODEC_ARM_VPX_ARITH_H */
diff --git a/libavcodec/vp5.c b/libavcodec/vp5.c
index de8846a867..8ba4de71e5 100644
--- a/libavcodec/vp5.c
+++ b/libavcodec/vp5.c
@@ -33,19 +33,20 @@
 #include "vp56.h"
 #include "vp56data.h"
 #include "vp5data.h"
+#include "vpx_rac.h"
 
 
 static int vp5_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     int rows, cols;
     int ret;
 
-    ret = ff_vp56_init_range_decoder(&s->c, buf, buf_size);
+    ret = ff_vpx_init_range_decoder(&s->c, buf, buf_size);
     if (ret < 0)
         return ret;
-    s->frames[VP56_FRAME_CURRENT]->key_frame = !vp56_rac_get(c);
-    vp56_rac_get(c);
+    s->frames[VP56_FRAME_CURRENT]->key_frame = !vpx_rac_get(c);
+    vpx_rac_get(c);
     ff_vp56_init_dequant(s, vp56_rac_gets(c, 6));
     if (s->frames[VP56_FRAME_CURRENT]->key_frame)
     {
@@ -55,7 +56,7 @@ static int vp5_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
         if(vp56_rac_gets(c, 5) > 5)
             return AVERROR_INVALIDDATA;
         vp56_rac_gets(c, 2);
-        if (vp56_rac_get(c)) {
+        if (vpx_rac_get(c)) {
             avpriv_report_missing_feature(s->avctx, "Interlacing");
             return AVERROR_PATCHWELCOME;
         }
@@ -87,16 +88,16 @@ static int vp5_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
 
 static void vp5_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     VP56Model *model = s->modelp;
     int comp, di;
 
     for (comp=0; comp<2; comp++) {
         int delta = 0;
-        if (vp56_rac_get_prob_branchy(c, model->vector_dct[comp])) {
-            int sign = vp56_rac_get_prob(c, model->vector_sig[comp]);
-            di  = vp56_rac_get_prob(c, model->vector_pdi[comp][0]);
-            di |= vp56_rac_get_prob(c, model->vector_pdi[comp][1]) << 1;
+        if (vpx_rac_get_prob_branchy(c, model->vector_dct[comp])) {
+            int sign = vpx_rac_get_prob(c, model->vector_sig[comp]);
+            di  = vpx_rac_get_prob(c, model->vector_pdi[comp][0]);
+            di |= vpx_rac_get_prob(c, model->vector_pdi[comp][1]) << 1;
             delta = vp56_rac_get_tree(c, ff_vp56_pva_tree,
                                       model->vector_pdv[comp]);
             delta = di | (delta << 2);
@@ -111,30 +112,30 @@ static void vp5_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
 
 static void vp5_parse_vector_models(VP56Context *s)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     VP56Model *model = s->modelp;
     int comp, node;
 
     for (comp=0; comp<2; comp++) {
-        if (vp56_rac_get_prob_branchy(c, vp5_vmc_pct[comp][0]))
+        if (vpx_rac_get_prob_branchy(c, vp5_vmc_pct[comp][0]))
             model->vector_dct[comp] = vp56_rac_gets_nn(c, 7);
-        if (vp56_rac_get_prob_branchy(c, vp5_vmc_pct[comp][1]))
+        if (vpx_rac_get_prob_branchy(c, vp5_vmc_pct[comp][1]))
             model->vector_sig[comp] = vp56_rac_gets_nn(c, 7);
-        if (vp56_rac_get_prob_branchy(c, vp5_vmc_pct[comp][2]))
+        if (vpx_rac_get_prob_branchy(c, vp5_vmc_pct[comp][2]))
             model->vector_pdi[comp][0] = vp56_rac_gets_nn(c, 7);
-        if (vp56_rac_get_prob_branchy(c, vp5_vmc_pct[comp][3]))
+        if (vpx_rac_get_prob_branchy(c, vp5_vmc_pct[comp][3]))
             model->vector_pdi[comp][1] = vp56_rac_gets_nn(c, 7);
     }
 
     for (comp=0; comp<2; comp++)
         for (node=0; node<7; node++)
-            if (vp56_rac_get_prob_branchy(c, vp5_vmc_pct[comp][4 + node]))
+            if (vpx_rac_get_prob_branchy(c, vp5_vmc_pct[comp][4 + node]))
                 model->vector_pdv[comp][node] = vp56_rac_gets_nn(c, 7);
 }
 
 static int vp5_parse_coeff_models(VP56Context *s)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     VP56Model *model = s->modelp;
     uint8_t def_prob[11];
     int node, cg, ctx;
@@ -145,7 +146,7 @@ static int vp5_parse_coeff_models(VP56Context *s)
 
     for (pt=0; pt<2; pt++)
         for (node=0; node<11; node++)
-            if (vp56_rac_get_prob_branchy(c, vp5_dccv_pct[pt][node])) {
+            if (vpx_rac_get_prob_branchy(c, vp5_dccv_pct[pt][node])) {
                 def_prob[node] = vp56_rac_gets_nn(c, 7);
                 model->coeff_dccv[pt][node] = def_prob[node];
             } else if (s->frames[VP56_FRAME_CURRENT]->key_frame) {
@@ -156,7 +157,7 @@ static int vp5_parse_coeff_models(VP56Context *s)
         for (pt=0; pt<2; pt++)
             for (cg=0; cg<6; cg++)
                 for (node=0; node<11; node++)
-                    if (vp56_rac_get_prob_branchy(c, vp5_ract_pct[ct][pt][cg][node])) {
+                    if (vpx_rac_get_prob_branchy(c, vp5_ract_pct[ct][pt][cg][node])) {
                         def_prob[node] = vp56_rac_gets_nn(c, 7);
                         model->coeff_ract[pt][ct][cg][node] = def_prob[node];
                     } else if (s->frames[VP56_FRAME_CURRENT]->key_frame) {
@@ -181,7 +182,7 @@ static int vp5_parse_coeff_models(VP56Context *s)
 
 static int vp5_parse_coeff(VP56Context *s)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     VP56Model *model = s->modelp;
     uint8_t *permute = s->idct_scantable;
     uint8_t *model1, *model2;
@@ -189,7 +190,7 @@ static int vp5_parse_coeff(VP56Context *s)
     int b, i, cg, idx, ctx, ctx_last;
     int pt = 0;    /* plane type (0 for Y, 1 for U or V) */
 
-    if (vpX_rac_is_end(c)) {
+    if (vpx_rac_is_end(c)) {
         av_log(s->avctx, AV_LOG_ERROR, "End of AC stream reached in vp5_parse_coeff\n");
         return AVERROR_INVALIDDATA;
     }
@@ -206,30 +207,30 @@ static int vp5_parse_coeff(VP56Context *s)
 
         coeff_idx = 0;
         for (;;) {
-            if (vp56_rac_get_prob_branchy(c, model2[0])) {
-                if (vp56_rac_get_prob_branchy(c, model2[2])) {
-                    if (vp56_rac_get_prob_branchy(c, model2[3])) {
+            if (vpx_rac_get_prob_branchy(c, model2[0])) {
+                if (vpx_rac_get_prob_branchy(c, model2[2])) {
+                    if (vpx_rac_get_prob_branchy(c, model2[3])) {
                         s->coeff_ctx[ff_vp56_b6to4[b]][coeff_idx] = 4;
                         idx = vp56_rac_get_tree(c, ff_vp56_pc_tree, model1);
-                        sign = vp56_rac_get(c);
+                        sign = vpx_rac_get(c);
                         coeff = ff_vp56_coeff_bias[idx+5];
                         for (i=ff_vp56_coeff_bit_length[idx]; i>=0; i--)
-                            coeff += vp56_rac_get_prob(c, ff_vp56_coeff_parse_table[idx][i]) << i;
+                            coeff += vpx_rac_get_prob(c, ff_vp56_coeff_parse_table[idx][i]) << i;
                     } else {
-                        if (vp56_rac_get_prob_branchy(c, model2[4])) {
-                            coeff = 3 + vp56_rac_get_prob(c, model1[5]);
+                        if (vpx_rac_get_prob_branchy(c, model2[4])) {
+                            coeff = 3 + vpx_rac_get_prob(c, model1[5]);
                             s->coeff_ctx[ff_vp56_b6to4[b]][coeff_idx] = 3;
                         } else {
                             coeff = 2;
                             s->coeff_ctx[ff_vp56_b6to4[b]][coeff_idx] = 2;
                         }
-                        sign = vp56_rac_get(c);
+                        sign = vpx_rac_get(c);
                     }
                     ct = 2;
                 } else {
                     ct = 1;
                     s->coeff_ctx[ff_vp56_b6to4[b]][coeff_idx] = 1;
-                    sign = vp56_rac_get(c);
+                    sign = vpx_rac_get(c);
                     coeff = 1;
                 }
                 coeff = (coeff ^ -sign) + sign;
@@ -237,7 +238,7 @@ static int vp5_parse_coeff(VP56Context *s)
                     coeff *= s->dequant_ac;
                 s->block_coeff[b][permute[coeff_idx]] = coeff;
             } else {
-                if (ct && !vp56_rac_get_prob_branchy(c, model2[1]))
+                if (ct && !vpx_rac_get_prob_branchy(c, model2[1]))
                     break;
                 ct = 0;
                 s->coeff_ctx[ff_vp56_b6to4[b]][coeff_idx] = 0;
diff --git a/libavcodec/vp56.c b/libavcodec/vp56.c
index a2efca1c9c..3863af15e5 100644
--- a/libavcodec/vp56.c
+++ b/libavcodec/vp56.c
@@ -29,6 +29,7 @@
 #include "h264chroma.h"
 #include "vp56.h"
 #include "vp56data.h"
+#include "vpx_rac.h"
 
 
 void ff_vp56_init_dequant(VP56Context *s, int quantizer)
@@ -80,22 +81,22 @@ static int vp56_get_vectors_predictors(VP56Context *s, int row, int col,
 
 static void vp56_parse_mb_type_models(VP56Context *s)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     VP56Model *model = s->modelp;
     int i, ctx, type;
 
     for (ctx=0; ctx<3; ctx++) {
-        if (vp56_rac_get_prob_branchy(c, 174)) {
+        if (vpx_rac_get_prob_branchy(c, 174)) {
             int idx = vp56_rac_gets(c, 4);
             memcpy(model->mb_types_stats[ctx],
                    ff_vp56_pre_def_mb_type_stats[idx][ctx],
                    sizeof(model->mb_types_stats[ctx]));
         }
-        if (vp56_rac_get_prob_branchy(c, 254)) {
+        if (vpx_rac_get_prob_branchy(c, 254)) {
             for (type=0; type<10; type++) {
                 for(i=0; i<2; i++) {
-                    if (vp56_rac_get_prob_branchy(c, 205)) {
-                        int delta, sign = vp56_rac_get(c);
+                    if (vpx_rac_get_prob_branchy(c, 205)) {
+                        int delta, sign = vpx_rac_get(c);
 
                         delta = vp56_rac_get_tree(c, ff_vp56_pmbtm_tree,
                                                   ff_vp56_mb_type_model_model);
@@ -153,9 +154,9 @@ static VP56mb vp56_parse_mb_type(VP56Context *s,
                                  VP56mb prev_type, int ctx)
 {
     uint8_t *mb_type_model = s->modelp->mb_type[ctx][prev_type];
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
 
-    if (vp56_rac_get_prob_branchy(c, mb_type_model[0]))
+    if (vpx_rac_get_prob_branchy(c, mb_type_model[0]))
         return prev_type;
     else
         return vp56_rac_get_tree(c, ff_vp56_pmbt_tree, mb_type_model);
diff --git a/libavcodec/vp56.h b/libavcodec/vp56.h
index 174f126309..b1b14b63f8 100644
--- a/libavcodec/vp56.h
+++ b/libavcodec/vp56.h
@@ -31,11 +31,11 @@
 #include "avcodec.h"
 #include "get_bits.h"
 #include "hpeldsp.h"
-#include "bytestream.h"
 #include "h264chroma.h"
 #include "videodsp.h"
 #include "vp3dsp.h"
 #include "vp56dsp.h"
+#include "vpx_rac.h"
 
 typedef struct vp56_context VP56Context;
 
@@ -84,16 +84,6 @@ typedef int  (*VP56ParseCoeffModels)(VP56Context *s);
 typedef int  (*VP56ParseHeader)(VP56Context *s, const uint8_t *buf,
                                 int buf_size);
 
-typedef struct VP56RangeCoder {
-    int high;
-    int bits; /* stored negated (i.e. negative "bits" is a positive number of
-                 bits left) in order to eliminate a negate in cache refilling */
-    const uint8_t *buffer;
-    const uint8_t *end;
-    unsigned int code_word;
-    int end_reached;
-} VP56RangeCoder;
-
 typedef struct VP56RefDc {
     uint8_t not_null_dc;
     VP56Frame ref_frame;
@@ -134,9 +124,9 @@ struct vp56_context {
     AVFrame *frames[4];
     uint8_t *edge_emu_buffer_alloc;
     uint8_t *edge_emu_buffer;
-    VP56RangeCoder c;
-    VP56RangeCoder cc;
-    VP56RangeCoder *ccp;
+    VPXRangeCoder c;
+    VPXRangeCoder cc;
+    VPXRangeCoder *ccp;
     int sub_version;
 
     /* frame info */
@@ -232,121 +222,31 @@ int ff_vp56_decode_frame(AVCodecContext *avctx, AVFrame *frame,
  * vp56 specific range coder implementation
  */
 
-extern const uint8_t ff_vp56_norm_shift[256];
-int ff_vp56_init_range_decoder(VP56RangeCoder *c, const uint8_t *buf, int buf_size);
-
-/**
- * vp5689 returns 1 if the end of the stream has been reached, 0 otherwise.
- */
-static av_always_inline int vpX_rac_is_end(VP56RangeCoder *c)
-{
-    if (c->end <= c->buffer && c->bits >= 0)
-        c->end_reached ++;
-    return c->end_reached > 10;
-}
-
-static av_always_inline unsigned int vp56_rac_renorm(VP56RangeCoder *c)
-{
-    int shift = ff_vp56_norm_shift[c->high];
-    int bits = c->bits;
-    unsigned int code_word = c->code_word;
-
-    c->high   <<= shift;
-    code_word <<= shift;
-    bits       += shift;
-    if(bits >= 0 && c->buffer < c->end) {
-        code_word |= bytestream_get_be16(&c->buffer) << bits;
-        bits -= 16;
-    }
-    c->bits = bits;
-    return code_word;
-}
-
-#if   ARCH_ARM
-#include "arm/vp56_arith.h"
-#elif ARCH_X86
-#include "x86/vp56_arith.h"
-#endif
-
-#ifndef vp56_rac_get_prob
-#define vp56_rac_get_prob vp56_rac_get_prob
-static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob)
-{
-    unsigned int code_word = vp56_rac_renorm(c);
-    unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
-    unsigned int low_shift = low << 16;
-    int bit = code_word >= low_shift;
-
-    c->high = bit ? c->high - low : low;
-    c->code_word = bit ? code_word - low_shift : code_word;
-
-    return bit;
-}
-#endif
-
-#ifndef vp56_rac_get_prob_branchy
-// branchy variant, to be used where there's a branch based on the bit decoded
-static av_always_inline int vp56_rac_get_prob_branchy(VP56RangeCoder *c, int prob)
-{
-    unsigned long code_word = vp56_rac_renorm(c);
-    unsigned low = 1 + (((c->high - 1) * prob) >> 8);
-    unsigned low_shift = low << 16;
-
-    if (code_word >= low_shift) {
-        c->high     -= low;
-        c->code_word = code_word - low_shift;
-        return 1;
-    }
-
-    c->high = low;
-    c->code_word = code_word;
-    return 0;
-}
-#endif
-
-static av_always_inline int vp56_rac_get(VP56RangeCoder *c)
-{
-    unsigned int code_word = vp56_rac_renorm(c);
-    /* equiprobable */
-    int low = (c->high + 1) >> 1;
-    unsigned int low_shift = low << 16;
-    int bit = code_word >= low_shift;
-    if (bit) {
-        c->high   -= low;
-        code_word -= low_shift;
-    } else {
-        c->high = low;
-    }
-
-    c->code_word = code_word;
-    return bit;
-}
-
-static int vp56_rac_gets(VP56RangeCoder *c, int bits)
+static int vp56_rac_gets(VPXRangeCoder *c, int bits)
 {
     int value = 0;
 
     while (bits--) {
-        value = (value << 1) | vp56_rac_get(c);
+        value = (value << 1) | vpx_rac_get(c);
     }
 
     return value;
 }
 
 // P(7)
-static av_unused int vp56_rac_gets_nn(VP56RangeCoder *c, int bits)
+static av_unused int vp56_rac_gets_nn(VPXRangeCoder *c, int bits)
 {
     int v = vp56_rac_gets(c, 7) << 1;
     return v + !v;
 }
 
 static av_always_inline
-int vp56_rac_get_tree(VP56RangeCoder *c,
+int vp56_rac_get_tree(VPXRangeCoder *c,
                       const VP56Tree *tree,
                       const uint8_t *probs)
 {
     while (tree->val > 0) {
-        if (vp56_rac_get_prob_branchy(c, probs[tree->prob_idx]))
+        if (vpx_rac_get_prob_branchy(c, probs[tree->prob_idx]))
             tree += tree->val;
         else
             tree++;
diff --git a/libavcodec/vp6.c b/libavcodec/vp6.c
index 37938038c4..ad81060886 100644
--- a/libavcodec/vp6.c
+++ b/libavcodec/vp6.c
@@ -38,6 +38,7 @@
 #include "vp56.h"
 #include "vp56data.h"
 #include "vp6data.h"
+#include "vpx_rac.h"
 
 #define VP6_MAX_HUFF_SIZE 12
 
@@ -46,7 +47,7 @@ static int vp6_parse_coeff_huffman(VP56Context *s);
 
 static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     int parse_filter_info = 0;
     int coeff_offset = 0;
     int vrt_shift = 0;
@@ -107,7 +108,7 @@ static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
             res = VP56_SIZE_CHANGE;
         }
 
-        ret = ff_vp56_init_range_decoder(c, buf+6, buf_size-6);
+        ret = ff_vpx_init_range_decoder(c, buf+6, buf_size-6);
         if (ret < 0)
             goto fail;
         vp56_rac_gets(c, 2);
@@ -126,26 +127,26 @@ static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
             buf += 2;
             buf_size -= 2;
         }
-        ret = ff_vp56_init_range_decoder(c, buf+1, buf_size-1);
+        ret = ff_vpx_init_range_decoder(c, buf+1, buf_size-1);
         if (ret < 0)
             return ret;
 
-        s->golden_frame = vp56_rac_get(c);
+        s->golden_frame = vpx_rac_get(c);
         if (s->filter_header) {
-            s->deblock_filtering = vp56_rac_get(c);
+            s->deblock_filtering = vpx_rac_get(c);
             if (s->deblock_filtering)
-                vp56_rac_get(c);
+                vpx_rac_get(c);
             if (s->sub_version > 7)
-                parse_filter_info = vp56_rac_get(c);
+                parse_filter_info = vpx_rac_get(c);
         }
     }
 
     if (parse_filter_info) {
-        if (vp56_rac_get(c)) {
+        if (vpx_rac_get(c)) {
             s->filter_mode = 2;
             s->sample_variance_threshold = vp56_rac_gets(c, 5) << vrt_shift;
             s->max_vector_length = 2 << vp56_rac_gets(c, 3);
-        } else if (vp56_rac_get(c)) {
+        } else if (vpx_rac_get(c)) {
             s->filter_mode = 1;
         } else {
             s->filter_mode = 0;
@@ -156,7 +157,7 @@ static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
             s->filter_selection = 16;
     }
 
-    s->use_huffman = vp56_rac_get(c);
+    s->use_huffman = vpx_rac_get(c);
 
     s->parse_coeff = vp6_parse_coeff;
     if (coeff_offset) {
@@ -172,7 +173,7 @@ static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
             if (ret < 0)
                 return ret;
         } else {
-            ret = ff_vp56_init_range_decoder(&s->cc, buf, buf_size);
+            ret = ff_vpx_init_range_decoder(&s->cc, buf, buf_size);
             if (ret < 0)
                 goto fail;
             s->ccp = &s->cc;
@@ -231,25 +232,25 @@ static void vp6_default_models_init(VP56Context *s)
 
 static void vp6_parse_vector_models(VP56Context *s)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     VP56Model *model = s->modelp;
     int comp, node;
 
     for (comp=0; comp<2; comp++) {
-        if (vp56_rac_get_prob_branchy(c, vp6_sig_dct_pct[comp][0]))
+        if (vpx_rac_get_prob_branchy(c, vp6_sig_dct_pct[comp][0]))
             model->vector_dct[comp] = vp56_rac_gets_nn(c, 7);
-        if (vp56_rac_get_prob_branchy(c, vp6_sig_dct_pct[comp][1]))
+        if (vpx_rac_get_prob_branchy(c, vp6_sig_dct_pct[comp][1]))
             model->vector_sig[comp] = vp56_rac_gets_nn(c, 7);
     }
 
     for (comp=0; comp<2; comp++)
         for (node=0; node<7; node++)
-            if (vp56_rac_get_prob_branchy(c, vp6_pdv_pct[comp][node]))
+            if (vpx_rac_get_prob_branchy(c, vp6_pdv_pct[comp][node]))
                 model->vector_pdv[comp][node] = vp56_rac_gets_nn(c, 7);
 
     for (comp=0; comp<2; comp++)
         for (node=0; node<8; node++)
-            if (vp56_rac_get_prob_branchy(c, vp6_fdv_pct[comp][node]))
+            if (vpx_rac_get_prob_branchy(c, vp6_fdv_pct[comp][node]))
                 model->vector_fdv[comp][node] = vp56_rac_gets_nn(c, 7);
 }
 
@@ -284,7 +285,7 @@ static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[],
 
 static int vp6_parse_coeff_models(VP56Context *s)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     VP56Model *model = s->modelp;
     int def_prob[11];
     int node, cg, ctx, pos;
@@ -295,30 +296,30 @@ static int vp6_parse_coeff_models(VP56Context *s)
 
     for (pt=0; pt<2; pt++)
         for (node=0; node<11; node++)
-            if (vp56_rac_get_prob_branchy(c, vp6_dccv_pct[pt][node])) {
+            if (vpx_rac_get_prob_branchy(c, vp6_dccv_pct[pt][node])) {
                 def_prob[node] = vp56_rac_gets_nn(c, 7);
                 model->coeff_dccv[pt][node] = def_prob[node];
             } else if (s->frames[VP56_FRAME_CURRENT]->key_frame) {
                 model->coeff_dccv[pt][node] = def_prob[node];
             }
 
-    if (vp56_rac_get(c)) {
+    if (vpx_rac_get(c)) {
         for (pos=1; pos<64; pos++)
-            if (vp56_rac_get_prob_branchy(c, vp6_coeff_reorder_pct[pos]))
+            if (vpx_rac_get_prob_branchy(c, vp6_coeff_reorder_pct[pos]))
                 model->coeff_reorder[pos] = vp56_rac_gets(c, 4);
         vp6_coeff_order_table_init(s);
     }
 
     for (cg=0; cg<2; cg++)
         for (node=0; node<14; node++)
-            if (vp56_rac_get_prob_branchy(c, vp6_runv_pct[cg][node]))
+            if (vpx_rac_get_prob_branchy(c, vp6_runv_pct[cg][node]))
                 model->coeff_runv[cg][node] = vp56_rac_gets_nn(c, 7);
 
     for (ct=0; ct<3; ct++)
         for (pt=0; pt<2; pt++)
             for (cg=0; cg<6; cg++)
                 for (node=0; node<11; node++)
-                    if (vp56_rac_get_prob_branchy(c, vp6_ract_pct[ct][pt][cg][node])) {
+                    if (vpx_rac_get_prob_branchy(c, vp6_ract_pct[ct][pt][cg][node])) {
                         def_prob[node] = vp56_rac_gets_nn(c, 7);
                         model->coeff_ract[pt][ct][cg][node] = def_prob[node];
                     } else if (s->frames[VP56_FRAME_CURRENT]->key_frame) {
@@ -353,7 +354,7 @@ static int vp6_parse_coeff_models(VP56Context *s)
 
 static void vp6_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     VP56Model *model = s->modelp;
     int comp;
 
@@ -364,14 +365,14 @@ static void vp6_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
     for (comp=0; comp<2; comp++) {
         int i, delta = 0;
 
-        if (vp56_rac_get_prob_branchy(c, model->vector_dct[comp])) {
+        if (vpx_rac_get_prob_branchy(c, model->vector_dct[comp])) {
             static const uint8_t prob_order[] = {0, 1, 2, 7, 6, 5, 4};
             for (i=0; i<sizeof(prob_order); i++) {
                 int j = prob_order[i];
-                delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][j])<<j;
+                delta |= vpx_rac_get_prob(c, model->vector_fdv[comp][j])<<j;
             }
             if (delta & 0xF0)
-                delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][3])<<3;
+                delta |= vpx_rac_get_prob(c, model->vector_fdv[comp][3])<<3;
             else
                 delta |= 8;
         } else {
@@ -379,7 +380,7 @@ static void vp6_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
                                       model->vector_pdv[comp]);
         }
 
-        if (delta && vp56_rac_get_prob_branchy(c, model->vector_sig[comp]))
+        if (delta && vpx_rac_get_prob_branchy(c, model->vector_sig[comp]))
             delta = -delta;
 
         if (!comp)
@@ -468,7 +469,7 @@ static int vp6_parse_coeff_huffman(VP56Context *s)
 
 static int vp6_parse_coeff(VP56Context *s)
 {
-    VP56RangeCoder *c = s->ccp;
+    VPXRangeCoder *c = s->ccp;
     VP56Model *model = s->modelp;
     uint8_t *permute = s->idct_scantable;
     uint8_t *model1, *model2, *model3;
@@ -476,7 +477,7 @@ static int vp6_parse_coeff(VP56Context *s)
     int b, i, cg, idx, ctx;
     int pt = 0;    /* plane type (0 for Y, 1 for U or V) */
 
-    if (vpX_rac_is_end(c)) {
+    if (vpx_rac_is_end(c)) {
         av_log(s->avctx, AV_LOG_ERROR, "End of AC stream reached in vp6_parse_coeff\n");
         return AVERROR_INVALIDDATA;
     }
@@ -494,17 +495,17 @@ static int vp6_parse_coeff(VP56Context *s)
 
         coeff_idx = 0;
         for (;;) {
-            if ((coeff_idx>1 && ct==0) || vp56_rac_get_prob_branchy(c, model2[0])) {
+            if ((coeff_idx>1 && ct==0) || vpx_rac_get_prob_branchy(c, model2[0])) {
                 /* parse a coeff */
-                if (vp56_rac_get_prob_branchy(c, model2[2])) {
-                    if (vp56_rac_get_prob_branchy(c, model2[3])) {
+                if (vpx_rac_get_prob_branchy(c, model2[2])) {
+                    if (vpx_rac_get_prob_branchy(c, model2[3])) {
                         idx = vp56_rac_get_tree(c, ff_vp56_pc_tree, model1);
                         coeff = ff_vp56_coeff_bias[idx+5];
                         for (i=ff_vp56_coeff_bit_length[idx]; i>=0; i--)
-                            coeff += vp56_rac_get_prob(c, ff_vp56_coeff_parse_table[idx][i]) << i;
+                            coeff += vpx_rac_get_prob(c, ff_vp56_coeff_parse_table[idx][i]) << i;
                     } else {
-                        if (vp56_rac_get_prob_branchy(c, model2[4]))
-                            coeff = 3 + vp56_rac_get_prob(c, model1[5]);
+                        if (vpx_rac_get_prob_branchy(c, model2[4]))
+                            coeff = 3 + vpx_rac_get_prob(c, model1[5]);
                         else
                             coeff = 2;
                     }
@@ -513,7 +514,7 @@ static int vp6_parse_coeff(VP56Context *s)
                     ct = 1;
                     coeff = 1;
                 }
-                sign = vp56_rac_get(c);
+                sign = vpx_rac_get(c);
                 coeff = (coeff ^ -sign) + sign;
                 if (coeff_idx)
                     coeff *= s->dequant_ac;
@@ -524,14 +525,14 @@ static int vp6_parse_coeff(VP56Context *s)
                 /* parse a run */
                 ct = 0;
                 if (coeff_idx > 0) {
-                    if (!vp56_rac_get_prob_branchy(c, model2[1]))
+                    if (!vpx_rac_get_prob_branchy(c, model2[1]))
                         break;
 
                     model3 = model->coeff_runv[coeff_idx >= 6];
                     run = vp56_rac_get_tree(c, vp6_pcr_tree, model3);
                     if (!run)
                         for (run=9, i=0; i<6; i++)
-                            run += vp56_rac_get_prob(c, model3[i+8]) << i;
+                            run += vpx_rac_get_prob(c, model3[i+8]) << i;
                 }
             }
             coeff_idx += run;
diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index ade7769943..de1fdac82e 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -40,6 +40,7 @@
 #include "vp8.h"
 #include "vp89_rac.h"
 #include "vp8data.h"
+#include "vpx_rac.h"
 
 #if ARCH_ARM
 #   include "arm/vp8.h"
@@ -54,7 +55,7 @@
 #endif
 
 // fixme: add 1 bit to all the calls to this?
-static int vp8_rac_get_sint(VP56RangeCoder *c, int bits)
+static int vp8_rac_get_sint(VPXRangeCoder *c, int bits)
 {
     int v;
 
@@ -69,19 +70,19 @@ static int vp8_rac_get_sint(VP56RangeCoder *c, int bits)
     return v;
 }
 
-static int vp8_rac_get_nn(VP56RangeCoder *c)
+static int vp8_rac_get_nn(VPXRangeCoder *c)
 {
     int v = vp89_rac_get_uint(c, 7) << 1;
     return v + !v;
 }
 
 // DCTextra
-static int vp8_rac_get_coeff(VP56RangeCoder *c, const uint8_t *prob)
+static int vp8_rac_get_coeff(VPXRangeCoder *c, const uint8_t *prob)
 {
     int v = 0;
 
     do {
-        v = (v<<1) + vp56_rac_get_prob(c, *prob++);
+        v = (v<<1) + vpx_rac_get_prob(c, *prob++);
     } while (*prob);
 
     return v;
@@ -301,7 +302,7 @@ static int vp8_update_dimensions(VP8Context *s, int width, int height)
 
 static void parse_segment_info(VP8Context *s)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     int i;
 
     s->segmentation.update_map = vp89_rac_get(c);
@@ -323,7 +324,7 @@ static void parse_segment_info(VP8Context *s)
 
 static void update_lf_deltas(VP8Context *s)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     int i;
 
     for (i = 0; i < 4; i++) {
@@ -364,7 +365,7 @@ static int setup_partitions(VP8Context *s, const uint8_t *buf, int buf_size)
             return -1;
         s->coeff_partition_size[i] = size;
 
-        ret = ff_vp56_init_range_decoder(&s->coeff_partition[i], buf, size);
+        ret = ff_vpx_init_range_decoder(&s->coeff_partition[i], buf, size);
         if (ret < 0)
             return ret;
         buf      += size;
@@ -372,14 +373,14 @@ static int setup_partitions(VP8Context *s, const uint8_t *buf, int buf_size)
     }
 
     s->coeff_partition_size[i] = buf_size;
-    ff_vp56_init_range_decoder(&s->coeff_partition[i], buf, buf_size);
+    ff_vpx_init_range_decoder(&s->coeff_partition[i], buf, buf_size);
 
     return 0;
 }
 
 static void vp7_get_quants(VP8Context *s)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
 
     int yac_qi  = vp89_rac_get_uint(c, 7);
     int ydc_qi  = vp89_rac_get(c) ? vp89_rac_get_uint(c, 7) : yac_qi;
@@ -398,7 +399,7 @@ static void vp7_get_quants(VP8Context *s)
 
 static void vp8_get_quants(VP8Context *s)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     int i, base_qi;
 
     s->quant.yac_qi     = vp89_rac_get_uint(c, 7);
@@ -444,7 +445,7 @@ static void vp8_get_quants(VP8Context *s)
  */
 static VP56Frame ref_to_update(VP8Context *s, int update, VP56Frame ref)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
 
     if (update)
         return VP56_FRAME_CURRENT;
@@ -469,14 +470,14 @@ static void vp78_reset_probability_tables(VP8Context *s)
 
 static void vp78_update_probability_tables(VP8Context *s)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     int i, j, k, l, m;
 
     for (i = 0; i < 4; i++)
         for (j = 0; j < 8; j++)
             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])) {
+                    if (vpx_rac_get_prob_branchy(c, vp8_token_update_probs[i][j][k][l])) {
                         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;
@@ -489,7 +490,7 @@ static void vp78_update_probability_tables(VP8Context *s)
 static void vp78_update_pred16x16_pred8x8_mvc_probabilities(VP8Context *s,
                                                             int mvc_size)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     int i, j;
 
     if (vp89_rac_get(c))
@@ -502,13 +503,13 @@ static void vp78_update_pred16x16_pred8x8_mvc_probabilities(VP8Context *s,
     // 17.2 MV probability update
     for (i = 0; i < 2; i++)
         for (j = 0; j < mvc_size; j++)
-            if (vp56_rac_get_prob_branchy(c, vp8_mv_update_prob[i][j]))
+            if (vpx_rac_get_prob_branchy(c, vp8_mv_update_prob[i][j]))
                 s->prob->mvc[i][j] = vp8_rac_get_nn(c);
 }
 
 static void update_refs(VP8Context *s)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
 
     int update_golden = vp89_rac_get(c);
     int update_altref = vp89_rac_get(c);
@@ -583,7 +584,7 @@ static int vp7_fade_frame(VP8Context *s, int alpha, int beta)
 
 static int vp7_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_size)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     int part1_size, hscale, vscale, i, j, ret;
     int width  = s->avctx->width;
     int height = s->avctx->height;
@@ -614,7 +615,7 @@ static int vp7_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_si
 
     memcpy(s->put_pixels_tab, s->vp8dsp.put_vp8_epel_pixels_tab, sizeof(s->put_pixels_tab));
 
-    ret = ff_vp56_init_range_decoder(c, buf, part1_size);
+    ret = ff_vpx_init_range_decoder(c, buf, part1_size);
     if (ret < 0)
         return ret;
     buf      += part1_size;
@@ -668,7 +669,7 @@ static int vp7_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_si
     s->lf_delta.enabled        = 0;
 
     s->num_coeff_partitions = 1;
-    ret = ff_vp56_init_range_decoder(&s->coeff_partition[0], buf, buf_size);
+    ret = ff_vpx_init_range_decoder(&s->coeff_partition[0], buf, buf_size);
     if (ret < 0)
         return ret;
 
@@ -701,7 +702,7 @@ static int vp7_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_si
             s->fade_present = vp89_rac_get(c);
     }
 
-    if (vpX_rac_is_end(c))
+    if (vpx_rac_is_end(c))
         return AVERROR_INVALIDDATA;
     /* E. Fading information for previous frame */
     if (s->fade_present && vp89_rac_get(c)) {
@@ -736,7 +737,7 @@ static int vp7_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_si
         vp78_update_pred16x16_pred8x8_mvc_probabilities(s, VP7_MVC_SIZE);
     }
 
-    if (vpX_rac_is_end(c))
+    if (vpx_rac_is_end(c))
         return AVERROR_INVALIDDATA;
 
     if ((ret = vp7_fade_frame(s, alpha, beta)) < 0)
@@ -747,7 +748,7 @@ static int vp7_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_si
 
 static int vp8_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_size)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     int header_size, hscale, vscale, ret;
     int width  = s->avctx->width;
     int height = s->avctx->height;
@@ -809,7 +810,7 @@ static int vp8_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_si
         memset(&s->lf_delta, 0, sizeof(s->lf_delta));
     }
 
-    ret = ff_vp56_init_range_decoder(c, buf, header_size);
+    ret = ff_vpx_init_range_decoder(c, buf, header_size);
     if (ret < 0)
         return ret;
     buf      += header_size;
@@ -876,7 +877,7 @@ static int vp8_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_si
     }
 
     // Record the entropy coder state here so that hwaccels can use it.
-    s->c.code_word = vp56_rac_renorm(&s->c);
+    s->c.code_word = vpx_rac_renorm(&s->c);
     s->coder_state_at_header_end.input     = s->c.buffer - (-s->c.bits / 8);
     s->coder_state_at_header_end.range     = s->c.high;
     s->coder_state_at_header_end.value     = s->c.code_word >> 16;
@@ -897,40 +898,40 @@ void clamp_mv(VP8mvbounds *s, VP56mv *dst, const VP56mv *src)
 /**
  * Motion vector coding, 17.1.
  */
-static av_always_inline int read_mv_component(VP56RangeCoder *c, const uint8_t *p, int vp7)
+static av_always_inline int read_mv_component(VPXRangeCoder *c, const uint8_t *p, int vp7)
 {
     int bit, x = 0;
 
-    if (vp56_rac_get_prob_branchy(c, p[0])) {
+    if (vpx_rac_get_prob_branchy(c, p[0])) {
         int i;
 
         for (i = 0; i < 3; i++)
-            x += vp56_rac_get_prob(c, p[9 + i]) << i;
+            x += vpx_rac_get_prob(c, p[9 + i]) << i;
         for (i = (vp7 ? 7 : 9); i > 3; i--)
-            x += vp56_rac_get_prob(c, p[9 + i]) << i;
-        if (!(x & (vp7 ? 0xF0 : 0xFFF0)) || vp56_rac_get_prob(c, p[12]))
+            x += vpx_rac_get_prob(c, p[9 + i]) << i;
+        if (!(x & (vp7 ? 0xF0 : 0xFFF0)) || vpx_rac_get_prob(c, p[12]))
             x += 8;
     } else {
         // small_mvtree
         const uint8_t *ps = p + 2;
-        bit = vp56_rac_get_prob(c, *ps);
+        bit = vpx_rac_get_prob(c, *ps);
         ps += 1 + 3 * bit;
         x  += 4 * bit;
-        bit = vp56_rac_get_prob(c, *ps);
+        bit = vpx_rac_get_prob(c, *ps);
         ps += 1 + bit;
         x  += 2 * bit;
-        x  += vp56_rac_get_prob(c, *ps);
+        x  += vpx_rac_get_prob(c, *ps);
     }
 
-    return (x && vp56_rac_get_prob(c, p[1])) ? -x : x;
+    return (x && vpx_rac_get_prob(c, p[1])) ? -x : x;
 }
 
-static int vp7_read_mv_component(VP56RangeCoder *c, const uint8_t *p)
+static int vp7_read_mv_component(VPXRangeCoder *c, const uint8_t *p)
 {
     return read_mv_component(c, p, 1);
 }
 
-static int vp8_read_mv_component(VP56RangeCoder *c, const uint8_t *p)
+static int vp8_read_mv_component(VPXRangeCoder *c, const uint8_t *p)
 {
     return read_mv_component(c, p, 0);
 }
@@ -953,7 +954,7 @@ const uint8_t *get_submv_prob(uint32_t left, uint32_t top, int is_vp7)
  * @returns the number of motion vectors parsed (2, 4 or 16)
  */
 static av_always_inline
-int decode_splitmvs(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb,
+int decode_splitmvs(VP8Context *s, VPXRangeCoder *c, VP8Macroblock *mb,
                     int layout, int is_vp7)
 {
     int part_idx;
@@ -973,9 +974,9 @@ int decode_splitmvs(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb,
     mbsplits_top = vp8_mbsplits[top_mb->partitioning];
     top_mv       = top_mb->bmv;
 
-    if (vp56_rac_get_prob_branchy(c, vp8_mbsplit_prob[0])) {
-        if (vp56_rac_get_prob_branchy(c, vp8_mbsplit_prob[1]))
-            part_idx = VP8_SPLITMVMODE_16x8 + vp56_rac_get_prob(c, vp8_mbsplit_prob[2]);
+    if (vpx_rac_get_prob_branchy(c, vp8_mbsplit_prob[0])) {
+        if (vpx_rac_get_prob_branchy(c, vp8_mbsplit_prob[1]))
+            part_idx = VP8_SPLITMVMODE_16x8 + vpx_rac_get_prob(c, vp8_mbsplit_prob[2]);
         else
             part_idx = VP8_SPLITMVMODE_8x8;
     } else {
@@ -1003,9 +1004,9 @@ int decode_splitmvs(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb,
 
         submv_prob = get_submv_prob(left, above, is_vp7);
 
-        if (vp56_rac_get_prob_branchy(c, submv_prob[0])) {
-            if (vp56_rac_get_prob_branchy(c, submv_prob[1])) {
-                if (vp56_rac_get_prob_branchy(c, submv_prob[2])) {
+        if (vpx_rac_get_prob_branchy(c, submv_prob[0])) {
+            if (vpx_rac_get_prob_branchy(c, submv_prob[1])) {
+                if (vpx_rac_get_prob_branchy(c, submv_prob[2])) {
                     mb->bmv[n].y = mb->mv.y +
                                    read_mv_component(c, s->prob->mvc[0], is_vp7);
                     mb->bmv[n].x = mb->mv.x +
@@ -1063,7 +1064,7 @@ void vp7_decode_mvs(VP8Context *s, VP8Macroblock *mb,
     int idx = CNT_ZERO;
     VP56mv near_mv[3];
     uint8_t cnt[3] = { 0 };
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     int i;
 
     AV_ZERO32(&near_mv[0]);
@@ -1109,19 +1110,19 @@ void vp7_decode_mvs(VP8Context *s, VP8Macroblock *mb,
 
     mb->partitioning = VP8_SPLITMVMODE_NONE;
 
-    if (vp56_rac_get_prob_branchy(c, vp7_mode_contexts[cnt[CNT_ZERO]][0])) {
+    if (vpx_rac_get_prob_branchy(c, vp7_mode_contexts[cnt[CNT_ZERO]][0])) {
         mb->mode = VP8_MVMODE_MV;
 
-        if (vp56_rac_get_prob_branchy(c, vp7_mode_contexts[cnt[CNT_NEAREST]][1])) {
+        if (vpx_rac_get_prob_branchy(c, vp7_mode_contexts[cnt[CNT_NEAREST]][1])) {
 
-            if (vp56_rac_get_prob_branchy(c, vp7_mode_contexts[cnt[CNT_NEAR]][2])) {
+            if (vpx_rac_get_prob_branchy(c, vp7_mode_contexts[cnt[CNT_NEAR]][2])) {
 
                 if (cnt[CNT_NEAREST] > cnt[CNT_NEAR])
                     AV_WN32A(&mb->mv, cnt[CNT_ZERO] > cnt[CNT_NEAREST] ? 0 : AV_RN32A(&near_mv[CNT_NEAREST]));
                 else
                     AV_WN32A(&mb->mv, cnt[CNT_ZERO] > cnt[CNT_NEAR]    ? 0 : AV_RN32A(&near_mv[CNT_NEAR]));
 
-                if (vp56_rac_get_prob_branchy(c, vp7_mode_contexts[cnt[CNT_NEAR]][3])) {
+                if (vpx_rac_get_prob_branchy(c, vp7_mode_contexts[cnt[CNT_NEAR]][3])) {
                     mb->mode = VP8_MVMODE_SPLIT;
                     mb->mv = mb->bmv[decode_splitmvs(s, c, mb, layout, IS_VP7) - 1];
                 } else {
@@ -1158,7 +1159,7 @@ void vp8_decode_mvs(VP8Context *s, VP8mvbounds *mv_bounds, VP8Macroblock *mb,
     int8_t *sign_bias = s->sign_bias;
     VP56mv near_mv[4];
     uint8_t cnt[4] = { 0 };
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
 
     if (!layout) { // layout is inlined (s->mb_layout is not)
         mb_edge[0] = mb + 2;
@@ -1199,7 +1200,7 @@ void vp8_decode_mvs(VP8Context *s, VP8mvbounds *mv_bounds, VP8Macroblock *mb,
     MV_EDGE_CHECK(2)
 
     mb->partitioning = VP8_SPLITMVMODE_NONE;
-    if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_ZERO]][0])) {
+    if (vpx_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_ZERO]][0])) {
         mb->mode = VP8_MVMODE_MV;
 
         /* If we have three distinct MVs, merge first and last if they're the same */
@@ -1213,15 +1214,15 @@ void vp8_decode_mvs(VP8Context *s, VP8mvbounds *mv_bounds, VP8Macroblock *mb,
             FFSWAP( VP56mv, near_mv[CNT_NEAREST], near_mv[CNT_NEAR]);
         }
 
-        if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_NEAREST]][1])) {
-            if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_NEAR]][2])) {
+        if (vpx_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_NEAREST]][1])) {
+            if (vpx_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_NEAR]][2])) {
                 /* Choose the best mv out of 0,0 and the nearest mv */
                 clamp_mv(mv_bounds, &mb->mv, &near_mv[CNT_ZERO + (cnt[CNT_NEAREST] >= cnt[CNT_ZERO])]);
                 cnt[CNT_SPLITMV] = ((mb_edge[VP8_EDGE_LEFT]->mode    == VP8_MVMODE_SPLIT) +
                                     (mb_edge[VP8_EDGE_TOP]->mode     == VP8_MVMODE_SPLIT)) * 2 +
                                     (mb_edge[VP8_EDGE_TOPLEFT]->mode == VP8_MVMODE_SPLIT);
 
-                if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_SPLITMV]][3])) {
+                if (vpx_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_SPLITMV]][3])) {
                     mb->mode = VP8_MVMODE_SPLIT;
                     mb->mv = mb->bmv[decode_splitmvs(s, c, mb, layout, IS_VP8) - 1];
                 } else {
@@ -1245,7 +1246,7 @@ void vp8_decode_mvs(VP8Context *s, VP8mvbounds *mv_bounds, VP8Macroblock *mb,
 }
 
 static av_always_inline
-void decode_intra4x4_modes(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb,
+void decode_intra4x4_modes(VP8Context *s, VPXRangeCoder *c, VP8Macroblock *mb,
                            int mb_x, int keyframe, int layout)
 {
     uint8_t *intra4x4 = mb->intra4x4_pred_mode_mb;
@@ -1284,7 +1285,7 @@ void decode_mb_mode(VP8Context *s, VP8mvbounds *mv_bounds,
                     VP8Macroblock *mb, int mb_x, int mb_y,
                     uint8_t *segment, uint8_t *ref, int layout, int is_vp7)
 {
-    VP56RangeCoder *c = &s->c;
+    VPXRangeCoder *c = &s->c;
     static const char * const vp7_feature_name[] = { "q-index",
                                                      "lf-delta",
                                                      "partial-golden-update",
@@ -1294,7 +1295,7 @@ void decode_mb_mode(VP8Context *s, VP8mvbounds *mv_bounds,
         *segment = 0;
         for (i = 0; i < 4; i++) {
             if (s->feature_enabled[i]) {
-                if (vp56_rac_get_prob_branchy(c, s->feature_present_prob[i])) {
+                if (vpx_rac_get_prob_branchy(c, s->feature_present_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,
@@ -1304,13 +1305,13 @@ void decode_mb_mode(VP8Context *s, VP8mvbounds *mv_bounds,
            }
         }
     } else if (s->segmentation.update_map) {
-        int bit  = vp56_rac_get_prob(c, s->prob->segmentid[0]);
-        *segment = vp56_rac_get_prob(c, s->prob->segmentid[1+bit]) + 2*bit;
+        int bit  = vpx_rac_get_prob(c, s->prob->segmentid[0]);
+        *segment = vpx_rac_get_prob(c, s->prob->segmentid[1+bit]) + 2*bit;
     } else if (s->segmentation.enabled)
         *segment = ref ? *ref : *segment;
     mb->segment = *segment;
 
-    mb->skip = s->mbskip_enabled ? vp56_rac_get_prob(c, s->prob->mbskip) : 0;
+    mb->skip = s->mbskip_enabled ? vpx_rac_get_prob(c, s->prob->mbskip) : 0;
 
     if (s->keyframe) {
         mb->mode = vp89_rac_get_tree(c, vp8_pred16x16_tree_intra,
@@ -1331,11 +1332,11 @@ void decode_mb_mode(VP8Context *s, VP8mvbounds *mv_bounds,
         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)) {
+    } else if (vpx_rac_get_prob_branchy(c, s->prob->intra)) {
         // inter MB, 16.2
-        if (vp56_rac_get_prob_branchy(c, s->prob->last))
+        if (vpx_rac_get_prob_branchy(c, s->prob->last))
             mb->ref_frame =
-                (!is_vp7 && vp56_rac_get_prob(c, s->prob->golden)) ? VP56_FRAME_GOLDEN2 /* altref */
+                (!is_vp7 && vpx_rac_get_prob(c, s->prob->golden)) ? VP56_FRAME_GOLDEN2 /* altref */
                                                                    : VP56_FRAME_GOLDEN;
         else
             mb->ref_frame = VP56_FRAME_PREVIOUS;
@@ -1373,21 +1374,21 @@ void decode_mb_mode(VP8Context *s, VP8mvbounds *mv_bounds,
  *         otherwise, the index of the last coeff decoded plus one
  */
 static av_always_inline
-int decode_block_coeffs_internal(VP56RangeCoder *r, int16_t block[16],
+int decode_block_coeffs_internal(VPXRangeCoder *r, int16_t block[16],
                                  uint8_t probs[16][3][NUM_DCT_TOKENS - 1],
                                  int i, uint8_t *token_prob, int16_t qmul[2],
                                  const uint8_t scan[16], int vp7)
 {
-    VP56RangeCoder c = *r;
+    VPXRangeCoder c = *r;
     goto skip_eob;
     do {
         int coeff;
 restart:
-        if (!vp56_rac_get_prob_branchy(&c, token_prob[0]))   // DCT_EOB
+        if (!vpx_rac_get_prob_branchy(&c, token_prob[0]))   // DCT_EOB
             break;
 
 skip_eob:
-        if (!vp56_rac_get_prob_branchy(&c, token_prob[1])) { // DCT_0
+        if (!vpx_rac_get_prob_branchy(&c, token_prob[1])) { // DCT_0
             if (++i == 16)
                 break; // invalid input; blocks should end with EOB
             token_prob = probs[i][0];
@@ -1396,28 +1397,28 @@ skip_eob:
             goto skip_eob;
         }
 
-        if (!vp56_rac_get_prob_branchy(&c, token_prob[2])) { // DCT_1
+        if (!vpx_rac_get_prob_branchy(&c, token_prob[2])) { // DCT_1
             coeff = 1;
             token_prob = probs[i + 1][1];
         } else {
-            if (!vp56_rac_get_prob_branchy(&c, token_prob[3])) { // DCT 2,3,4
-                coeff = vp56_rac_get_prob_branchy(&c, token_prob[4]);
+            if (!vpx_rac_get_prob_branchy(&c, token_prob[3])) { // DCT 2,3,4
+                coeff = vpx_rac_get_prob_branchy(&c, token_prob[4]);
                 if (coeff)
-                    coeff += vp56_rac_get_prob(&c, token_prob[5]);
+                    coeff += vpx_rac_get_prob(&c, token_prob[5]);
                 coeff += 2;
             } else {
                 // DCT_CAT*
-                if (!vp56_rac_get_prob_branchy(&c, token_prob[6])) {
-                    if (!vp56_rac_get_prob_branchy(&c, token_prob[7])) { // DCT_CAT1
-                        coeff = 5 + vp56_rac_get_prob(&c, vp8_dct_cat1_prob[0]);
+                if (!vpx_rac_get_prob_branchy(&c, token_prob[6])) {
+                    if (!vpx_rac_get_prob_branchy(&c, token_prob[7])) { // DCT_CAT1
+                        coeff = 5 + vpx_rac_get_prob(&c, vp8_dct_cat1_prob[0]);
                     } else {                                    // DCT_CAT2
                         coeff  = 7;
-                        coeff += vp56_rac_get_prob(&c, vp8_dct_cat2_prob[0]) << 1;
-                        coeff += vp56_rac_get_prob(&c, vp8_dct_cat2_prob[1]);
+                        coeff += vpx_rac_get_prob(&c, vp8_dct_cat2_prob[0]) << 1;
+                        coeff += vpx_rac_get_prob(&c, vp8_dct_cat2_prob[1]);
                     }
                 } else {    // DCT_CAT3 and up
-                    int a   = vp56_rac_get_prob(&c, token_prob[8]);
-                    int b   = vp56_rac_get_prob(&c, token_prob[9 + a]);
+                    int a   = vpx_rac_get_prob(&c, token_prob[8]);
+                    int b   = vpx_rac_get_prob(&c, token_prob[9 + a]);
                     int cat = (a << 1) + b;
                     coeff  = 3 + (8 << cat);
                     coeff += vp8_rac_get_coeff(&c, ff_vp8_dct_cat_prob[cat]);
@@ -1455,7 +1456,7 @@ int inter_predict_dc(int16_t block[16], int16_t pred[2])
     return ret;
 }
 
-static int vp7_decode_block_coeffs_internal(VP56RangeCoder *r,
+static int vp7_decode_block_coeffs_internal(VPXRangeCoder *r,
                                             int16_t block[16],
                                             uint8_t probs[16][3][NUM_DCT_TOKENS - 1],
                                             int i, uint8_t *token_prob,
@@ -1467,7 +1468,7 @@ static int vp7_decode_block_coeffs_internal(VP56RangeCoder *r,
 }
 
 #ifndef vp8_decode_block_coeffs_internal
-static int vp8_decode_block_coeffs_internal(VP56RangeCoder *r,
+static int vp8_decode_block_coeffs_internal(VPXRangeCoder *r,
                                             int16_t block[16],
                                             uint8_t probs[16][3][NUM_DCT_TOKENS - 1],
                                             int i, uint8_t *token_prob,
@@ -1492,13 +1493,13 @@ static int vp8_decode_block_coeffs_internal(VP56RangeCoder *r,
  *         otherwise, the index of the last coeff decoded plus one
  */
 static av_always_inline
-int decode_block_coeffs(VP56RangeCoder *c, int16_t block[16],
+int decode_block_coeffs(VPXRangeCoder *c, int16_t block[16],
                         uint8_t probs[16][3][NUM_DCT_TOKENS - 1],
                         int i, int zero_nhood, int16_t qmul[2],
                         const uint8_t scan[16], int vp7)
 {
     uint8_t *token_prob = probs[i][zero_nhood];
-    if (!vp56_rac_get_prob_branchy(c, token_prob[0]))   // DCT_EOB
+    if (!vpx_rac_get_prob_branchy(c, token_prob[0]))   // DCT_EOB
         return 0;
     return vp7 ? vp7_decode_block_coeffs_internal(c, block, probs, i,
                                                   token_prob, qmul, scan)
@@ -1507,7 +1508,7 @@ int decode_block_coeffs(VP56RangeCoder *c, int16_t block[16],
 }
 
 static av_always_inline
-void decode_mb_coeffs(VP8Context *s, VP8ThreadData *td, VP56RangeCoder *c,
+void decode_mb_coeffs(VP8Context *s, VP8ThreadData *td, VPXRangeCoder *c,
                       VP8Macroblock *mb, uint8_t t_nnz[9], uint8_t l_nnz[9],
                       int is_vp7)
 {
@@ -2334,7 +2335,7 @@ int vp78_decode_mv_mb_modes(AVCodecContext *avctx, VP8Frame *curframe,
         s->mv_bounds.mv_max.x = ((s->mb_width - 1) << 6) + MARGIN;
 
         for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb_xy++, mb++) {
-            if (vpX_rac_is_end(&s->c)) {
+            if (vpx_rac_is_end(&s->c)) {
                 return AVERROR_INVALIDDATA;
             }
             if (mb_y == 0)
@@ -2411,7 +2412,7 @@ static av_always_inline int decode_mb_row_no_filter(AVCodecContext *avctx, void
     int mb_x, mb_xy = mb_y * s->mb_width;
     int num_jobs = s->num_jobs;
     VP8Frame *curframe = s->curframe, *prev_frame = s->prev_frame;
-    VP56RangeCoder *c  = &s->coeff_partition[mb_y & (s->num_coeff_partitions - 1)];
+    VPXRangeCoder *c  = &s->coeff_partition[mb_y & (s->num_coeff_partitions - 1)];
     VP8Macroblock *mb;
     uint8_t *dst[3] = {
         curframe->tf.f->data[0] + 16 * mb_y * s->linesize,
@@ -2419,7 +2420,7 @@ static av_always_inline int decode_mb_row_no_filter(AVCodecContext *avctx, void
         curframe->tf.f->data[2] +  8 * mb_y * s->uvlinesize
     };
 
-    if (vpX_rac_is_end(c))
+    if (vpx_rac_is_end(c))
          return AVERROR_INVALIDDATA;
 
     if (mb_y == 0)
@@ -2450,7 +2451,7 @@ static av_always_inline int decode_mb_row_no_filter(AVCodecContext *avctx, void
     td->mv_bounds.mv_max.x = ((s->mb_width - 1) << 6) + MARGIN;
 
     for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb_xy++, mb++) {
-        if (vpX_rac_is_end(c))
+        if (vpx_rac_is_end(c))
             return AVERROR_INVALIDDATA;
         // Wait for previous thread to read mb_x+2, and reach mb_y-1.
         if (prev_td != td) {
diff --git a/libavcodec/vp8.h b/libavcodec/vp8.h
index 8fe45573ed..9695111806 100644
--- a/libavcodec/vp8.h
+++ b/libavcodec/vp8.h
@@ -36,6 +36,7 @@
 #include "threadframe.h"
 #include "vp56.h"
 #include "vp8dsp.h"
+#include "vpx_rac.h"
 
 #define VP8_MAX_QUANT 127
 
@@ -245,7 +246,7 @@ typedef struct VP8Context {
     uint8_t (*top_border)[16 + 8 + 8];
     uint8_t (*top_nnz)[9];
 
-    VP56RangeCoder c;   ///< header context, includes mb modes and motion vectors
+    VPXRangeCoder c;   ///< header context, includes mb modes and motion vectors
 
     /* This contains the entropy coder state at the end of the header
      * block, in the form specified by the standard.  For use by
@@ -297,7 +298,7 @@ typedef struct VP8Context {
      * There can be 1, 2, 4, or 8 of these after the header context.
      */
     int num_coeff_partitions;
-    VP56RangeCoder coeff_partition[8];
+    VPXRangeCoder coeff_partition[8];
     int coeff_partition_size[8];
     VideoDSPContext vdsp;
     VP8DSPContext vp8dsp;
diff --git a/libavcodec/vp89_rac.h b/libavcodec/vp89_rac.h
index 382c8ee64d..bc0924c387 100644
--- a/libavcodec/vp89_rac.h
+++ b/libavcodec/vp89_rac.h
@@ -30,15 +30,15 @@
 
 #include "libavutil/attributes.h"
 
-#include "vp56.h"
+#include "vpx_rac.h"
 
-// rounding is different than vp56_rac_get, is vp56_rac_get wrong?
-static av_always_inline int vp89_rac_get(VP56RangeCoder *c)
+// rounding is different than vpx_rac_get, is vpx_rac_get wrong?
+static av_always_inline int vp89_rac_get(VPXRangeCoder *c)
 {
-    return vp56_rac_get_prob(c, 128);
+    return vpx_rac_get_prob(c, 128);
 }
 
-static av_unused int vp89_rac_get_uint(VP56RangeCoder *c, int bits)
+static av_unused int vp89_rac_get_uint(VPXRangeCoder *c, int bits)
 {
     int value = 0;
 
@@ -51,13 +51,13 @@ static av_unused int vp89_rac_get_uint(VP56RangeCoder *c, int bits)
 
 // 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],
+static av_always_inline int vp89_rac_get_tree(VPXRangeCoder *c, const int8_t (*tree)[2],
                                               const uint8_t *probs)
 {
     int i = 0;
 
     do {
-        i = tree[i][vp56_rac_get_prob(c, probs[i])];
+        i = tree[i][vpx_rac_get_prob(c, probs[i])];
     } while (i > 0);
 
     return -i;
diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 57ad8623a8..1eeb460fc0 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -39,6 +39,7 @@
 #include "vp9.h"
 #include "vp9data.h"
 #include "vp9dec.h"
+#include "vpx_rac.h"
 #include "libavutil/avassert.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/video_enc_params.h"
@@ -380,7 +381,7 @@ static av_always_inline int inv_recenter_nonneg(int v, int m)
 }
 
 // differential forward probability updates
-static int update_prob(VP56RangeCoder *c, int p)
+static int update_prob(VPXRangeCoder *c, int p)
 {
     static const uint8_t inv_map_table[255] = {
           7,  20,  33,  46,  59,  72,  85,  98, 111, 124, 137, 150, 163, 176,
@@ -785,7 +786,7 @@ static int decode_frame_header(AVCodecContext *avctx,
     s->s.h.tiling.tile_rows = 1 << s->s.h.tiling.log2_tile_rows;
     if (s->s.h.tiling.tile_cols != (1 << s->s.h.tiling.log2_tile_cols)) {
         int n_range_coders;
-        VP56RangeCoder *rc;
+        VPXRangeCoder *rc;
 
         if (s->td) {
             for (i = 0; i < s->active_tile_cols; i++)
@@ -803,10 +804,10 @@ static int decode_frame_header(AVCodecContext *avctx,
             n_range_coders = s->s.h.tiling.tile_cols;
         }
         s->td = av_calloc(s->active_tile_cols, sizeof(VP9TileData) +
-                                 n_range_coders * sizeof(VP56RangeCoder));
+                                 n_range_coders * sizeof(VPXRangeCoder));
         if (!s->td)
             return AVERROR(ENOMEM);
-        rc = (VP56RangeCoder *) &s->td[s->active_tile_cols];
+        rc = (VPXRangeCoder *) &s->td[s->active_tile_cols];
         for (i = 0; i < s->active_tile_cols; i++) {
             s->td[i].s = s;
             s->td[i].c_b = rc;
@@ -878,11 +879,11 @@ static int decode_frame_header(AVCodecContext *avctx,
         av_log(avctx, AV_LOG_ERROR, "Invalid compressed header size\n");
         return AVERROR_INVALIDDATA;
     }
-    ret = ff_vp56_init_range_decoder(&s->c, data2, size2);
+    ret = ff_vpx_init_range_decoder(&s->c, data2, size2);
     if (ret < 0)
         return ret;
 
-    if (vp56_rac_get_prob_branchy(&s->c, 128)) { // marker bit
+    if (vpx_rac_get_prob_branchy(&s->c, 128)) { // marker bit
         av_log(avctx, AV_LOG_ERROR, "Marker bit was set\n");
         return AVERROR_INVALIDDATA;
     }
@@ -912,16 +913,16 @@ static int decode_frame_header(AVCodecContext *avctx,
 
         if (s->s.h.txfmmode == TX_SWITCHABLE) {
             for (i = 0; i < 2; i++)
-                if (vp56_rac_get_prob_branchy(&s->c, 252))
+                if (vpx_rac_get_prob_branchy(&s->c, 252))
                     s->prob.p.tx8p[i] = update_prob(&s->c, s->prob.p.tx8p[i]);
             for (i = 0; i < 2; i++)
                 for (j = 0; j < 2; j++)
-                    if (vp56_rac_get_prob_branchy(&s->c, 252))
+                    if (vpx_rac_get_prob_branchy(&s->c, 252))
                         s->prob.p.tx16p[i][j] =
                             update_prob(&s->c, s->prob.p.tx16p[i][j]);
             for (i = 0; i < 2; i++)
                 for (j = 0; j < 3; j++)
-                    if (vp56_rac_get_prob_branchy(&s->c, 252))
+                    if (vpx_rac_get_prob_branchy(&s->c, 252))
                         s->prob.p.tx32p[i][j] =
                             update_prob(&s->c, s->prob.p.tx32p[i][j]);
         }
@@ -940,7 +941,7 @@ static int decode_frame_header(AVCodecContext *avctx,
                             if (m >= 3 && l == 0) // dc only has 3 pt
                                 break;
                             for (n = 0; n < 3; n++) {
-                                if (vp56_rac_get_prob_branchy(&s->c, 252))
+                                if (vpx_rac_get_prob_branchy(&s->c, 252))
                                     p[n] = update_prob(&s->c, r[n]);
                                 else
                                     p[n] = r[n];
@@ -966,24 +967,24 @@ static int decode_frame_header(AVCodecContext *avctx,
 
     // mode updates
     for (i = 0; i < 3; i++)
-        if (vp56_rac_get_prob_branchy(&s->c, 252))
+        if (vpx_rac_get_prob_branchy(&s->c, 252))
             s->prob.p.skip[i] = update_prob(&s->c, s->prob.p.skip[i]);
     if (!s->s.h.keyframe && !s->s.h.intraonly) {
         for (i = 0; i < 7; i++)
             for (j = 0; j < 3; j++)
-                if (vp56_rac_get_prob_branchy(&s->c, 252))
+                if (vpx_rac_get_prob_branchy(&s->c, 252))
                     s->prob.p.mv_mode[i][j] =
                         update_prob(&s->c, s->prob.p.mv_mode[i][j]);
 
         if (s->s.h.filtermode == FILTER_SWITCHABLE)
             for (i = 0; i < 4; i++)
                 for (j = 0; j < 2; j++)
-                    if (vp56_rac_get_prob_branchy(&s->c, 252))
+                    if (vpx_rac_get_prob_branchy(&s->c, 252))
                         s->prob.p.filter[i][j] =
                             update_prob(&s->c, s->prob.p.filter[i][j]);
 
         for (i = 0; i < 4; i++)
-            if (vp56_rac_get_prob_branchy(&s->c, 252))
+            if (vpx_rac_get_prob_branchy(&s->c, 252))
                 s->prob.p.intra[i] = update_prob(&s->c, s->prob.p.intra[i]);
 
         if (s->s.h.allowcompinter) {
@@ -992,7 +993,7 @@ static int decode_frame_header(AVCodecContext *avctx,
                 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))
+                    if (vpx_rac_get_prob_branchy(&s->c, 252))
                         s->prob.p.comp[i] =
                             update_prob(&s->c, s->prob.p.comp[i]);
         } else {
@@ -1001,10 +1002,10 @@ static int decode_frame_header(AVCodecContext *avctx,
 
         if (s->s.h.comppredmode != PRED_COMPREF) {
             for (i = 0; i < 5; i++) {
-                if (vp56_rac_get_prob_branchy(&s->c, 252))
+                if (vpx_rac_get_prob_branchy(&s->c, 252))
                     s->prob.p.single_ref[i][0] =
                         update_prob(&s->c, s->prob.p.single_ref[i][0]);
-                if (vp56_rac_get_prob_branchy(&s->c, 252))
+                if (vpx_rac_get_prob_branchy(&s->c, 252))
                     s->prob.p.single_ref[i][1] =
                         update_prob(&s->c, s->prob.p.single_ref[i][1]);
             }
@@ -1012,46 +1013,46 @@ static int decode_frame_header(AVCodecContext *avctx,
 
         if (s->s.h.comppredmode != PRED_SINGLEREF) {
             for (i = 0; i < 5; i++)
-                if (vp56_rac_get_prob_branchy(&s->c, 252))
+                if (vpx_rac_get_prob_branchy(&s->c, 252))
                     s->prob.p.comp_ref[i] =
                         update_prob(&s->c, s->prob.p.comp_ref[i]);
         }
 
         for (i = 0; i < 4; i++)
             for (j = 0; j < 9; j++)
-                if (vp56_rac_get_prob_branchy(&s->c, 252))
+                if (vpx_rac_get_prob_branchy(&s->c, 252))
                     s->prob.p.y_mode[i][j] =
                         update_prob(&s->c, s->prob.p.y_mode[i][j]);
 
         for (i = 0; i < 4; i++)
             for (j = 0; j < 4; j++)
                 for (k = 0; k < 3; k++)
-                    if (vp56_rac_get_prob_branchy(&s->c, 252))
+                    if (vpx_rac_get_prob_branchy(&s->c, 252))
                         s->prob.p.partition[3 - i][j][k] =
                             update_prob(&s->c,
                                         s->prob.p.partition[3 - i][j][k]);
 
         // 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))
+            if (vpx_rac_get_prob_branchy(&s->c, 252))
                 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))
+            if (vpx_rac_get_prob_branchy(&s->c, 252))
                 s->prob.p.mv_comp[i].sign =
                     (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
 
             for (j = 0; j < 10; j++)
-                if (vp56_rac_get_prob_branchy(&s->c, 252))
+                if (vpx_rac_get_prob_branchy(&s->c, 252))
                     s->prob.p.mv_comp[i].classes[j] =
                         (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
 
-            if (vp56_rac_get_prob_branchy(&s->c, 252))
+            if (vpx_rac_get_prob_branchy(&s->c, 252))
                 s->prob.p.mv_comp[i].class0 =
                     (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
 
             for (j = 0; j < 10; j++)
-                if (vp56_rac_get_prob_branchy(&s->c, 252))
+                if (vpx_rac_get_prob_branchy(&s->c, 252))
                     s->prob.p.mv_comp[i].bits[j] =
                         (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
         }
@@ -1059,23 +1060,23 @@ static int decode_frame_header(AVCodecContext *avctx,
         for (i = 0; i < 2; i++) {
             for (j = 0; j < 2; j++)
                 for (k = 0; k < 3; k++)
-                    if (vp56_rac_get_prob_branchy(&s->c, 252))
+                    if (vpx_rac_get_prob_branchy(&s->c, 252))
                         s->prob.p.mv_comp[i].class0_fp[j][k] =
                             (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
 
             for (j = 0; j < 3; j++)
-                if (vp56_rac_get_prob_branchy(&s->c, 252))
+                if (vpx_rac_get_prob_branchy(&s->c, 252))
                     s->prob.p.mv_comp[i].fp[j] =
                         (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))
+                if (vpx_rac_get_prob_branchy(&s->c, 252))
                     s->prob.p.mv_comp[i].class0_hp =
                         (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
 
-                if (vp56_rac_get_prob_branchy(&s->c, 252))
+                if (vpx_rac_get_prob_branchy(&s->c, 252))
                     s->prob.p.mv_comp[i].hp =
                         (vp89_rac_get_uint(&s->c, 7) << 1) | 1;
             }
@@ -1136,7 +1137,7 @@ static void decode_sb(VP9TileData *td, int row, int col, VP9Filter *lflvl,
             default:
                 av_assert0(0);
             }
-        } else if (vp56_rac_get_prob_branchy(td->c, p[1])) {
+        } else if (vpx_rac_get_prob_branchy(td->c, p[1])) {
             bp = PARTITION_SPLIT;
             decode_sb(td, row, col, lflvl, yoff, uvoff, bl + 1);
             decode_sb(td, row, col + hbs, lflvl,
@@ -1147,7 +1148,7 @@ static void decode_sb(VP9TileData *td, int row, int col, VP9Filter *lflvl,
             ff_vp9_decode_block(td, row, col, lflvl, yoff, uvoff, bl, bp);
         }
     } else if (row + hbs < s->rows) { // FIXME why not <=?
-        if (vp56_rac_get_prob_branchy(td->c, p[2])) {
+        if (vpx_rac_get_prob_branchy(td->c, p[2])) {
             bp = PARTITION_SPLIT;
             decode_sb(td, row, col, lflvl, yoff, uvoff, bl + 1);
             yoff  += hbs * 8 * y_stride;
@@ -1292,10 +1293,10 @@ static int decode_tiles(AVCodecContext *avctx,
                 ff_thread_report_progress(&s->s.frames[CUR_FRAME].tf, INT_MAX, 0);
                 return AVERROR_INVALIDDATA;
             }
-            ret = ff_vp56_init_range_decoder(&td->c_b[tile_col], data, tile_size);
+            ret = ff_vpx_init_range_decoder(&td->c_b[tile_col], data, tile_size);
             if (ret < 0)
                 return ret;
-            if (vp56_rac_get_prob_branchy(&td->c_b[tile_col], 128)) { // marker bit
+            if (vpx_rac_get_prob_branchy(&td->c_b[tile_col], 128)) { // marker bit
                 ff_thread_report_progress(&s->s.frames[CUR_FRAME].tf, INT_MAX, 0);
                 return AVERROR_INVALIDDATA;
             }
@@ -1341,7 +1342,7 @@ static int decode_tiles(AVCodecContext *avctx,
                         decode_sb_mem(td, row, col, lflvl_ptr,
                                       yoff2, uvoff2, BL_64X64);
                     } else {
-                        if (vpX_rac_is_end(td->c)) {
+                        if (vpx_rac_is_end(td->c)) {
                             return AVERROR_INVALIDDATA;
                         }
                         decode_sb(td, row, col, lflvl_ptr,
@@ -1715,10 +1716,10 @@ static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame,
                     }
                     if (tile_size > size)
                         return AVERROR_INVALIDDATA;
-                    ret = ff_vp56_init_range_decoder(&s->td[tile_col].c_b[tile_row], data, tile_size);
+                    ret = ff_vpx_init_range_decoder(&s->td[tile_col].c_b[tile_row], data, tile_size);
                     if (ret < 0)
                         return ret;
-                    if (vp56_rac_get_prob_branchy(&s->td[tile_col].c_b[tile_row], 128)) // marker bit
+                    if (vpx_rac_get_prob_branchy(&s->td[tile_col].c_b[tile_row], 128)) // marker bit
                         return AVERROR_INVALIDDATA;
                     data += tile_size;
                     size -= tile_size;
diff --git a/libavcodec/vp9block.c b/libavcodec/vp9block.c
index f5088e3b59..baa343fddc 100644
--- a/libavcodec/vp9block.c
+++ b/libavcodec/vp9block.c
@@ -29,6 +29,7 @@
 #include "vp9.h"
 #include "vp9data.h"
 #include "vp9dec.h"
+#include "vpx_rac.h"
 
 static av_always_inline void setctx_2d(uint8_t *ptr, int w, int h,
                                        ptrdiff_t stride, int v)
@@ -105,7 +106,7 @@ static void decode_mode(VP9TileData *td)
                                       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,
+                vpx_rac_get_prob_branchy(td->c,
                     s->s.h.segmentation.pred_prob[s->above_segpred_ctx[col] +
                                     td->left_segpred_ctx[row7]]))) {
         if (!s->s.h.errorres && s->s.frames[REF_FRAME_SEGMAP].segmentation_map) {
@@ -144,7 +145,7 @@ static void decode_mode(VP9TileData *td)
         s->s.h.segmentation.feat[b->seg_id].skip_enabled;
     if (!b->skip) {
         int c = td->left_skip_ctx[row7] + s->above_skip_ctx[col];
-        b->skip = vp56_rac_get_prob(td->c, s->prob.p.skip[c]);
+        b->skip = vpx_rac_get_prob(td->c, s->prob.p.skip[c]);
         td->counts.skip[c][b->skip]++;
     }
 
@@ -162,7 +163,7 @@ static void decode_mode(VP9TileData *td)
             c = have_a ? 2 * s->above_intra_ctx[col] :
                 have_l ? 2 * td->left_intra_ctx[row7] : 0;
         }
-        bit = vp56_rac_get_prob(td->c, s->prob.p.intra[c]);
+        bit = vpx_rac_get_prob(td->c, s->prob.p.intra[c]);
         td->counts.intra[c][bit]++;
         b->intra = !bit;
     }
@@ -187,22 +188,22 @@ static void decode_mode(VP9TileData *td)
         }
         switch (max_tx) {
         case TX_32X32:
-            b->tx = vp56_rac_get_prob(td->c, s->prob.p.tx32p[c][0]);
+            b->tx = vpx_rac_get_prob(td->c, s->prob.p.tx32p[c][0]);
             if (b->tx) {
-                b->tx += vp56_rac_get_prob(td->c, s->prob.p.tx32p[c][1]);
+                b->tx += vpx_rac_get_prob(td->c, s->prob.p.tx32p[c][1]);
                 if (b->tx == 2)
-                    b->tx += vp56_rac_get_prob(td->c, s->prob.p.tx32p[c][2]);
+                    b->tx += vpx_rac_get_prob(td->c, s->prob.p.tx32p[c][2]);
             }
             td->counts.tx32p[c][b->tx]++;
             break;
         case TX_16X16:
-            b->tx = vp56_rac_get_prob(td->c, s->prob.p.tx16p[c][0]);
+            b->tx = vpx_rac_get_prob(td->c, s->prob.p.tx16p[c][0]);
             if (b->tx)
-                b->tx += vp56_rac_get_prob(td->c, s->prob.p.tx16p[c][1]);
+                b->tx += vpx_rac_get_prob(td->c, s->prob.p.tx16p[c][1]);
             td->counts.tx16p[c][b->tx]++;
             break;
         case TX_8X8:
-            b->tx = vp56_rac_get_prob(td->c, s->prob.p.tx8p[c]);
+            b->tx = vpx_rac_get_prob(td->c, s->prob.p.tx8p[c]);
             td->counts.tx8p[c][b->tx]++;
             break;
         case TX_4X4:
@@ -367,7 +368,7 @@ static void decode_mode(VP9TileData *td)
                 } else {
                     c = 1;
                 }
-                b->comp = vp56_rac_get_prob(td->c, s->prob.p.comp[c]);
+                b->comp = vpx_rac_get_prob(td->c, s->prob.p.comp[c]);
                 td->counts.comp[c][b->comp]++;
             }
 
@@ -439,7 +440,7 @@ static void decode_mode(VP9TileData *td)
                 } else {
                     c = 2;
                 }
-                bit = vp56_rac_get_prob(td->c, s->prob.p.comp_ref[c]);
+                bit = vpx_rac_get_prob(td->c, s->prob.p.comp_ref[c]);
                 b->ref[var_idx] = s->s.h.varcompref[bit];
                 td->counts.comp_ref[c][bit]++;
             } else /* single reference */ {
@@ -479,7 +480,7 @@ static void decode_mode(VP9TileData *td)
                 } else {
                     c = 2;
                 }
-                bit = vp56_rac_get_prob(td->c, s->prob.p.single_ref[c][0]);
+                bit = vpx_rac_get_prob(td->c, s->prob.p.single_ref[c][0]);
                 td->counts.single_ref[c][0][bit]++;
                 if (!bit) {
                     b->ref[0] = 0;
@@ -566,7 +567,7 @@ static void decode_mode(VP9TileData *td)
                     } else {
                         c = 2;
                     }
-                    bit = vp56_rac_get_prob(td->c, s->prob.p.single_ref[c][1]);
+                    bit = vpx_rac_get_prob(td->c, s->prob.p.single_ref[c][1]);
                     td->counts.single_ref[c][1][bit]++;
                     b->ref[0] = 1 + bit;
                 }
@@ -802,7 +803,7 @@ static void decode_mode(VP9TileData *td)
 
 // FIXME merge cnt/eob arguments?
 static av_always_inline int
-decode_coeffs_b_generic(VP56RangeCoder *c, int16_t *coef, int n_coeffs,
+decode_coeffs_b_generic(VPXRangeCoder *c, int16_t *coef, int n_coeffs,
                         int is_tx32x32, int is8bitsperpixel, int bpp, unsigned (*cnt)[6][3],
                         unsigned (*eob)[6][2], uint8_t (*p)[6][11],
                         int nnz, const int16_t *scan, const int16_t (*nb)[2],
@@ -815,13 +816,13 @@ decode_coeffs_b_generic(VP56RangeCoder *c, int16_t *coef, int n_coeffs,
     do {
         int val, rc;
 
-        val = vp56_rac_get_prob_branchy(c, tp[0]); // eob
+        val = vpx_rac_get_prob_branchy(c, tp[0]); // eob
         eob[band][nnz][val]++;
         if (!val)
             break;
 
 skip_eob:
-        if (!vp56_rac_get_prob_branchy(c, tp[1])) { // zero
+        if (!vpx_rac_get_prob_branchy(c, tp[1])) { // zero
             cnt[band][nnz][0]++;
             if (!--band_left)
                 band_left = band_counts[++band];
@@ -834,70 +835,70 @@ skip_eob:
         }
 
         rc = scan[i];
-        if (!vp56_rac_get_prob_branchy(c, tp[2])) { // one
+        if (!vpx_rac_get_prob_branchy(c, tp[2])) { // one
             cnt[band][nnz][1]++;
             val       = 1;
             cache[rc] = 1;
         } else {
             cnt[band][nnz][2]++;
-            if (!vp56_rac_get_prob_branchy(c, tp[3])) { // 2, 3, 4
-                if (!vp56_rac_get_prob_branchy(c, tp[4])) {
+            if (!vpx_rac_get_prob_branchy(c, tp[3])) { // 2, 3, 4
+                if (!vpx_rac_get_prob_branchy(c, tp[4])) {
                     cache[rc] = val = 2;
                 } else {
-                    val       = 3 + vp56_rac_get_prob(c, tp[5]);
+                    val       = 3 + vpx_rac_get_prob(c, tp[5]);
                     cache[rc] = 3;
                 }
-            } else if (!vp56_rac_get_prob_branchy(c, tp[6])) { // cat1/2
+            } else if (!vpx_rac_get_prob_branchy(c, tp[6])) { // cat1/2
                 cache[rc] = 4;
-                if (!vp56_rac_get_prob_branchy(c, tp[7])) {
-                    val  =  vp56_rac_get_prob(c, 159) + 5;
+                if (!vpx_rac_get_prob_branchy(c, tp[7])) {
+                    val  =  vpx_rac_get_prob(c, 159) + 5;
                 } else {
-                    val  = (vp56_rac_get_prob(c, 165) << 1) + 7;
-                    val +=  vp56_rac_get_prob(c, 145);
+                    val  = (vpx_rac_get_prob(c, 165) << 1) + 7;
+                    val +=  vpx_rac_get_prob(c, 145);
                 }
             } else { // cat 3-6
                 cache[rc] = 5;
-                if (!vp56_rac_get_prob_branchy(c, tp[8])) {
-                    if (!vp56_rac_get_prob_branchy(c, tp[9])) {
-                        val  = 11 + (vp56_rac_get_prob(c, 173) << 2);
-                        val +=      (vp56_rac_get_prob(c, 148) << 1);
-                        val +=       vp56_rac_get_prob(c, 140);
+                if (!vpx_rac_get_prob_branchy(c, tp[8])) {
+                    if (!vpx_rac_get_prob_branchy(c, tp[9])) {
+                        val  = 11 + (vpx_rac_get_prob(c, 173) << 2);
+                        val +=      (vpx_rac_get_prob(c, 148) << 1);
+                        val +=       vpx_rac_get_prob(c, 140);
                     } else {
-                        val  = 19 + (vp56_rac_get_prob(c, 176) << 3);
-                        val +=      (vp56_rac_get_prob(c, 155) << 2);
-                        val +=      (vp56_rac_get_prob(c, 140) << 1);
-                        val +=       vp56_rac_get_prob(c, 135);
+                        val  = 19 + (vpx_rac_get_prob(c, 176) << 3);
+                        val +=      (vpx_rac_get_prob(c, 155) << 2);
+                        val +=      (vpx_rac_get_prob(c, 140) << 1);
+                        val +=       vpx_rac_get_prob(c, 135);
                     }
-                } else if (!vp56_rac_get_prob_branchy(c, tp[10])) {
-                    val  = (vp56_rac_get_prob(c, 180) << 4) + 35;
-                    val += (vp56_rac_get_prob(c, 157) << 3);
-                    val += (vp56_rac_get_prob(c, 141) << 2);
-                    val += (vp56_rac_get_prob(c, 134) << 1);
-                    val +=  vp56_rac_get_prob(c, 130);
+                } else if (!vpx_rac_get_prob_branchy(c, tp[10])) {
+                    val  = (vpx_rac_get_prob(c, 180) << 4) + 35;
+                    val += (vpx_rac_get_prob(c, 157) << 3);
+                    val += (vpx_rac_get_prob(c, 141) << 2);
+                    val += (vpx_rac_get_prob(c, 134) << 1);
+                    val +=  vpx_rac_get_prob(c, 130);
                 } else {
                     val = 67;
                     if (!is8bitsperpixel) {
                         if (bpp == 12) {
-                            val += vp56_rac_get_prob(c, 255) << 17;
-                            val += vp56_rac_get_prob(c, 255) << 16;
+                            val += vpx_rac_get_prob(c, 255) << 17;
+                            val += vpx_rac_get_prob(c, 255) << 16;
                         }
-                        val +=  (vp56_rac_get_prob(c, 255) << 15);
-                        val +=  (vp56_rac_get_prob(c, 255) << 14);
+                        val +=  (vpx_rac_get_prob(c, 255) << 15);
+                        val +=  (vpx_rac_get_prob(c, 255) << 14);
                     }
-                    val += (vp56_rac_get_prob(c, 254) << 13);
-                    val += (vp56_rac_get_prob(c, 254) << 12);
-                    val += (vp56_rac_get_prob(c, 254) << 11);
-                    val += (vp56_rac_get_prob(c, 252) << 10);
-                    val += (vp56_rac_get_prob(c, 249) << 9);
-                    val += (vp56_rac_get_prob(c, 243) << 8);
-                    val += (vp56_rac_get_prob(c, 230) << 7);
-                    val += (vp56_rac_get_prob(c, 196) << 6);
-                    val += (vp56_rac_get_prob(c, 177) << 5);
-                    val += (vp56_rac_get_prob(c, 153) << 4);
-                    val += (vp56_rac_get_prob(c, 140) << 3);
-                    val += (vp56_rac_get_prob(c, 133) << 2);
-                    val += (vp56_rac_get_prob(c, 130) << 1);
-                    val +=  vp56_rac_get_prob(c, 129);
+                    val += (vpx_rac_get_prob(c, 254) << 13);
+                    val += (vpx_rac_get_prob(c, 254) << 12);
+                    val += (vpx_rac_get_prob(c, 254) << 11);
+                    val += (vpx_rac_get_prob(c, 252) << 10);
+                    val += (vpx_rac_get_prob(c, 249) << 9);
+                    val += (vpx_rac_get_prob(c, 243) << 8);
+                    val += (vpx_rac_get_prob(c, 230) << 7);
+                    val += (vpx_rac_get_prob(c, 196) << 6);
+                    val += (vpx_rac_get_prob(c, 177) << 5);
+                    val += (vpx_rac_get_prob(c, 153) << 4);
+                    val += (vpx_rac_get_prob(c, 140) << 3);
+                    val += (vpx_rac_get_prob(c, 133) << 2);
+                    val += (vpx_rac_get_prob(c, 130) << 1);
+                    val +=  vpx_rac_get_prob(c, 129);
                 }
             }
         }
diff --git a/libavcodec/vp9dec.h b/libavcodec/vp9dec.h
index 9cbd5839a8..56676a7c03 100644
--- a/libavcodec/vp9dec.h
+++ b/libavcodec/vp9dec.h
@@ -36,6 +36,7 @@
 #include "vp9.h"
 #include "vp9dsp.h"
 #include "vp9shared.h"
+#include "vpx_rac.h"
 
 #define REF_INVALID_SCALE 0xFFFF
 
@@ -98,7 +99,7 @@ typedef struct VP9Context {
     VP9DSPContext dsp;
     VideoDSPContext vdsp;
     GetBitContext gb;
-    VP56RangeCoder c;
+    VPXRangeCoder c;
     int pass, active_tile_cols;
 
 #if HAVE_THREADS
@@ -166,8 +167,8 @@ struct VP9TileData {
     //VP9Context should be const, but because of the threading API(generates
     //a lot of warnings) it's not.
     VP9Context *s;
-    VP56RangeCoder *c_b;
-    VP56RangeCoder *c;
+    VPXRangeCoder *c_b;
+    VPXRangeCoder *c;
     int row, row7, col, col7;
     uint8_t *dst[3];
     ptrdiff_t y_stride, uv_stride;
diff --git a/libavcodec/vp9mvs.c b/libavcodec/vp9mvs.c
index cee91dc34d..c604ec7cb6 100644
--- a/libavcodec/vp9mvs.c
+++ b/libavcodec/vp9mvs.c
@@ -24,9 +24,9 @@
 #include "threadframe.h"
 #include "vp56.h"
 #include "vp89_rac.h"
-#include "vp9.h"
 #include "vp9data.h"
 #include "vp9dec.h"
+#include "vpx_rac.h"
 
 static av_always_inline void clamp_mv(VP56mv *dst, const VP56mv *src,
                                       VP9TileData *td)
@@ -237,7 +237,7 @@ static void find_ref_mvs(VP9TileData *td,
 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 bit, sign = vpx_rac_get_prob(td->c, s->prob.p.mv_comp[idx].sign);
     int n, c = vp89_rac_get_tree(td->c, ff_vp9_mv_class_tree,
                                  s->prob.p.mv_comp[idx].classes);
 
@@ -247,7 +247,7 @@ static av_always_inline int read_mv_component(VP9TileData *td, int idx, int hp)
         int m;
 
         for (n = 0, m = 0; m < c; m++) {
-            bit = vp56_rac_get_prob(td->c, s->prob.p.mv_comp[idx].bits[m]);
+            bit = vpx_rac_get_prob(td->c, s->prob.p.mv_comp[idx].bits[m]);
             n |= bit << m;
             td->counts.mv_comp[idx].bits[m][bit]++;
         }
@@ -257,7 +257,7 @@ static av_always_inline int read_mv_component(VP9TileData *td, int idx, int hp)
         n  |= bit << 1;
         td->counts.mv_comp[idx].fp[bit]++;
         if (hp) {
-            bit = vp56_rac_get_prob(td->c, s->prob.p.mv_comp[idx].hp);
+            bit = vpx_rac_get_prob(td->c, s->prob.p.mv_comp[idx].hp);
             td->counts.mv_comp[idx].hp[bit]++;
             n |= bit;
         } else {
@@ -268,14 +268,14 @@ static av_always_inline int read_mv_component(VP9TileData *td, int idx, int hp)
         }
         n += 8 << c;
     } else {
-        n = vp56_rac_get_prob(td->c, s->prob.p.mv_comp[idx].class0);
+        n = vpx_rac_get_prob(td->c, s->prob.p.mv_comp[idx].class0);
         td->counts.mv_comp[idx].class0[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) {
-            bit = vp56_rac_get_prob(td->c, s->prob.p.mv_comp[idx].class0_hp);
+            bit = vpx_rac_get_prob(td->c, s->prob.p.mv_comp[idx].class0_hp);
             td->counts.mv_comp[idx].class0_hp[bit]++;
             n |= bit;
         } else {
diff --git a/libavcodec/vp56rac.c b/libavcodec/vpx_rac.c
similarity index 92%
rename from libavcodec/vp56rac.c
rename to libavcodec/vpx_rac.c
index 19e7dcf2bb..cf02e9a19c 100644
--- a/libavcodec/vp56rac.c
+++ b/libavcodec/vpx_rac.c
@@ -22,9 +22,9 @@
 #include <stdint.h>
 #include "libavutil/error.h"
 #include "bytestream.h"
-#include "vp56.h"
+#include "vpx_rac.h"
 
-const uint8_t ff_vp56_norm_shift[256]= {
+const uint8_t ff_vpx_norm_shift[256]= {
  8,7,6,6,5,5,5,5,4,4,4,4,4,4,4,4,
  3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
  2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
@@ -39,7 +39,7 @@ const uint8_t ff_vp56_norm_shift[256]= {
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 };
 
-int ff_vp56_init_range_decoder(VP56RangeCoder *c, const uint8_t *buf, int buf_size)
+int ff_vpx_init_range_decoder(VPXRangeCoder *c, const uint8_t *buf, int buf_size)
 {
     c->high = 255;
     c->bits = -16;
diff --git a/libavcodec/vpx_rac.h b/libavcodec/vpx_rac.h
new file mode 100644
index 0000000000..b158cc0754
--- /dev/null
+++ b/libavcodec/vpx_rac.h
@@ -0,0 +1,135 @@
+/*
+ * 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
+ * Common VP5-VP9 range decoder stuff
+ */
+
+#ifndef AVCODEC_VPX_RAC_H
+#define AVCODEC_VPX_RAC_H
+
+#include <stdint.h>
+
+#include "config.h"
+#include "libavutil/attributes.h"
+#include "bytestream.h"
+
+typedef struct VPXRangeCoder {
+    int high;
+    int bits; /* stored negated (i.e. negative "bits" is a positive number of
+                 bits left) in order to eliminate a negate in cache refilling */
+    const uint8_t *buffer;
+    const uint8_t *end;
+    unsigned int code_word;
+    int end_reached;
+} VPXRangeCoder;
+
+extern const uint8_t ff_vpx_norm_shift[256];
+int ff_vpx_init_range_decoder(VPXRangeCoder *c, const uint8_t *buf, int buf_size);
+
+/**
+ * returns 1 if the end of the stream has been reached, 0 otherwise.
+ */
+static av_always_inline int vpx_rac_is_end(VPXRangeCoder *c)
+{
+    if (c->end <= c->buffer && c->bits >= 0)
+        c->end_reached ++;
+    return c->end_reached > 10;
+}
+
+static av_always_inline unsigned int vpx_rac_renorm(VPXRangeCoder *c)
+{
+    int shift = ff_vpx_norm_shift[c->high];
+    int bits = c->bits;
+    unsigned int code_word = c->code_word;
+
+    c->high   <<= shift;
+    code_word <<= shift;
+    bits       += shift;
+    if(bits >= 0 && c->buffer < c->end) {
+        code_word |= bytestream_get_be16(&c->buffer) << bits;
+        bits -= 16;
+    }
+    c->bits = bits;
+    return code_word;
+}
+
+#if   ARCH_ARM
+#include "arm/vpx_arith.h"
+#elif ARCH_X86
+#include "x86/vpx_arith.h"
+#endif
+
+#ifndef vpx_rac_get_prob
+#define vpx_rac_get_prob vpx_rac_get_prob
+static av_always_inline int vpx_rac_get_prob(VPXRangeCoder *c, uint8_t prob)
+{
+    unsigned int code_word = vpx_rac_renorm(c);
+    unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
+    unsigned int low_shift = low << 16;
+    int bit = code_word >= low_shift;
+
+    c->high = bit ? c->high - low : low;
+    c->code_word = bit ? code_word - low_shift : code_word;
+
+    return bit;
+}
+#endif
+
+#ifndef vpx_rac_get_prob_branchy
+// branchy variant, to be used where there's a branch based on the bit decoded
+static av_always_inline int vpx_rac_get_prob_branchy(VPXRangeCoder *c, int prob)
+{
+    unsigned long code_word = vpx_rac_renorm(c);
+    unsigned low = 1 + (((c->high - 1) * prob) >> 8);
+    unsigned low_shift = low << 16;
+
+    if (code_word >= low_shift) {
+        c->high     -= low;
+        c->code_word = code_word - low_shift;
+        return 1;
+    }
+
+    c->high = low;
+    c->code_word = code_word;
+    return 0;
+}
+#endif
+
+static av_always_inline int vpx_rac_get(VPXRangeCoder *c)
+{
+    unsigned int code_word = vpx_rac_renorm(c);
+    /* equiprobable */
+    int low = (c->high + 1) >> 1;
+    unsigned int low_shift = low << 16;
+    int bit = code_word >= low_shift;
+    if (bit) {
+        c->high   -= low;
+        code_word -= low_shift;
+    } else {
+        c->high = low;
+    }
+
+    c->code_word = code_word;
+    return bit;
+}
+
+#endif /* AVCODEC_VPX_RAC_H */
diff --git a/libavcodec/x86/vp56_arith.h b/libavcodec/x86/vpx_arith.h
similarity index 83%
rename from libavcodec/x86/vp56_arith.h
rename to libavcodec/x86/vpx_arith.h
index 9f7639980c..d9e4c0dec4 100644
--- a/libavcodec/x86/vp56_arith.h
+++ b/libavcodec/x86/vpx_arith.h
@@ -21,16 +21,18 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#ifndef AVCODEC_X86_VP56_ARITH_H
-#define AVCODEC_X86_VP56_ARITH_H
+#ifndef AVCODEC_X86_VPX_ARITH_H
+#define AVCODEC_X86_VPX_ARITH_H
+
+#include "libavutil/x86/asm.h"
 
 #if HAVE_INLINE_ASM && HAVE_FAST_CMOV && HAVE_6REGS
 #include "libavutil/attributes.h"
 
-#define vp56_rac_get_prob vp56_rac_get_prob
-static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob)
+#define vpx_rac_get_prob vpx_rac_get_prob
+static av_always_inline int vpx_rac_get_prob(VPXRangeCoder *c, uint8_t prob)
 {
-    unsigned int code_word = vp56_rac_renorm(c);
+    unsigned int code_word = vpx_rac_renorm(c);
     unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
     unsigned int low_shift = low << 16;
     int bit = 0;
@@ -50,4 +52,4 @@ static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob)
 }
 #endif
 
-#endif /* AVCODEC_X86_VP56_ARITH_H */
+#endif /* AVCODEC_X86_VPX_ARITH_H */
-- 
2.34.1



More information about the ffmpeg-devel mailing list