shithub: dav1d

Download patch

ref: 9923967842794c2af3b3991ff97a16bef5e2197e
parent: aa0fc4718bca67f521ac5ef21b29719764182cf1
author: Henrik Gramner <gramner@twoorioles.com>
date: Thu Oct 4 07:35:22 EDT 2018

Correctly use dav1d_ prefix for global symbols

--- a/src/cdf.c
+++ b/src/cdf.c
@@ -4055,14 +4055,14 @@
     [3] = { .cdf = NULL },
 };
 
-void av1_init_states(CdfThreadContext *const cdf, const int qidx) {
+void dav1d_init_states(CdfThreadContext *const cdf, const int qidx) {
     const int qcat = get_qcat_idx(qidx);
     if (cdf_init[qcat].cdf) {
-        cdf_thread_ref(cdf, &cdf_init[qcat]);
+        dav1d_cdf_thread_ref(cdf, &cdf_init[qcat]);
         return;
     }
 
-    cdf_thread_alloc(&cdf_init[qcat], NULL);
+    dav1d_cdf_thread_alloc(&cdf_init[qcat], NULL);
     cdf_init[qcat].cdf->m = av1_default_cdf;
     memcpy(cdf_init[qcat].cdf->kfym, default_kf_y_mode_cdf,
            sizeof(default_kf_y_mode_cdf));
@@ -4069,12 +4069,12 @@
     cdf_init[qcat].cdf->coef = av1_default_coef_cdf[qcat];
     cdf_init[qcat].cdf->mv = default_mv_cdf;
     cdf_init[qcat].cdf->dmv = default_mv_cdf;
-    cdf_thread_ref(cdf, &cdf_init[qcat]);
+    dav1d_cdf_thread_ref(cdf, &cdf_init[qcat]);
 }
 
-void av1_update_tile_cdf(const Av1FrameHeader *const hdr,
-                         CdfContext *const dst,
-                         const CdfContext *const src)
+void dav1d_update_tile_cdf(const Av1FrameHeader *const hdr,
+                           CdfContext *const dst,
+                           const CdfContext *const src)
 {
     int i, j, k, l;
 
@@ -4210,7 +4210,9 @@
 /*
  * CDF threading wrappers.
  */
-void cdf_thread_alloc(CdfThreadContext *const cdf, struct thread_data *const t) {
+void dav1d_cdf_thread_alloc(CdfThreadContext *const cdf,
+                            struct thread_data *const t)
+{
     cdf->ref = dav1d_ref_create(sizeof(CdfContext) +
                                 (t != NULL) * sizeof(atomic_uint));
     cdf->cdf = cdf->ref->data;
@@ -4221,17 +4223,19 @@
     }
 }
 
-void cdf_thread_ref(CdfThreadContext *const dst, CdfThreadContext *const src) {
+void dav1d_cdf_thread_ref(CdfThreadContext *const dst,
+                          CdfThreadContext *const src)
+{
     dav1d_ref_inc(src->ref);
     *dst = *src;
 }
 
-void cdf_thread_unref(CdfThreadContext *const cdf) {
+void dav1d_cdf_thread_unref(CdfThreadContext *const cdf) {
     dav1d_ref_dec(cdf->ref);
     memset(cdf, 0, sizeof(*cdf));
 }
 
-void cdf_thread_wait(CdfThreadContext *const cdf) {
+void dav1d_cdf_thread_wait(CdfThreadContext *const cdf) {
     if (!cdf->t) return;
 
     if (atomic_load(cdf->progress)) return;
@@ -4241,7 +4245,7 @@
     pthread_mutex_unlock(&cdf->t->lock);
 }
 
-void cdf_thread_signal(CdfThreadContext *const cdf) {
+void dav1d_cdf_thread_signal(CdfThreadContext *const cdf) {
     if (!cdf->t) return;
 
     pthread_mutex_lock(&cdf->t->lock);
--- a/src/cdf.h
+++ b/src/cdf.h
@@ -131,18 +131,18 @@
     atomic_uint *progress;
 } CdfThreadContext;
 
-void av1_init_states(CdfThreadContext *cdf, int qidx);
-void av1_update_tile_cdf(const Av1FrameHeader *hdr, CdfContext *dst,
+void dav1d_init_states(CdfThreadContext *cdf, int qidx);
+void dav1d_update_tile_cdf(const Av1FrameHeader *hdr, CdfContext *dst,
                          const CdfContext *src);
 
-void cdf_thread_alloc(CdfThreadContext *cdf, struct thread_data *t);
-void cdf_thread_ref(CdfThreadContext *dst, CdfThreadContext *src);
-void cdf_thread_unref(CdfThreadContext *cdf);
+void dav1d_cdf_thread_alloc(CdfThreadContext *cdf, struct thread_data *t);
+void dav1d_cdf_thread_ref(CdfThreadContext *dst, CdfThreadContext *src);
+void dav1d_cdf_thread_unref(CdfThreadContext *cdf);
 
 /*
  * These are binary signals (so a signal is either "done" or "not done").
  */
-void cdf_thread_wait(CdfThreadContext *cdf);
-void cdf_thread_signal(CdfThreadContext *cdf);
+void dav1d_cdf_thread_wait(CdfThreadContext *cdf);
+void dav1d_cdf_thread_signal(CdfThreadContext *cdf);
 
 #endif /* __AV1_CDF_H__ */
--- a/src/decode.c
+++ b/src/decode.c
@@ -134,7 +134,7 @@
 {
     const Dav1dFrameContext *const f = t->f;
     const int bx4 = t->bx & 31, by4 = t->by & 31;
-    const TxfmInfo *const t_dim = &av1_txfm_dimensions[from];
+    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[from];
     const int txw = t_dim->lw, txh = t_dim->lh;
     int is_split;
 
@@ -152,7 +152,7 @@
 
     if (is_split && t_dim->max > TX_8X8) {
         const enum RectTxfmSize sub = t_dim->sub;
-        const TxfmInfo *const sub_t_dim = &av1_txfm_dimensions[sub];
+        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
         const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
 
         read_tx_tree(t, sub, depth + 1, masks, x_off * 2 + 0, y_off * 2 + 0);
@@ -176,7 +176,7 @@
     }
 }
 
-int av1_neg_deinterleave(int diff, int ref, int max) {
+static int neg_deinterleave(int diff, int ref, int max) {
     if (!ref) return diff;
     if (ref >= (max - 1)) return max - diff - 1;
     if (2 * ref < max) {
@@ -214,7 +214,7 @@
                         have_top && t->bx + bw4 < t->ts->tiling.col_end &&
                         (intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT);
 
-#define bs(rp) av1_block_dimensions[sbtype_to_bs[(rp)->sb_type]]
+#define bs(rp) dav1d_block_dimensions[sbtype_to_bs[(rp)->sb_type]]
 #define matches(rp) ((rp)->ref[0] == ref + 1 && (rp)->ref[1] == -1)
 
     if (have_top) {
@@ -342,8 +342,8 @@
         memcpy(pts[i], pts[j], sizeof(*pts));
     }
 
-    if (!find_affine_int(pts, ret, bw4, bh4, mv, wmp, t->bx, t->by) &&
-        !get_shear_params(wmp))
+    if (!dav1d_find_affine_int(pts, ret, bw4, bh4, mv, wmp, t->bx, t->by) &&
+        !dav1d_get_shear_params(wmp))
     {
         wmp->type = WM_TYPE_AFFINE;
     } else
@@ -600,12 +600,12 @@
                             const int bx4, const int by4)
 {
     const Dav1dFrameContext *const f = t->f;
-    const uint8_t *const b_dim = av1_block_dimensions[bs];
+    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
     const int bw4 = b_dim[0], bh4 = b_dim[1];
 
     // var-tx tree coding
     b->tx_split[0] = b->tx_split[1] = 0;
-    b->max_ytx = av1_max_txfm_size_for_bs[bs][0];
+    b->max_ytx = dav1d_max_txfm_size_for_bs[bs][0];
     if (f->frame_hdr.segmentation.lossless[b->seg_id] ||
         b->max_ytx == TX_4X4)
     {
@@ -621,11 +621,11 @@
         } else {
             assert(f->frame_hdr.txfm_mode == TX_LARGEST);
         }
-        b->uvtx = av1_max_txfm_size_for_bs[bs][f->cur.p.p.layout];
+        b->uvtx = dav1d_max_txfm_size_for_bs[bs][f->cur.p.p.layout];
     } else {
         assert(imin(bw4, bh4) <= 16 || b->max_ytx == TX_64X64);
         int y, x, y_off, x_off;
-        const TxfmInfo *const ytx = &av1_txfm_dimensions[b->max_ytx];
+        const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
         for (y = 0, y_off = 0; y < bh4; y += ytx->h, y_off++) {
             for (x = 0, x_off = 0; x < bw4; x += ytx->w, x_off++) {
                 read_tx_tree(t, b->max_ytx, 0, b->tx_split, x_off, y_off);
@@ -639,7 +639,7 @@
         if (DEBUG_BLOCK_INFO)
             printf("Post-vartxtree[%x/%x]: r=%d\n",
                    b->tx_split[0], b->tx_split[1], t->ts->msac.rng);
-        b->uvtx = av1_max_txfm_size_for_bs[bs][f->cur.p.p.layout];
+        b->uvtx = dav1d_max_txfm_size_for_bs[bs][f->cur.p.p.layout];
     }
 }
 
@@ -676,7 +676,7 @@
     const Dav1dFrameContext *const f = t->f;
     Av1Block b_mem, *const b = f->frame_thread.pass ?
         &f->frame_thread.b[t->by * f->b4_stride + t->bx] : &b_mem;
-    const uint8_t *const b_dim = av1_block_dimensions[bs];
+    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
     const int bx4 = t->bx & 31, by4 = t->by & 31;
     const int ss_ver = f->cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
     const int ss_hor = f->cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
@@ -711,7 +711,7 @@
             }
             f->bd_fn.recon_b_inter(t, bs, b);
 
-            const uint8_t *const filter = eve_av1_filter_dir[b->filter2d];
+            const uint8_t *const filter = dav1d_filter_dir[b->filter2d];
             memset(&t->l.filter[0][by4], filter[0], bh4);
             memset(&t->a->filter[0][bx4], filter[0], bw4);
             memset(&t->l.filter[1][by4], filter[1], bh4);
@@ -770,8 +770,8 @@
                                                    NUM_SEGMENTS);
                 const unsigned last_active_seg_id =
                     f->frame_hdr.segmentation.seg_data.last_active_segid;
-                b->seg_id = av1_neg_deinterleave(diff, pred_seg_id,
-                                                 last_active_seg_id + 1);
+                b->seg_id = neg_deinterleave(diff, pred_seg_id,
+                                             last_active_seg_id + 1);
                 if (b->seg_id > last_active_seg_id) b->seg_id = 0; // error?
             }
 
@@ -817,8 +817,8 @@
                                                    NUM_SEGMENTS);
                 const unsigned last_active_seg_id =
                     f->frame_hdr.segmentation.seg_data.last_active_segid;
-                b->seg_id = av1_neg_deinterleave(diff, pred_seg_id,
-                                                 last_active_seg_id + 1);
+                b->seg_id = neg_deinterleave(diff, pred_seg_id,
+                                             last_active_seg_id + 1);
                 if (b->seg_id > last_active_seg_id) b->seg_id = 0; // error?
             }
         }
@@ -928,9 +928,9 @@
     // intra/inter-specific stuff
     if (b->intra) {
         uint16_t *const ymode_cdf = f->frame_hdr.frame_type & 1 ?
-            ts->cdf.m.y_mode[av1_ymode_size_context[bs]] :
-            ts->cdf.kfym[intra_mode_context[t->a->mode[bx4]]]
-                        [intra_mode_context[t->l.mode[by4]]];
+            ts->cdf.m.y_mode[dav1d_ymode_size_context[bs]] :
+            ts->cdf.kfym[dav1d_intra_mode_context[t->a->mode[bx4]]]
+                        [dav1d_intra_mode_context[t->l.mode[by4]]];
         b->y_mode = msac_decode_symbol_adapt(&ts->msac, ymode_cdf,
                                               N_INTRA_PRED_MODES);
         if (DEBUG_BLOCK_INFO)
@@ -1060,11 +1060,11 @@
         const TxfmInfo *t_dim;
         if (f->frame_hdr.segmentation.lossless[b->seg_id]) {
             b->tx = b->uvtx = (int) TX_4X4;
-            t_dim = &av1_txfm_dimensions[TX_4X4];
+            t_dim = &dav1d_txfm_dimensions[TX_4X4];
         } else {
-            b->tx = av1_max_txfm_size_for_bs[bs][0];
-            b->uvtx = av1_max_txfm_size_for_bs[bs][f->cur.p.p.layout];
-            t_dim = &av1_txfm_dimensions[b->tx];
+            b->tx = dav1d_max_txfm_size_for_bs[bs][0];
+            b->uvtx = dav1d_max_txfm_size_for_bs[bs][f->cur.p.p.layout];
+            t_dim = &dav1d_txfm_dimensions[b->tx];
             if (f->frame_hdr.txfm_mode == TX_SWITCHABLE && t_dim->max > TX_4X4) {
                 const int tctx = get_tx_ctx(t->a, &t->l, t_dim, by4, bx4);
                 uint16_t *const tx_cdf = ts->cdf.m.txsz[t_dim->max - 1][tctx];
@@ -1073,7 +1073,7 @@
 
                 while (depth--) {
                     b->tx = t_dim->sub;
-                    t_dim = &av1_txfm_dimensions[b->tx];
+                    t_dim = &dav1d_txfm_dimensions[b->tx];
                 }
             }
             if (DEBUG_BLOCK_INFO)
@@ -1327,7 +1327,7 @@
                 printf("Post-compintermode[%d,ctx=%d,n_mvs=%d]: r=%d\n",
                        b->inter_mode, ctx, n_mvs, ts->msac.rng);
 
-            const uint8_t *const im = av1_comp_inter_pred_modes[b->inter_mode];
+            const uint8_t *const im = dav1d_comp_inter_pred_modes[b->inter_mode];
             b->drl_idx = 0;
             if (b->inter_mode == NEWMV_NEWMV) {
                 if (n_mvs > 1) {
@@ -1422,7 +1422,7 @@
                 }
             } else {
                 if (wedge_allowed_mask & (1 << bs)) {
-                    const int ctx = av1_wedge_ctx_lut[bs];
+                    const int ctx = dav1d_wedge_ctx_lut[bs];
                     b->comp_type = COMP_INTER_WEDGE -
                         msac_decode_bool_adapt(&ts->msac,
                                                ts->cdf.m.wedge_comp[ctx]);
@@ -1558,7 +1558,7 @@
             }
 
             // interintra flags
-            const int ii_sz_grp = av1_ymode_size_context[bs];
+            const int ii_sz_grp = dav1d_ymode_size_context[bs];
             if (f->seq_hdr.inter_intra &&
                 interintra_allowed_mask & (1 << bs) &&
                 msac_decode_bool_adapt(&ts->msac, ts->cdf.m.interintra[ii_sz_grp]))
@@ -1566,7 +1566,7 @@
                 b->interintra_mode = msac_decode_symbol_adapt(&ts->msac,
                                           ts->cdf.m.interintra_mode[ii_sz_grp],
                                           N_INTER_INTRA_PRED_MODES);
-                const int wedge_ctx = av1_wedge_ctx_lut[bs];
+                const int wedge_ctx = dav1d_wedge_ctx_lut[bs];
                 b->interintra_type = INTER_INTRA_BLEND +
                     msac_decode_bool_adapt(&ts->msac,
                                            ts->cdf.m.interintra_wedge[wedge_ctx]);
@@ -1666,7 +1666,7 @@
         } else {
             filter[0] = filter[1] = f->frame_hdr.subpel_filter_mode;
         }
-        b->filter2d = av1_filter_2d[filter[1]][filter[0]];
+        b->filter2d = dav1d_filter_2d[filter[1]][filter[0]];
 
         read_vartx_tree(t, b, bs, bx4, by4);
 
@@ -1795,7 +1795,7 @@
                        f->frame_hdr.frame_offset, t->by, t->bx, bl, ctx, bp,
                        t->ts->msac.rng);
         }
-        const uint8_t *const b = av1_block_sizes[bl][bp];
+        const uint8_t *const b = dav1d_block_sizes[bl][bp];
 
         switch (bp) {
         case PARTITION_NONE:
@@ -1939,7 +1939,7 @@
             t->bx -= hsz;
         } else {
             bp = PARTITION_H;
-            decode_b(t, bl, av1_block_sizes[bl][PARTITION_H][0], PARTITION_H,
+            decode_b(t, bl, dav1d_block_sizes[bl][PARTITION_H][0], PARTITION_H,
                      node->h[0]);
         }
     } else {
@@ -1969,14 +1969,14 @@
             t->by -= hsz;
         } else {
             bp = PARTITION_V;
-            decode_b(t, bl, av1_block_sizes[bl][PARTITION_V][0], PARTITION_V,
+            decode_b(t, bl, dav1d_block_sizes[bl][PARTITION_V][0], PARTITION_V,
                      node->v[0]);
         }
     }
 
     if (f->frame_thread.pass != 2 && (bp != PARTITION_SPLIT || bl == BL_8X8)) {
-        memset(&t->a->partition[bx8], av1_al_part_ctx[0][bl][bp], hsz);
-        memset(&t->l.partition[by8], av1_al_part_ctx[1][bl][bp], hsz);
+        memset(&t->a->partition[bx8], dav1d_al_part_ctx[0][bl][bp], hsz);
+        memset(&t->l.partition[by8], dav1d_al_part_ctx[1][bl][bp], hsz);
     }
 
     return 0;
@@ -2058,7 +2058,7 @@
         atomic_init(&ts->progress, row_sb_start);
 }
 
-int decode_tile_sbrow(Dav1dTileContext *const t) {
+int dav1d_decode_tile_sbrow(Dav1dTileContext *const t) {
     const Dav1dFrameContext *const f = t->f;
     const enum BlockLevel root_bl = f->seq_hdr.sb128 ? BL_128X128 : BL_64X64;
     Dav1dTileState *const ts = t->ts;
@@ -2192,12 +2192,12 @@
             } else if (lr->type == RESTORATION_SGRPROJ) {
                 const unsigned idx = msac_decode_bools(&ts->msac, 4);
                 lr->sgr_idx = idx;
-                lr->sgr_weights[0] = sgr_params[idx][0] ?
+                lr->sgr_weights[0] = dav1d_sgr_params[idx][0] ?
                     msac_decode_subexp(&ts->msac,
                                        ts->lr_ref[p]->sgr_weights[0] + 96, 128,
                                        4) - 96 :
                     0;
-                lr->sgr_weights[1] = sgr_params[idx][1] ?
+                lr->sgr_weights[1] = dav1d_sgr_params[idx][1] ?
                     msac_decode_subexp(&ts->msac,
                                        ts->lr_ref[p]->sgr_weights[1] + 32, 128,
                                        4) - 32 :
@@ -2235,7 +2235,7 @@
     return 0;
 }
 
-int decode_frame(Dav1dFrameContext *const f) {
+int dav1d_decode_frame(Dav1dFrameContext *const f) {
     const Dav1dContext *const c = f->c;
     int retval = -EINVAL;
 
@@ -2429,14 +2429,14 @@
     init_quant_tables(&f->seq_hdr, &f->frame_hdr, f->frame_hdr.quant.yac, f->dq);
     if (f->frame_hdr.quant.qm)
         for (int j = 0; j < N_RECT_TX_SIZES; j++) {
-            f->qm[0][j][0] = av1_qm_tbl[f->frame_hdr.quant.qm_y][0][j];
-            f->qm[0][j][1] = av1_qm_tbl[f->frame_hdr.quant.qm_u][1][j];
-            f->qm[0][j][2] = av1_qm_tbl[f->frame_hdr.quant.qm_v][1][j];
+            f->qm[0][j][0] = dav1d_qm_tbl[f->frame_hdr.quant.qm_y][0][j];
+            f->qm[0][j][1] = dav1d_qm_tbl[f->frame_hdr.quant.qm_u][1][j];
+            f->qm[0][j][2] = dav1d_qm_tbl[f->frame_hdr.quant.qm_v][1][j];
         }
     for (int i = f->frame_hdr.quant.qm; i < 2; i++)
         for (int tx = 0; tx < N_RECT_TX_SIZES; tx++)
             for (int pl = 0; pl < 3; pl++)
-                f->qm[i][tx][pl] = av1_qm_tbl[15][!!pl][tx];
+                f->qm[i][tx][pl] = dav1d_qm_tbl[15][!!pl][tx];
 
     // setup jnt_comp weights
     if (f->frame_hdr.switchable_comp_refs) {
@@ -2480,7 +2480,7 @@
     f->lf.p[2] = f->cur.p.data[2];
     f->lf.tile_row = 1;
 
-    cdf_thread_wait(&f->in_cdf);
+    dav1d_cdf_thread_wait(&f->in_cdf);
 
     // parse individual tiles per tile group
     int update_set = 0, tile_idx = 0;
@@ -2524,7 +2524,7 @@
         }
     }
 
-    cdf_thread_unref(&f->in_cdf);
+    dav1d_cdf_thread_unref(&f->in_cdf);
 
     // 2-pass decoding:
     // - enabled for frame-threading, so that one frame can do symbol parsing
@@ -2562,7 +2562,7 @@
                         t->ts = &f->ts[tile_row * f->frame_hdr.tiling.cols + tile_col];
 
                         int res;
-                        if ((res = decode_tile_sbrow(t)))
+                        if ((res = dav1d_decode_tile_sbrow(t)))
                             return res;
                     }
 
@@ -2628,10 +2628,10 @@
         if (f->frame_thread.pass <= 1 && f->frame_hdr.refresh_context) {
             // cdf update
             if (update_set)
-                av1_update_tile_cdf(&f->frame_hdr, f->out_cdf.cdf,
-                                    &f->ts[f->frame_hdr.tiling.update].cdf);
-            cdf_thread_signal(&f->out_cdf);
-            cdf_thread_unref(&f->out_cdf);
+                dav1d_update_tile_cdf(&f->frame_hdr, f->out_cdf.cdf,
+                                      &f->ts[f->frame_hdr.tiling.update].cdf);
+            dav1d_cdf_thread_signal(&f->out_cdf);
+            dav1d_cdf_thread_unref(&f->out_cdf);
         }
         if (f->frame_thread.pass == 1) {
             assert(c->n_fc > 1);
@@ -2674,7 +2674,7 @@
     return retval;
 }
 
-int submit_frame(Dav1dContext *const c) {
+int dav1d_submit_frame(Dav1dContext *const c) {
     Dav1dFrameContext *f;
     int res;
 
@@ -2733,11 +2733,11 @@
     }
 
 #define assign_bitdepth_case(bd) \
-        f->bd_fn.recon_b_inter = recon_b_inter_##bd##bpc; \
-        f->bd_fn.recon_b_intra = recon_b_intra_##bd##bpc; \
-        f->bd_fn.filter_sbrow = filter_sbrow_##bd##bpc; \
-        f->bd_fn.backup_ipred_edge = backup_ipred_edge_##bd##bpc; \
-        f->bd_fn.read_coef_blocks = read_coef_blocks_##bd##bpc
+        f->bd_fn.recon_b_inter = dav1d_recon_b_inter_##bd##bpc; \
+        f->bd_fn.recon_b_intra = dav1d_recon_b_intra_##bd##bpc; \
+        f->bd_fn.filter_sbrow = dav1d_filter_sbrow_##bd##bpc; \
+        f->bd_fn.backup_ipred_edge = dav1d_backup_ipred_edge_##bd##bpc; \
+        f->bd_fn.read_coef_blocks = dav1d_read_coef_blocks_##bd##bpc
     if (f->seq_hdr.bpc <= 8) {
 #if CONFIG_8BPC
         assign_bitdepth_case(8);
@@ -2757,13 +2757,13 @@
 
     // setup entropy
     if (f->frame_hdr.primary_ref_frame == PRIMARY_REF_NONE) {
-        av1_init_states(&f->in_cdf, f->frame_hdr.quant.yac);
+        dav1d_init_states(&f->in_cdf, f->frame_hdr.quant.yac);
     } else {
         const int pri_ref = f->frame_hdr.refidx[f->frame_hdr.primary_ref_frame];
-        cdf_thread_ref(&f->in_cdf, &c->cdf[pri_ref]);
+        dav1d_cdf_thread_ref(&f->in_cdf, &c->cdf[pri_ref]);
     }
     if (f->frame_hdr.refresh_context) {
-        cdf_thread_alloc(&f->out_cdf, c->n_fc > 1 ? &f->frame_thread.td : NULL);
+        dav1d_cdf_thread_alloc(&f->out_cdf, c->n_fc > 1 ? &f->frame_thread.td : NULL);
         memcpy(f->out_cdf.cdf, f->in_cdf.cdf, sizeof(*f->in_cdf.cdf));
     }
 
@@ -2878,11 +2878,11 @@
                 dav1d_thread_picture_unref(&c->refs[i].p);
             dav1d_thread_picture_ref(&c->refs[i].p, &f->cur);
 
-            if (c->cdf[i].cdf) cdf_thread_unref(&c->cdf[i]);
+            if (c->cdf[i].cdf) dav1d_cdf_thread_unref(&c->cdf[i]);
             if (f->frame_hdr.refresh_context) {
-                cdf_thread_ref(&c->cdf[i], &f->out_cdf);
+                dav1d_cdf_thread_ref(&c->cdf[i], &f->out_cdf);
             } else {
-                cdf_thread_ref(&c->cdf[i], &f->in_cdf);
+                dav1d_cdf_thread_ref(&c->cdf[i], &f->in_cdf);
             }
             c->refs[i].lf_mode_ref_deltas =
                 f->frame_hdr.loopfilter.mode_ref_deltas;
@@ -2909,7 +2909,7 @@
     }
 
     if (c->n_fc == 1) {
-        if ((res = decode_frame(f)) < 0)
+        if ((res = dav1d_decode_frame(f)) < 0)
             return res;
     } else {
         pthread_cond_signal(&f->frame_thread.td.cond);
--- a/src/decode.h
+++ b/src/decode.h
@@ -30,6 +30,6 @@
 
 #include "src/internal.h"
 
-int submit_frame(Dav1dContext *c);
+int dav1d_submit_frame(Dav1dContext *c);
 
 #endif /* __DAV1D_SRC_DECODE_H__ */
--- a/src/env.h
+++ b/src/env.h
@@ -132,7 +132,7 @@
         return TXTP_SET_LOSSLESS;
     }
 
-    const TxfmInfo *const t_dim = &av1_txfm_dimensions[tx];
+    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
 
     if (t_dim->max >= TX_64X64)
         return TXTP_SET_DCT;
@@ -161,9 +161,9 @@
         return WHT_WHT;
     }
 
-    const TxfmInfo *const t_dim = &av1_txfm_dimensions[tx];
+    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
 
-    return t_dim->max == TX_32X32 ? DCT_DCT : av1_txtp_from_uvmode[uv_mode];
+    return t_dim->max == TX_32X32 ? DCT_DCT : dav1d_txtp_from_uvmode[uv_mode];
 }
 
 static inline enum TxfmType get_uv_inter_txtp(const TxfmInfo *const uvt_dim,
@@ -531,7 +531,7 @@
                                     const int chroma,
                                     const enum Dav1dPixelLayout layout)
 {
-    const uint8_t *const b_dim = av1_block_dimensions[bs];
+    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
 
     if (chroma) {
         const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
@@ -610,7 +610,7 @@
                                   const enum RectTxfmSize tx,
                                   const enum TxClass tx_class)
 {
-    const TxfmInfo *const t_dim = &av1_txfm_dimensions[tx];
+    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
 
     if (is_eob) {
         if (scan_idx == 0)         return 0;
@@ -640,7 +640,7 @@
     const int ctx = imin((mag + 1) >> 1, 4);
     if (tx_class == TX_CLASS_2D) {
         return !rc ? 0 :
-            av1_nz_map_ctx_offset[tx][imin(y, 4)][imin(x, 4)] + ctx;
+            dav1d_nz_map_ctx_offset[tx][imin(y, 4)][imin(x, 4)] + ctx;
     } else {
         return 26 + imin((tx_class == TX_CLASS_V) ? y : x, 2) * 5 + ctx;
     }
@@ -685,7 +685,7 @@
                              const int rc, const enum RectTxfmSize tx,
                              const enum TxClass tx_class)
 {
-    const TxfmInfo *const t_dim = &av1_txfm_dimensions[tx];
+    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
     const int x = rc >> (imin(t_dim->lh, 3) + 2);
     const int y = rc & (4 * imin(t_dim->h, 8) - 1);
     const int stride = 4 * (imin(t_dim->h, 8) + 1);
--- a/src/getbits.c
+++ b/src/getbits.c
@@ -33,8 +33,8 @@
 
 #include "src/getbits.h"
 
-void init_get_bits(GetBits *const c,
-                   const uint8_t *const data, const size_t sz)
+void dav1d_init_get_bits(GetBits *const c, const uint8_t *const data,
+                         const size_t sz)
 {
     c->ptr = c->ptr_start = data;
     c->ptr_end = &c->ptr_start[sz];
@@ -60,7 +60,7 @@
     c->state |= state << (64 - c->bits_left);
 }
 
-unsigned get_bits(GetBits *const c, const unsigned n) {
+unsigned dav1d_get_bits(GetBits *const c, const unsigned n) {
     assert(n <= 32 /* can go up to 57 if we change return type */);
 
     if (n > c->bits_left) refill(c, n);
@@ -72,27 +72,27 @@
     return state >> (64 - n);
 }
 
-int get_sbits(GetBits *const c, const unsigned n) {
+int dav1d_get_sbits(GetBits *const c, const unsigned n) {
     const int shift = 31 - n;
-    const int res = get_bits(c, n + 1) << shift;
+    const int res = dav1d_get_bits(c, n + 1) << shift;
     return res >> shift;
 }
 
-unsigned get_uniform(GetBits *const c, const unsigned n) {
+unsigned dav1d_get_uniform(GetBits *const c, const unsigned n) {
     assert(n > 0);
     const int l = ulog2(n) + 1;
     assert(l > 0);
     const int m = (1 << l) - n;
-    const int v = get_bits(c, l - 1);
-    return v < m ? v : (v << 1) - m + get_bits(c, 1);
+    const int v = dav1d_get_bits(c, l - 1);
+    return v < m ? v : (v << 1) - m + dav1d_get_bits(c, 1);
 }
 
-unsigned get_vlc(GetBits *const c) {
+unsigned dav1d_get_vlc(GetBits *const c) {
     int n_bits = 0;
-    while (!get_bits(c, 1))
+    while (!dav1d_get_bits(c, 1))
         if (++n_bits == 32)
             return 0xFFFFFFFFU;
-    return ((1 << n_bits) - 1) + get_bits(c, n_bits);
+    return ((1 << n_bits) - 1) + dav1d_get_bits(c, n_bits);
 }
 
 static unsigned get_bits_subexp_u(GetBits *const c, const unsigned ref,
@@ -104,12 +104,12 @@
         const int b = i ? 3 + i - 1 : 3;
 
         if (n < v + 3 * (1 << b)) {
-            v += get_uniform(c, n - v + 1);
+            v += dav1d_get_uniform(c, n - v + 1);
             break;
         }
 
-        if (!get_bits(c, 1)) {
-            v += get_bits(c, b);
+        if (!dav1d_get_bits(c, 1)) {
+            v += dav1d_get_bits(c, b);
             break;
         }
 
@@ -119,11 +119,11 @@
     return ref * 2 <= n ? inv_recenter(ref, v) : n - inv_recenter(n - ref, v);
 }
 
-int get_bits_subexp(GetBits *const c, const int ref, const unsigned n) {
+int dav1d_get_bits_subexp(GetBits *const c, const int ref, const unsigned n) {
     return (int) get_bits_subexp_u(c, ref + (1 << n), 2 << n) - (1 << n);
 }
 
-const uint8_t *flush_get_bits(GetBits *c) {
+const uint8_t *dav1d_flush_get_bits(GetBits *c) {
     c->bits_left = 0;
     c->state = 0;
     return c->ptr;
--- a/src/getbits.h
+++ b/src/getbits.h
@@ -38,12 +38,12 @@
     const uint8_t *ptr, *ptr_start, *ptr_end;
 } GetBits;
 
-void init_get_bits(GetBits *c, const uint8_t *data, size_t sz);
-unsigned get_bits(GetBits *c, unsigned n);
-int get_sbits(GetBits *c, unsigned n);
-unsigned get_uniform(GetBits *c, unsigned range);
-unsigned get_vlc(GetBits *c);
-int get_bits_subexp(GetBits *c, int ref, unsigned n);
-const uint8_t *flush_get_bits(GetBits *c);
+void dav1d_init_get_bits(GetBits *c, const uint8_t *data, size_t sz);
+unsigned dav1d_get_bits(GetBits *c, unsigned n);
+int dav1d_get_sbits(GetBits *c, unsigned n);
+unsigned dav1d_get_uniform(GetBits *c, unsigned range);
+unsigned dav1d_get_vlc(GetBits *c);
+int dav1d_get_bits_subexp(GetBits *c, int ref, unsigned n);
+const uint8_t *dav1d_flush_get_bits(GetBits *c);
 
 #endif /* __DAV1D_SRC_GETBITS_H__ */
--- a/src/intra_edge.c
+++ b/src/intra_edge.c
@@ -137,8 +137,8 @@
     }
 }
 
-void init_mode_tree(EdgeNode *const root_node, EdgeTip *const nt,
-                    const int allow_sb128)
+void dav1d_init_mode_tree(EdgeNode *const root_node, EdgeTip *const nt,
+                          const int allow_sb128)
 {
     EdgeBranch *const root = (EdgeBranch *) root_node;
     struct ModeSelMem mem;
--- a/src/intra_edge.h
+++ b/src/intra_edge.h
@@ -51,7 +51,7 @@
     EdgeNode *split[4];
 } EdgeBranch;
 
-void init_mode_tree(EdgeNode *const root, EdgeTip *const nt,
-                    const int allow_sb128);
+void dav1d_init_mode_tree(EdgeNode *const root, EdgeTip *const nt,
+                          const int allow_sb128);
 
 #endif /* __DAV1D_SRC_INTRA_EDGE_H__ */
--- a/src/ipred_prepare.c
+++ b/src/ipred_prepare.c
@@ -74,16 +74,16 @@
 };
 
 enum IntraPredMode
-bytefn(prepare_intra_edges)(const int x, const int have_left,
-                            const int y, const int have_top,
-                            const int w, const int h,
-                            const enum EdgeFlags edge_flags,
-                            const pixel *const dst,
-                            const ptrdiff_t stride,
-                            const pixel *prefilter_toplevel_sb_edge,
-                            enum IntraPredMode mode, int *const angle,
-                            const int tw, const int th,
-                            pixel *const topleft_out)
+bytefn(dav1d_prepare_intra_edges)(const int x, const int have_left,
+                                  const int y, const int have_top,
+                                  const int w, const int h,
+                                  const enum EdgeFlags edge_flags,
+                                  const pixel *const dst,
+                                  const ptrdiff_t stride,
+                                  const pixel *prefilter_toplevel_sb_edge,
+                                  enum IntraPredMode mode, int *const angle,
+                                  const int tw, const int th,
+                                  pixel *const topleft_out)
 {
     assert(y < h && x < w);
 
--- a/src/ipred_prepare.h
+++ b/src/ipred_prepare.h
@@ -76,12 +76,12 @@
  * they will be extended from nearby edges as defined by the av1 spec.
  */
 enum IntraPredMode
-    bytefn(prepare_intra_edges)(int x, int have_left, int y, int have_top,
-                                int w, int h, enum EdgeFlags edge_flags,
-                                const pixel *dst, ptrdiff_t stride,
-                                const pixel *prefilter_toplevel_sb_edge,
-                                enum IntraPredMode mode, int *angle,
-                                int tw, int th, pixel *topleft_out);
+    bytefn(dav1d_prepare_intra_edges)(int x, int have_left, int y, int have_top,
+                                      int w, int h, enum EdgeFlags edge_flags,
+                                      const pixel *dst, ptrdiff_t stride,
+                                      const pixel *prefilter_toplevel_sb_edge,
+                                      enum IntraPredMode mode, int *angle,
+                                      int tw, int th, pixel *topleft_out);
 
 // is or'ed with the angle argument into intra predictors to signal that edges
 // are smooth and should use reduced filter strength
--- a/src/lf_mask.c
+++ b/src/lf_mask.c
@@ -42,7 +42,7 @@
                       const int y_off, const int x_off,
                       const uint16_t *const tx_masks)
 {
-    const TxfmInfo *const t_dim = &av1_txfm_dimensions[from];
+    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[from];
     int is_split;
 
     if (depth > 1) {
@@ -87,7 +87,7 @@
                                     const uint16_t *const tx_masks,
                                     uint8_t *const a, uint8_t *const l)
 {
-    const TxfmInfo *const t_dim = &av1_txfm_dimensions[max_tx];
+    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[max_tx];
     int y, x;
 
     uint8_t txa[2 /* edge */][2 /* txsz, step */][32 /* y */][32 /* x */];
@@ -151,7 +151,7 @@
                                     const enum RectTxfmSize tx,
                                     uint8_t *const a, uint8_t *const l)
 {
-    const TxfmInfo *const t_dim = &av1_txfm_dimensions[tx];
+    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
     const int twl4 = t_dim->lw, thl4 = t_dim->lh;
     const int twl4c = imin(2, twl4), thl4c = imin(2, thl4);
     int y, x;
@@ -194,7 +194,7 @@
                                      const enum RectTxfmSize tx,
                                      uint8_t *const a, uint8_t *const l)
 {
-    const TxfmInfo *const t_dim = &av1_txfm_dimensions[tx];
+    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
     const int twl4 = t_dim->lw, thl4 = t_dim->lh;
     const int twl4c = !!twl4, thl4c = !!thl4;
     int y, x;
@@ -249,7 +249,7 @@
     if (!hdr->loopfilter.level_y[0] && !hdr->loopfilter.level_y[1])
         return;
 
-    const uint8_t *const b_dim = av1_block_dimensions[bs];
+    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
     const int bw4 = imin(iw - bx, b_dim[0]);
     const int bh4 = imin(ih - by, b_dim[1]);
     const int bx4 = bx & 31;
@@ -297,7 +297,7 @@
     if (!hdr->loopfilter.level_y[0] && !hdr->loopfilter.level_y[1])
         return;
 
-    const uint8_t *const b_dim = av1_block_dimensions[bs];
+    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
     const int bw4 = imin(iw - bx, b_dim[0]);
     const int bh4 = imin(ih - by, b_dim[1]);
     const int bx4 = bx & 31;
@@ -315,7 +315,7 @@
     }
 
     mask_edges_inter(lflvl->filter_y, by4, bx4, bw4, bh4, skip,
-                     av1_max_txfm_size_for_bs[bs][0], tx_masks, ay, ly);
+                     dav1d_max_txfm_size_for_bs[bs][0], tx_masks, ay, ly);
 
     if (!auv) return;
 
--- a/src/lib.c
+++ b/src/lib.c
@@ -45,9 +45,9 @@
 #include "src/wedge.h"
 
 static void init_internal(void) {
-    av1_init_wedge_masks();
-    av1_init_interintra_masks();
-    av1_init_qm_tables();
+    dav1d_init_wedge_masks();
+    dav1d_init_interintra_masks();
+    dav1d_init_qm_tables();
 }
 
 const char *dav1d_version(void) {
@@ -129,9 +129,9 @@
 
     // intra edge tree
     c->intra_edge.root[BL_128X128] = &c->intra_edge.branch_sb128[0].node;
-    init_mode_tree(c->intra_edge.root[BL_128X128], c->intra_edge.tip_sb128, 1);
+    dav1d_init_mode_tree(c->intra_edge.root[BL_128X128], c->intra_edge.tip_sb128, 1);
     c->intra_edge.root[BL_64X64] = &c->intra_edge.branch_sb64[0].node;
-    init_mode_tree(c->intra_edge.root[BL_64X64], c->intra_edge.tip_sb64, 0);
+    dav1d_init_mode_tree(c->intra_edge.root[BL_64X64], c->intra_edge.tip_sb64, 0);
 
     return 0;
 
@@ -190,7 +190,7 @@
     }
 
     while (in->sz > 0) {
-        if ((res = parse_obus(c, in)) < 0)
+        if ((res = dav1d_parse_obus(c, in)) < 0)
             return res;
 
         assert(res <= in->sz);
@@ -301,7 +301,7 @@
         dav1d_data_unref(&c->tile[n].data);
     for (int n = 0; n < 8; n++) {
         if (c->cdf[n].cdf)
-            cdf_thread_unref(&c->cdf[n]);
+            dav1d_cdf_thread_unref(&c->cdf[n]);
         if (c->refs[n].p.p.data[0])
             dav1d_thread_picture_unref(&c->refs[n].p);
         if (c->refs[n].refmvs)
--- a/src/looprestoration.c
+++ b/src/looprestoration.c
@@ -424,9 +424,9 @@
             const uint32_t p = (a * n >= b * b) * (a * n - b * b);
             const uint32_t z = (p * s + (1 << 19)) >> 20;
 
-            const int x = sgr_x_by_xplus1[imin(z, 255)];
+            const int x = dav1d_sgr_x_by_xplus1[imin(z, 255)];
             // This is where we invert A and B, so that B is of size coef.
-            AA[i] = (((1 << 8) - x) * BB[i] * sgr_one_by_x[n - 1] + (1 << 11)) >> 12;
+            AA[i] = (((1 << 8) - x) * BB[i] * dav1d_sgr_one_by_x[n - 1] + (1 << 11)) >> 12;
             BB[i] = x;
         }
         AA += step * REST_UNIT_STRIDE;
@@ -504,8 +504,8 @@
     int32_t dst[64 * 384];
 
     // both r1 and r0 can't be zero
-    if (!sgr_params[sgr_idx][0]) {
-        const int s1 = sgr_params[sgr_idx][3];
+    if (!dav1d_sgr_params[sgr_idx][0]) {
+        const int s1 = dav1d_sgr_params[sgr_idx][3];
         selfguided_filter(dst, tmp, REST_UNIT_STRIDE, w, h, 9, s1);
         const int w1 = (1 << 7) - sgr_w[1];
         for (int j = 0; j < h; j++) {
@@ -516,8 +516,8 @@
             }
             p += PXSTRIDE(p_stride);
         }
-    } else if (!sgr_params[sgr_idx][1]) {
-        const int s0 = sgr_params[sgr_idx][2];
+    } else if (!dav1d_sgr_params[sgr_idx][1]) {
+        const int s0 = dav1d_sgr_params[sgr_idx][2];
         selfguided_filter(dst, tmp, REST_UNIT_STRIDE, w, h, 25, s0);
         const int w0 = sgr_w[0];
         for (int j = 0; j < h; j++) {
@@ -530,8 +530,8 @@
         }
     } else {
         int32_t dst1[64 * 384];
-        const int s0 = sgr_params[sgr_idx][2];
-        const int s1 = sgr_params[sgr_idx][3];
+        const int s0 = dav1d_sgr_params[sgr_idx][2];
+        const int s1 = dav1d_sgr_params[sgr_idx][3];
         const int w0 = sgr_w[0];
         const int w1 = (1 << 7) - w0 - sgr_w[1];
         selfguided_filter(dst, tmp, REST_UNIT_STRIDE, w, h, 25, s0);
--- a/src/obu.c
+++ b/src/obu.c
@@ -49,7 +49,7 @@
 
 #define DEBUG_SEQ_HDR 0
 
-    hdr->profile = get_bits(gb, 3);
+    hdr->profile = dav1d_get_bits(gb, 3);
     if (hdr->profile > 2) goto error;
 #if DEBUG_SEQ_HDR
     printf("SEQHDR: post-profile: off=%ld\n",
@@ -56,8 +56,8 @@
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
 #endif
 
-    hdr->still_picture = get_bits(gb, 1);
-    hdr->reduced_still_picture_header = get_bits(gb, 1);
+    hdr->still_picture = dav1d_get_bits(gb, 1);
+    hdr->reduced_still_picture_header = dav1d_get_bits(gb, 1);
     if (hdr->reduced_still_picture_header && !hdr->still_picture) goto error;
 #if DEBUG_SEQ_HDR
     printf("SEQHDR: post-stillpicture_flags: off=%ld\n",
@@ -70,28 +70,28 @@
         hdr->display_model_info_present = 0;
         hdr->num_operating_points = 1;
         hdr->operating_points[0].idc = 0;
-        hdr->operating_points[0].major_level = get_bits(gb, 3);
-        hdr->operating_points[0].minor_level = get_bits(gb, 2);
+        hdr->operating_points[0].major_level = dav1d_get_bits(gb, 3);
+        hdr->operating_points[0].minor_level = dav1d_get_bits(gb, 2);
         hdr->operating_points[0].tier = 0;
         hdr->operating_points[0].decoder_model_param_present = 0;
         hdr->operating_points[0].display_model_param_present = 0;
     } else {
-        hdr->timing_info_present = get_bits(gb, 1);
+        hdr->timing_info_present = dav1d_get_bits(gb, 1);
         if (hdr->timing_info_present) {
-            hdr->num_units_in_tick = get_bits(gb, 32);
-            hdr->time_scale = get_bits(gb, 32);
-            hdr->equal_picture_interval = get_bits(gb, 1);
+            hdr->num_units_in_tick = dav1d_get_bits(gb, 32);
+            hdr->time_scale = dav1d_get_bits(gb, 32);
+            hdr->equal_picture_interval = dav1d_get_bits(gb, 1);
             if (hdr->equal_picture_interval)
-                hdr->num_ticks_per_picture = get_vlc(gb) + 1;
+                hdr->num_ticks_per_picture = dav1d_get_vlc(gb) + 1;
 
-            hdr->decoder_model_info_present = get_bits(gb, 1);
+            hdr->decoder_model_info_present = dav1d_get_bits(gb, 1);
             if (hdr->decoder_model_info_present) {
-                hdr->bitrate_scale = get_bits(gb, 4);
-                hdr->buffer_size_scale = get_bits(gb, 4);
-                hdr->encoder_decoder_buffer_delay_length = get_bits(gb, 5) + 1;
-                hdr->num_units_in_decoding_tick = get_bits(gb, 32);
-                hdr->buffer_removal_delay_length = get_bits(gb, 5) + 1;
-                hdr->frame_presentation_delay_length = get_bits(gb, 5) + 1;
+                hdr->bitrate_scale = dav1d_get_bits(gb, 4);
+                hdr->buffer_size_scale = dav1d_get_bits(gb, 4);
+                hdr->encoder_decoder_buffer_delay_length = dav1d_get_bits(gb, 5) + 1;
+                hdr->num_units_in_decoding_tick = dav1d_get_bits(gb, 32);
+                hdr->buffer_removal_delay_length = dav1d_get_bits(gb, 5) + 1;
+                hdr->frame_presentation_delay_length = dav1d_get_bits(gb, 5) + 1;
             }
         } else {
             hdr->decoder_model_info_present = 0;
@@ -101,31 +101,31 @@
                (gb->ptr - init_ptr) * 8 - gb->bits_left);
 #endif
 
-        hdr->display_model_info_present = get_bits(gb, 1);
-        hdr->num_operating_points = get_bits(gb, 5) + 1;
+        hdr->display_model_info_present = dav1d_get_bits(gb, 1);
+        hdr->num_operating_points = dav1d_get_bits(gb, 5) + 1;
         for (int i = 0; i < c->seq_hdr.num_operating_points; i++) {
             struct Av1SequenceHeaderOperatingPoint *const op =
                 &hdr->operating_points[i];
-            op->idc = get_bits(gb, 12);
-            op->major_level = 2 + get_bits(gb, 3);
-            op->minor_level = get_bits(gb, 2);
-            op->tier = op->major_level > 3 ? get_bits(gb, 1) : 0;
+            op->idc = dav1d_get_bits(gb, 12);
+            op->major_level = 2 + dav1d_get_bits(gb, 3);
+            op->minor_level = dav1d_get_bits(gb, 2);
+            op->tier = op->major_level > 3 ? dav1d_get_bits(gb, 1) : 0;
             op->decoder_model_param_present =
-                hdr->decoder_model_info_present && get_bits(gb, 1);
+                hdr->decoder_model_info_present && dav1d_get_bits(gb, 1);
             if (op->decoder_model_param_present) {
-                op->bitrate = get_vlc(gb) + 1;
-                op->buffer_size = get_vlc(gb) + 1;
-                op->cbr = get_bits(gb, 1);
+                op->bitrate = dav1d_get_vlc(gb) + 1;
+                op->buffer_size = dav1d_get_vlc(gb) + 1;
+                op->cbr = dav1d_get_bits(gb, 1);
                 op->decoder_buffer_delay =
-                    get_bits(gb, hdr->encoder_decoder_buffer_delay_length);
+                    dav1d_get_bits(gb, hdr->encoder_decoder_buffer_delay_length);
                 op->encoder_buffer_delay =
-                    get_bits(gb, hdr->encoder_decoder_buffer_delay_length);
-                op->low_delay_mode = get_bits(gb, 1);
+                    dav1d_get_bits(gb, hdr->encoder_decoder_buffer_delay_length);
+                op->low_delay_mode = dav1d_get_bits(gb, 1);
             }
             op->display_model_param_present =
-                hdr->display_model_info_present && get_bits(gb, 1);
+                hdr->display_model_info_present && dav1d_get_bits(gb, 1);
             if (op->display_model_param_present) {
-                op->initial_display_delay = get_bits(gb, 4) + 1;
+                op->initial_display_delay = dav1d_get_bits(gb, 4) + 1;
             }
         }
 #if DEBUG_SEQ_HDR
@@ -134,19 +134,19 @@
 #endif
     }
 
-    hdr->width_n_bits = get_bits(gb, 4) + 1;
-    hdr->height_n_bits = get_bits(gb, 4) + 1;
-    hdr->max_width = get_bits(gb, hdr->width_n_bits) + 1;
-    hdr->max_height = get_bits(gb, hdr->height_n_bits) + 1;
+    hdr->width_n_bits = dav1d_get_bits(gb, 4) + 1;
+    hdr->height_n_bits = dav1d_get_bits(gb, 4) + 1;
+    hdr->max_width = dav1d_get_bits(gb, hdr->width_n_bits) + 1;
+    hdr->max_height = dav1d_get_bits(gb, hdr->height_n_bits) + 1;
 #if DEBUG_SEQ_HDR
     printf("SEQHDR: post-size: off=%ld\n",
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
 #endif
     hdr->frame_id_numbers_present =
-        hdr->reduced_still_picture_header ? 0 : get_bits(gb, 1);
+        hdr->reduced_still_picture_header ? 0 : dav1d_get_bits(gb, 1);
     if (hdr->frame_id_numbers_present) {
-        hdr->delta_frame_id_n_bits = get_bits(gb, 4) + 2;
-        hdr->frame_id_n_bits = get_bits(gb, 3) + hdr->delta_frame_id_n_bits + 1;
+        hdr->delta_frame_id_n_bits = dav1d_get_bits(gb, 4) + 2;
+        hdr->frame_id_n_bits = dav1d_get_bits(gb, 3) + hdr->delta_frame_id_n_bits + 1;
     }
 #if DEBUG_SEQ_HDR
     printf("SEQHDR: post-frame-id-numbers-present: off=%ld\n",
@@ -153,9 +153,9 @@
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
 #endif
 
-    hdr->sb128 = get_bits(gb, 1);
-    hdr->filter_intra = get_bits(gb, 1);
-    hdr->intra_edge_filter = get_bits(gb, 1);
+    hdr->sb128 = dav1d_get_bits(gb, 1);
+    hdr->filter_intra = dav1d_get_bits(gb, 1);
+    hdr->intra_edge_filter = dav1d_get_bits(gb, 1);
     if (hdr->reduced_still_picture_header) {
         hdr->inter_intra = 0;
         hdr->masked_compound = 0;
@@ -168,46 +168,46 @@
         hdr->screen_content_tools = ADAPTIVE;
         hdr->force_integer_mv = ADAPTIVE;
     } else {
-        hdr->inter_intra = get_bits(gb, 1);
-        hdr->masked_compound = get_bits(gb, 1);
-        hdr->warped_motion = get_bits(gb, 1);
-        hdr->dual_filter = get_bits(gb, 1);
-        hdr->order_hint = get_bits(gb, 1);
+        hdr->inter_intra = dav1d_get_bits(gb, 1);
+        hdr->masked_compound = dav1d_get_bits(gb, 1);
+        hdr->warped_motion = dav1d_get_bits(gb, 1);
+        hdr->dual_filter = dav1d_get_bits(gb, 1);
+        hdr->order_hint = dav1d_get_bits(gb, 1);
         if (hdr->order_hint) {
-            hdr->jnt_comp = get_bits(gb, 1);
-            hdr->ref_frame_mvs = get_bits(gb, 1);
+            hdr->jnt_comp = dav1d_get_bits(gb, 1);
+            hdr->ref_frame_mvs = dav1d_get_bits(gb, 1);
         } else {
             hdr->jnt_comp = 0;
             hdr->ref_frame_mvs = 0;
             hdr->order_hint_n_bits = 0;
         }
-        hdr->screen_content_tools = get_bits(gb, 1) ? ADAPTIVE : get_bits(gb, 1);
+        hdr->screen_content_tools = dav1d_get_bits(gb, 1) ? ADAPTIVE : dav1d_get_bits(gb, 1);
     #if DEBUG_SEQ_HDR
         printf("SEQHDR: post-screentools: off=%ld\n",
                (gb->ptr - init_ptr) * 8 - gb->bits_left);
     #endif
         hdr->force_integer_mv = hdr->screen_content_tools ?
-                                get_bits(gb, 1) ? ADAPTIVE : get_bits(gb, 1) : 2;
+                                dav1d_get_bits(gb, 1) ? ADAPTIVE : dav1d_get_bits(gb, 1) : 2;
         if (hdr->order_hint)
-            hdr->order_hint_n_bits = get_bits(gb, 3) + 1;
+            hdr->order_hint_n_bits = dav1d_get_bits(gb, 3) + 1;
     }
-    hdr->super_res = get_bits(gb, 1);
-    hdr->cdef = get_bits(gb, 1);
-    hdr->restoration = get_bits(gb, 1);
+    hdr->super_res = dav1d_get_bits(gb, 1);
+    hdr->cdef = dav1d_get_bits(gb, 1);
+    hdr->restoration = dav1d_get_bits(gb, 1);
 #if DEBUG_SEQ_HDR
     printf("SEQHDR: post-featurebits: off=%ld\n",
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
 #endif
 
-    const int hbd = get_bits(gb, 1);
-    hdr->bpc = hdr->profile == 2 && hbd ? 10 + 2 * get_bits(gb, 1): 8 + 2 * hbd;
+    const int hbd = dav1d_get_bits(gb, 1);
+    hdr->bpc = hdr->profile == 2 && hbd ? 10 + 2 * dav1d_get_bits(gb, 1): 8 + 2 * hbd;
     hdr->hbd = hdr->bpc > 8;
-    const int monochrome = hdr->profile != 1 ? get_bits(gb, 1) : 0;
-    hdr->color_description_present = get_bits(gb, 1);
+    const int monochrome = hdr->profile != 1 ? dav1d_get_bits(gb, 1) : 0;
+    hdr->color_description_present = dav1d_get_bits(gb, 1);
     if (hdr->color_description_present) {
-        hdr->pri = get_bits(gb, 8);
-        hdr->trc = get_bits(gb, 8);
-        hdr->mtrx = get_bits(gb, 8);
+        hdr->pri = dav1d_get_bits(gb, 8);
+        hdr->trc = dav1d_get_bits(gb, 8);
+        hdr->mtrx = dav1d_get_bits(gb, 8);
     } else {
         hdr->pri = DAV1D_COLOR_PRI_UNKNOWN;
         hdr->trc = DAV1D_TRC_UNKNOWN;
@@ -214,7 +214,7 @@
         hdr->mtrx = DAV1D_MC_UNKNOWN;
     }
     if (monochrome) {
-        hdr->color_range = get_bits(gb, 1);
+        hdr->color_range = dav1d_get_bits(gb, 1);
         hdr->layout = DAV1D_PIXEL_LAYOUT_I400;
         hdr->chr = DAV1D_CHR_UNKNOWN;
         hdr->separate_uv_delta_q = 0;
@@ -227,23 +227,23 @@
         if (hdr->profile != 1 && !(hdr->profile == 2 && hdr->bpc == 12))
             goto error;
     } else {
-        hdr->color_range = get_bits(gb, 1);
+        hdr->color_range = dav1d_get_bits(gb, 1);
         switch (hdr->profile) {
         case 0: hdr->layout = DAV1D_PIXEL_LAYOUT_I420; break;
         case 1: hdr->layout = DAV1D_PIXEL_LAYOUT_I444; break;
         case 2:
             if (hdr->bpc == 12) {
-                hdr->layout = get_bits(gb, 1) ?
-                              get_bits(gb, 1) ? DAV1D_PIXEL_LAYOUT_I420 :
-                                                DAV1D_PIXEL_LAYOUT_I422 :
-                                                DAV1D_PIXEL_LAYOUT_I444;
+                hdr->layout = dav1d_get_bits(gb, 1) ?
+                              dav1d_get_bits(gb, 1) ? DAV1D_PIXEL_LAYOUT_I420 :
+                                                      DAV1D_PIXEL_LAYOUT_I422 :
+                                                      DAV1D_PIXEL_LAYOUT_I444;
             } else
                 hdr->layout = DAV1D_PIXEL_LAYOUT_I422;
             break;
         }
         if (hdr->layout == DAV1D_PIXEL_LAYOUT_I420)
-            hdr->chr = get_bits(gb, 2);
-        hdr->separate_uv_delta_q = get_bits(gb, 1);
+            hdr->chr = dav1d_get_bits(gb, 2);
+        hdr->separate_uv_delta_q = dav1d_get_bits(gb, 1);
     }
 #if DEBUG_SEQ_HDR
     printf("SEQHDR: post-colorinfo: off=%ld\n",
@@ -250,15 +250,15 @@
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
 #endif
 
-    c->seq_hdr.film_grain_present = get_bits(gb, 1);
+    c->seq_hdr.film_grain_present = dav1d_get_bits(gb, 1);
 #if DEBUG_SEQ_HDR
     printf("SEQHDR: post-filmgrain: off=%ld\n",
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
 #endif
 
-    get_bits(gb, 1); // dummy bit
+    dav1d_get_bits(gb, 1); // dummy bit
 
-    return flush_get_bits(gb) - init_ptr;
+    return dav1d_flush_get_bits(gb) - init_ptr;
 
 error:
     fprintf(stderr, "Error parsing sequence header\n");
@@ -273,7 +273,7 @@
 
     if (use_ref) {
         for (int i = 0; i < 7; i++) {
-            if (get_bits(gb, 1)) {
+            if (dav1d_get_bits(gb, 1)) {
                 Dav1dThreadPicture *const ref =
                     &c->refs[c->frame_hdr.refidx[i]].p;
                 if (!ref->p.data[0]) return -1;
@@ -287,18 +287,18 @@
     }
 
     if (hdr->frame_size_override) {
-        hdr->width = get_bits(gb, seqhdr->width_n_bits) + 1;
-        hdr->height = get_bits(gb, seqhdr->height_n_bits) + 1;
+        hdr->width = dav1d_get_bits(gb, seqhdr->width_n_bits) + 1;
+        hdr->height = dav1d_get_bits(gb, seqhdr->height_n_bits) + 1;
     } else {
         hdr->width = seqhdr->max_width;
         hdr->height = seqhdr->max_height;
     }
-    hdr->super_res = seqhdr->super_res && get_bits(gb, 1);
+    hdr->super_res = seqhdr->super_res && dav1d_get_bits(gb, 1);
     if (hdr->super_res) return -1; // FIXME
-    hdr->have_render_size = get_bits(gb, 1);
+    hdr->have_render_size = dav1d_get_bits(gb, 1);
     if (hdr->have_render_size) {
-        hdr->render_width = get_bits(gb, seqhdr->width_n_bits) + 1;
-        hdr->render_height = get_bits(gb, seqhdr->height_n_bits) + 1;
+        hdr->render_width = dav1d_get_bits(gb, seqhdr->width_n_bits) + 1;
+        hdr->render_height = dav1d_get_bits(gb, seqhdr->height_n_bits) + 1;
     } else {
         hdr->render_width = hdr->width;
         hdr->render_height = hdr->height;
@@ -328,89 +328,89 @@
 #define DEBUG_FRAME_HDR 0
 
     hdr->show_existing_frame =
-        !seqhdr->reduced_still_picture_header && get_bits(gb, 1);
+        !seqhdr->reduced_still_picture_header && dav1d_get_bits(gb, 1);
 #if DEBUG_FRAME_HDR
     printf("HDR: post-show_existing_frame: off=%ld\n",
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
 #endif
     if (hdr->show_existing_frame) {
-        hdr->existing_frame_idx = get_bits(gb, 3);
+        hdr->existing_frame_idx = dav1d_get_bits(gb, 3);
         if (seqhdr->frame_id_numbers_present)
-            hdr->frame_id = get_bits(gb, seqhdr->frame_id_n_bits);
+            hdr->frame_id = dav1d_get_bits(gb, seqhdr->frame_id_n_bits);
         goto end;
     }
 
-    hdr->frame_type = seqhdr->reduced_still_picture_header ? DAV1D_FRAME_TYPE_KEY : get_bits(gb, 2);
-    hdr->show_frame = seqhdr->reduced_still_picture_header || get_bits(gb, 1);
+    hdr->frame_type = seqhdr->reduced_still_picture_header ? DAV1D_FRAME_TYPE_KEY : dav1d_get_bits(gb, 2);
+    hdr->show_frame = seqhdr->reduced_still_picture_header || dav1d_get_bits(gb, 1);
     if (!hdr->show_frame)
-        hdr->showable_frame = get_bits(gb, 1);
+        hdr->showable_frame = dav1d_get_bits(gb, 1);
     hdr->error_resilient_mode =
         (hdr->frame_type == DAV1D_FRAME_TYPE_KEY && hdr->show_frame) ||
         hdr->frame_type == DAV1D_FRAME_TYPE_SWITCH ||
-        seqhdr->reduced_still_picture_header || get_bits(gb, 1);
+        seqhdr->reduced_still_picture_header || dav1d_get_bits(gb, 1);
 #if DEBUG_FRAME_HDR
     printf("HDR: post-frametype_bits: off=%ld\n",
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
 #endif
-    hdr->disable_cdf_update = get_bits(gb, 1);
+    hdr->disable_cdf_update = dav1d_get_bits(gb, 1);
     hdr->allow_screen_content_tools = seqhdr->screen_content_tools == ADAPTIVE ?
-                                 get_bits(gb, 1) : seqhdr->screen_content_tools;
+                                 dav1d_get_bits(gb, 1) : seqhdr->screen_content_tools;
     if (hdr->allow_screen_content_tools)
         hdr->force_integer_mv = seqhdr->force_integer_mv == ADAPTIVE ?
-                                get_bits(gb, 1) : seqhdr->force_integer_mv;
+                                dav1d_get_bits(gb, 1) : seqhdr->force_integer_mv;
 
     if (seqhdr->frame_id_numbers_present)
-        hdr->frame_id = get_bits(gb, seqhdr->frame_id_n_bits);
+        hdr->frame_id = dav1d_get_bits(gb, seqhdr->frame_id_n_bits);
 
     hdr->frame_size_override = seqhdr->reduced_still_picture_header ? 0 :
-                               hdr->frame_type == DAV1D_FRAME_TYPE_SWITCH ? 1 : get_bits(gb, 1);
+                               hdr->frame_type == DAV1D_FRAME_TYPE_SWITCH ? 1 : dav1d_get_bits(gb, 1);
 #if DEBUG_FRAME_HDR
     printf("HDR: post-frame_size_override_flag: off=%ld\n",
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
 #endif
     hdr->frame_offset = seqhdr->order_hint ?
-                        get_bits(gb, seqhdr->order_hint_n_bits) : 0;
+                        dav1d_get_bits(gb, seqhdr->order_hint_n_bits) : 0;
     hdr->primary_ref_frame = !hdr->error_resilient_mode && hdr->frame_type & 1 ?
-                             get_bits(gb, 3) : PRIMARY_REF_NONE;
+                             dav1d_get_bits(gb, 3) : PRIMARY_REF_NONE;
 
     if (hdr->frame_type == DAV1D_FRAME_TYPE_KEY) {
-        hdr->refresh_frame_flags = hdr->show_frame ? 0xff : get_bits(gb, 8);
+        hdr->refresh_frame_flags = hdr->show_frame ? 0xff : dav1d_get_bits(gb, 8);
         if ((res = read_frame_size(c, gb, 0)) < 0) goto error;
         hdr->allow_intrabc = hdr->allow_screen_content_tools &&
-                             /* FIXME: no superres scaling && */ get_bits(gb, 1);
+                             /* FIXME: no superres scaling && */ dav1d_get_bits(gb, 1);
         hdr->use_ref_frame_mvs = 0;
     } else {
         if (hdr->error_resilient_mode && seqhdr->order_hint)
             for (int i = 0; i < 8; i++)
-                get_bits(gb, seqhdr->order_hint_n_bits);
+                dav1d_get_bits(gb, seqhdr->order_hint_n_bits);
 
         if (hdr->frame_type == DAV1D_FRAME_TYPE_INTRA) {
-            hdr->refresh_frame_flags = get_bits(gb, 8);
+            hdr->refresh_frame_flags = dav1d_get_bits(gb, 8);
             if ((res = read_frame_size(c, gb, 0)) < 0) goto error;
             hdr->allow_intrabc = hdr->allow_screen_content_tools &&
-                             /* FIXME: no superres scaling && */ get_bits(gb, 1);
+                             /* FIXME: no superres scaling && */ dav1d_get_bits(gb, 1);
         } else {
             hdr->allow_intrabc = 0;
             hdr->refresh_frame_flags = hdr->frame_type == DAV1D_FRAME_TYPE_SWITCH ? 0xff :
-                                       get_bits(gb, 8);
+                                       dav1d_get_bits(gb, 8);
             hdr->frame_ref_short_signaling =
-                seqhdr->order_hint && get_bits(gb, 1);
+                seqhdr->order_hint && dav1d_get_bits(gb, 1);
             if (hdr->frame_ref_short_signaling) goto error; // FIXME
             for (int i = 0; i < 7; i++) {
-                hdr->refidx[i] = get_bits(gb, 3);
+                hdr->refidx[i] = dav1d_get_bits(gb, 3);
                 if (seqhdr->frame_id_numbers_present)
-                    get_bits(gb, seqhdr->delta_frame_id_n_bits);
+                    dav1d_get_bits(gb, seqhdr->delta_frame_id_n_bits);
             }
             const int use_ref = !hdr->error_resilient_mode &&
                                 hdr->frame_size_override;
             if ((res = read_frame_size(c, gb, use_ref)) < 0) goto error;
-            hdr->hp = !hdr->force_integer_mv && get_bits(gb, 1);
-            hdr->subpel_filter_mode = get_bits(gb, 1) ? FILTER_SWITCHABLE :
-                                                        get_bits(gb, 2);
-            hdr->switchable_motion_mode = get_bits(gb, 1);
+            hdr->hp = !hdr->force_integer_mv && dav1d_get_bits(gb, 1);
+            hdr->subpel_filter_mode = dav1d_get_bits(gb, 1) ? FILTER_SWITCHABLE :
+                                                              dav1d_get_bits(gb, 2);
+            hdr->switchable_motion_mode = dav1d_get_bits(gb, 1);
             hdr->use_ref_frame_mvs = !hdr->error_resilient_mode &&
                 seqhdr->ref_frame_mvs && seqhdr->order_hint &&
-                hdr->frame_type & 1 && get_bits(gb, 1);
+                hdr->frame_type & 1 && dav1d_get_bits(gb, 1);
         }
     }
 #if DEBUG_FRAME_HDR
@@ -419,7 +419,7 @@
 #endif
 
     hdr->refresh_context = !seqhdr->reduced_still_picture_header &&
-                           !hdr->disable_cdf_update && !get_bits(gb, 1);
+                           !hdr->disable_cdf_update && !dav1d_get_bits(gb, 1);
 #if DEBUG_FRAME_HDR
     printf("HDR: post-refresh_context: off=%ld\n",
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
@@ -426,7 +426,7 @@
 #endif
 
     // tile data
-    hdr->tiling.uniform = get_bits(gb, 1);
+    hdr->tiling.uniform = dav1d_get_bits(gb, 1);
     const int sbsz_min1 = (64 << seqhdr->sb128) - 1;
     int sbsz_log2 = 6 + seqhdr->sb128;
     int sbw = (hdr->width + sbsz_min1) >> sbsz_log2;
@@ -440,7 +440,7 @@
                               hdr->tiling.min_log2_cols);
     if (hdr->tiling.uniform) {
         for (hdr->tiling.log2_cols = hdr->tiling.min_log2_cols;
-             hdr->tiling.log2_cols < hdr->tiling.max_log2_cols && get_bits(gb, 1);
+             hdr->tiling.log2_cols < hdr->tiling.max_log2_cols && dav1d_get_bits(gb, 1);
              hdr->tiling.log2_cols++) ;
         const int tile_w = 1 + ((sbw - 1) >> hdr->tiling.log2_cols);
         hdr->tiling.cols = 0;
@@ -451,7 +451,7 @@
         max_tile_height_sb = sbh >> hdr->tiling.min_log2_rows;
 
         for (hdr->tiling.log2_rows = hdr->tiling.min_log2_rows;
-             hdr->tiling.log2_rows < hdr->tiling.max_log2_rows && get_bits(gb, 1);
+             hdr->tiling.log2_rows < hdr->tiling.max_log2_rows && dav1d_get_bits(gb, 1);
              hdr->tiling.log2_rows++) ;
         const int tile_h = 1 + ((sbh - 1) >> hdr->tiling.log2_rows);
         hdr->tiling.rows = 0;
@@ -461,8 +461,8 @@
         hdr->tiling.cols = 0;
         int widest_tile = 0, max_tile_area_sb = sbw * sbh;
         for (int sbx = 0; sbx < sbw; hdr->tiling.cols++) {
-            const int tile_w = 1 + get_uniform(gb, imin(sbw - sbx,
-                                                        max_tile_width_sb));
+            const int tile_w = 1 + dav1d_get_uniform(gb, imin(sbw - sbx,
+                                                              max_tile_width_sb));
             hdr->tiling.col_start_sb[hdr->tiling.cols] = sbx;
             sbx += tile_w;
             widest_tile = imax(widest_tile, tile_w);
@@ -473,8 +473,8 @@
 
         hdr->tiling.rows = 0;
         for (int sby = 0; sby < sbh; hdr->tiling.rows++) {
-            const int tile_h = 1 + get_uniform(gb, imin(sbh - sby,
-                                                        max_tile_height_sb));
+            const int tile_h = 1 + dav1d_get_uniform(gb, imin(sbh - sby,
+                                                              max_tile_height_sb));
             hdr->tiling.row_start_sb[hdr->tiling.rows] = sby;
             sby += tile_h;
         }
@@ -483,9 +483,9 @@
     hdr->tiling.col_start_sb[hdr->tiling.cols] = sbw;
     hdr->tiling.row_start_sb[hdr->tiling.rows] = sbh;
     if (hdr->tiling.log2_cols || hdr->tiling.log2_rows) {
-        hdr->tiling.update = get_bits(gb, hdr->tiling.log2_cols +
-                                          hdr->tiling.log2_rows);
-        hdr->tiling.n_bytes = get_bits(gb, 2) + 1;
+        hdr->tiling.update = dav1d_get_bits(gb, hdr->tiling.log2_cols +
+                                                hdr->tiling.log2_rows);
+        hdr->tiling.n_bytes = dav1d_get_bits(gb, 2) + 1;
     } else {
         hdr->tiling.n_bytes = hdr->tiling.update = 0;
     }
@@ -495,14 +495,14 @@
 #endif
 
     // quant data
-    hdr->quant.yac = get_bits(gb, 8);
-    hdr->quant.ydc_delta = get_bits(gb, 1) ? get_sbits(gb, 6) : 0;
+    hdr->quant.yac = dav1d_get_bits(gb, 8);
+    hdr->quant.ydc_delta = dav1d_get_bits(gb, 1) ? dav1d_get_sbits(gb, 6) : 0;
     if (seqhdr->layout != DAV1D_PIXEL_LAYOUT_I400) {
-        hdr->quant.udc_delta = get_bits(gb, 1) ? get_sbits(gb, 6) : 0;
-        hdr->quant.uac_delta = get_bits(gb, 1) ? get_sbits(gb, 6) : 0;
+        hdr->quant.udc_delta = dav1d_get_bits(gb, 1) ? dav1d_get_sbits(gb, 6) : 0;
+        hdr->quant.uac_delta = dav1d_get_bits(gb, 1) ? dav1d_get_sbits(gb, 6) : 0;
         if (seqhdr->separate_uv_delta_q) {
-            hdr->quant.vdc_delta = get_bits(gb, 1) ? get_sbits(gb, 6) : 0;
-            hdr->quant.vac_delta = get_bits(gb, 1) ? get_sbits(gb, 6) : 0;
+            hdr->quant.vdc_delta = dav1d_get_bits(gb, 1) ? dav1d_get_sbits(gb, 6) : 0;
+            hdr->quant.vac_delta = dav1d_get_bits(gb, 1) ? dav1d_get_sbits(gb, 6) : 0;
         } else {
             hdr->quant.vdc_delta = hdr->quant.udc_delta;
             hdr->quant.vac_delta = hdr->quant.uac_delta;
@@ -512,11 +512,11 @@
     printf("HDR: post-quant: off=%ld\n",
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
 #endif
-    hdr->quant.qm = get_bits(gb, 1);
+    hdr->quant.qm = dav1d_get_bits(gb, 1);
     if (hdr->quant.qm) {
-        hdr->quant.qm_y = get_bits(gb, 4);
-        hdr->quant.qm_u = get_bits(gb, 4);
-        hdr->quant.qm_v = seqhdr->separate_uv_delta_q ? get_bits(gb, 4) :
+        hdr->quant.qm_y = dav1d_get_bits(gb, 4);
+        hdr->quant.qm_u = dav1d_get_bits(gb, 4);
+        hdr->quant.qm_v = seqhdr->separate_uv_delta_q ? dav1d_get_bits(gb, 4) :
                                                         hdr->quant.qm_u;
     }
 #if DEBUG_FRAME_HDR
@@ -525,7 +525,7 @@
 #endif
 
     // segmentation data
-    hdr->segmentation.enabled = get_bits(gb, 1);
+    hdr->segmentation.enabled = dav1d_get_bits(gb, 1);
     if (hdr->segmentation.enabled) {
         if (hdr->primary_ref_frame == PRIMARY_REF_NONE) {
             hdr->segmentation.update_map = 1;
@@ -532,10 +532,10 @@
             hdr->segmentation.temporal = 0;
             hdr->segmentation.update_data = 1;
         } else {
-            hdr->segmentation.update_map = get_bits(gb, 1);
+            hdr->segmentation.update_map = dav1d_get_bits(gb, 1);
             hdr->segmentation.temporal =
-                hdr->segmentation.update_map ? get_bits(gb, 1) : 0;
-            hdr->segmentation.update_data = get_bits(gb, 1);
+                hdr->segmentation.update_map ? dav1d_get_bits(gb, 1) : 0;
+            hdr->segmentation.update_data = dav1d_get_bits(gb, 1);
         }
 
         if (hdr->segmentation.update_data) {
@@ -544,48 +544,48 @@
             for (int i = 0; i < NUM_SEGMENTS; i++) {
                 Av1SegmentationData *const seg =
                     &hdr->segmentation.seg_data.d[i];
-                if (get_bits(gb, 1)) {
-                    seg->delta_q = get_sbits(gb, 8);
+                if (dav1d_get_bits(gb, 1)) {
+                    seg->delta_q = dav1d_get_sbits(gb, 8);
                     hdr->segmentation.seg_data.last_active_segid = i;
                 } else {
                     seg->delta_q = 0;
                 }
-                if (get_bits(gb, 1)) {
-                    seg->delta_lf_y_v = get_sbits(gb, 6);
+                if (dav1d_get_bits(gb, 1)) {
+                    seg->delta_lf_y_v = dav1d_get_sbits(gb, 6);
                     hdr->segmentation.seg_data.last_active_segid = i;
                 } else {
                     seg->delta_lf_y_v = 0;
                 }
-                if (get_bits(gb, 1)) {
-                    seg->delta_lf_y_h = get_sbits(gb, 6);
+                if (dav1d_get_bits(gb, 1)) {
+                    seg->delta_lf_y_h = dav1d_get_sbits(gb, 6);
                     hdr->segmentation.seg_data.last_active_segid = i;
                 } else {
                     seg->delta_lf_y_h = 0;
                 }
-                if (get_bits(gb, 1)) {
-                    seg->delta_lf_u = get_sbits(gb, 6);
+                if (dav1d_get_bits(gb, 1)) {
+                    seg->delta_lf_u = dav1d_get_sbits(gb, 6);
                     hdr->segmentation.seg_data.last_active_segid = i;
                 } else {
                     seg->delta_lf_u = 0;
                 }
-                if (get_bits(gb, 1)) {
-                    seg->delta_lf_v = get_sbits(gb, 6);
+                if (dav1d_get_bits(gb, 1)) {
+                    seg->delta_lf_v = dav1d_get_sbits(gb, 6);
                     hdr->segmentation.seg_data.last_active_segid = i;
                 } else {
                     seg->delta_lf_v = 0;
                 }
-                if (get_bits(gb, 1)) {
-                    seg->ref = get_bits(gb, 3);
+                if (dav1d_get_bits(gb, 1)) {
+                    seg->ref = dav1d_get_bits(gb, 3);
                     hdr->segmentation.seg_data.last_active_segid = i;
                     hdr->segmentation.seg_data.preskip = 1;
                 } else {
                     seg->ref = -1;
                 }
-                if ((seg->skip = get_bits(gb, 1))) {
+                if ((seg->skip = dav1d_get_bits(gb, 1))) {
                     hdr->segmentation.seg_data.last_active_segid = i;
                     hdr->segmentation.seg_data.preskip = 1;
                 }
-                if ((seg->globalmv = get_bits(gb, 1))) {
+                if ((seg->globalmv = dav1d_get_bits(gb, 1))) {
                     hdr->segmentation.seg_data.last_active_segid = i;
                     hdr->segmentation.seg_data.preskip = 1;
                 }
@@ -608,12 +608,12 @@
 #endif
 
     // delta q
-    hdr->delta.q.present = hdr->quant.yac ? get_bits(gb, 1) : 0;
-    hdr->delta.q.res_log2 = hdr->delta.q.present ? get_bits(gb, 2) : 0;
+    hdr->delta.q.present = hdr->quant.yac ? dav1d_get_bits(gb, 1) : 0;
+    hdr->delta.q.res_log2 = hdr->delta.q.present ? dav1d_get_bits(gb, 2) : 0;
     hdr->delta.lf.present = hdr->delta.q.present && !hdr->allow_intrabc &&
-                            get_bits(gb, 1);
-    hdr->delta.lf.res_log2 = hdr->delta.lf.present ? get_bits(gb, 2) : 0;
-    hdr->delta.lf.multi = hdr->delta.lf.present ? get_bits(gb, 1) : 0;
+                            dav1d_get_bits(gb, 1);
+    hdr->delta.lf.res_log2 = hdr->delta.lf.present ? dav1d_get_bits(gb, 2) : 0;
+    hdr->delta.lf.multi = hdr->delta.lf.present ? dav1d_get_bits(gb, 1) : 0;
 #if DEBUG_FRAME_HDR
     printf("HDR: post-delta_q_lf_flags: off=%ld\n",
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
@@ -641,15 +641,15 @@
         hdr->loopfilter.mode_ref_delta_update = 1;
         hdr->loopfilter.mode_ref_deltas = default_mode_ref_deltas;
     } else {
-        hdr->loopfilter.level_y[0] = get_bits(gb, 6);
-        hdr->loopfilter.level_y[1] = get_bits(gb, 6);
+        hdr->loopfilter.level_y[0] = dav1d_get_bits(gb, 6);
+        hdr->loopfilter.level_y[1] = dav1d_get_bits(gb, 6);
         if (seqhdr->layout != DAV1D_PIXEL_LAYOUT_I400 &&
             (hdr->loopfilter.level_y[0] || hdr->loopfilter.level_y[1]))
         {
-            hdr->loopfilter.level_u = get_bits(gb, 6);
-            hdr->loopfilter.level_v = get_bits(gb, 6);
+            hdr->loopfilter.level_u = dav1d_get_bits(gb, 6);
+            hdr->loopfilter.level_v = dav1d_get_bits(gb, 6);
         }
-        hdr->loopfilter.sharpness = get_bits(gb, 3);
+        hdr->loopfilter.sharpness = dav1d_get_bits(gb, 3);
 
         if (hdr->primary_ref_frame == PRIMARY_REF_NONE) {
             hdr->loopfilter.mode_ref_deltas = default_mode_ref_deltas;
@@ -657,18 +657,18 @@
             const int ref = hdr->refidx[hdr->primary_ref_frame];
             hdr->loopfilter.mode_ref_deltas = c->refs[ref].lf_mode_ref_deltas;
         }
-        hdr->loopfilter.mode_ref_delta_enabled = get_bits(gb, 1);
+        hdr->loopfilter.mode_ref_delta_enabled = dav1d_get_bits(gb, 1);
         if (hdr->loopfilter.mode_ref_delta_enabled) {
-            hdr->loopfilter.mode_ref_delta_update = get_bits(gb, 1);
+            hdr->loopfilter.mode_ref_delta_update = dav1d_get_bits(gb, 1);
             if (hdr->loopfilter.mode_ref_delta_update) {
                 for (int i = 0; i < 8; i++)
-                    if (get_bits(gb, 1))
+                    if (dav1d_get_bits(gb, 1))
                         hdr->loopfilter.mode_ref_deltas.ref_delta[i] =
-                            get_sbits(gb, 6);
+                            dav1d_get_sbits(gb, 6);
                 for (int i = 0; i < 2; i++)
-                    if (get_bits(gb, 1))
+                    if (dav1d_get_bits(gb, 1))
                         hdr->loopfilter.mode_ref_deltas.mode_delta[i] =
-                            get_sbits(gb, 6);
+                            dav1d_get_sbits(gb, 6);
             }
         }
     }
@@ -679,12 +679,12 @@
 
     // cdef
     if (!hdr->all_lossless && seqhdr->cdef && !hdr->allow_intrabc) {
-        hdr->cdef.damping = get_bits(gb, 2) + 3;
-        hdr->cdef.n_bits = get_bits(gb, 2);
+        hdr->cdef.damping = dav1d_get_bits(gb, 2) + 3;
+        hdr->cdef.n_bits = dav1d_get_bits(gb, 2);
         for (int i = 0; i < (1 << hdr->cdef.n_bits); i++) {
-            hdr->cdef.y_strength[i] = get_bits(gb, 6);
+            hdr->cdef.y_strength[i] = dav1d_get_bits(gb, 6);
             if (seqhdr->layout != DAV1D_PIXEL_LAYOUT_I400)
-                hdr->cdef.uv_strength[i] = get_bits(gb, 6);
+                hdr->cdef.uv_strength[i] = dav1d_get_bits(gb, 6);
         }
     } else {
         hdr->cdef.n_bits = 0;
@@ -698,10 +698,10 @@
 
     // restoration
     if (!hdr->all_lossless && seqhdr->restoration && !hdr->allow_intrabc) {
-        hdr->restoration.type[0] = get_bits(gb, 2);
+        hdr->restoration.type[0] = dav1d_get_bits(gb, 2);
         if (seqhdr->layout != DAV1D_PIXEL_LAYOUT_I400) {
-            hdr->restoration.type[1] = get_bits(gb, 2);
-            hdr->restoration.type[2] = get_bits(gb, 2);
+            hdr->restoration.type[1] = dav1d_get_bits(gb, 2);
+            hdr->restoration.type[2] = dav1d_get_bits(gb, 2);
         }
 
         if (hdr->restoration.type[0] || hdr->restoration.type[1] ||
@@ -709,16 +709,16 @@
         {
             // Log2 of the restoration unit size.
             hdr->restoration.unit_size[0] = 6 + seqhdr->sb128;
-            if (get_bits(gb, 1)) {
+            if (dav1d_get_bits(gb, 1)) {
                 hdr->restoration.unit_size[0]++;
                 if (!seqhdr->sb128)
-                    hdr->restoration.unit_size[0] += get_bits(gb, 1);
+                    hdr->restoration.unit_size[0] += dav1d_get_bits(gb, 1);
             }
             hdr->restoration.unit_size[1] = hdr->restoration.unit_size[0];
             if ((hdr->restoration.type[1] || hdr->restoration.type[2]) &&
                 seqhdr->layout == DAV1D_PIXEL_LAYOUT_I420)
             {
-                hdr->restoration.unit_size[1] -= get_bits(gb, 1);
+                hdr->restoration.unit_size[1] -= dav1d_get_bits(gb, 1);
             }
         } else {
             hdr->restoration.unit_size[0] = 8;
@@ -734,12 +734,12 @@
 #endif
 
     hdr->txfm_mode = hdr->all_lossless ? TX_4X4_ONLY :
-                     get_bits(gb, 1) ? TX_SWITCHABLE : TX_LARGEST;
+                     dav1d_get_bits(gb, 1) ? TX_SWITCHABLE : TX_LARGEST;
 #if DEBUG_FRAME_HDR
     printf("HDR: post-txfmmode: off=%ld\n",
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
 #endif
-    hdr->switchable_comp_refs = hdr->frame_type & 1 ? get_bits(gb, 1) : 0;
+    hdr->switchable_comp_refs = hdr->frame_type & 1 ? dav1d_get_bits(gb, 1) : 0;
 #if DEBUG_FRAME_HDR
     printf("HDR: post-refmode: off=%ld\n",
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
@@ -793,18 +793,18 @@
             hdr->skip_mode_allowed = 1;
         }
     }
-    hdr->skip_mode_enabled = hdr->skip_mode_allowed ? get_bits(gb, 1) : 0;
+    hdr->skip_mode_enabled = hdr->skip_mode_allowed ? dav1d_get_bits(gb, 1) : 0;
 #if DEBUG_FRAME_HDR
     printf("HDR: post-extskip: off=%ld\n",
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
 #endif
     hdr->warp_motion = !hdr->error_resilient_mode && hdr->frame_type & 1 &&
-        seqhdr->warped_motion && get_bits(gb, 1);
+        seqhdr->warped_motion && dav1d_get_bits(gb, 1);
 #if DEBUG_FRAME_HDR
     printf("HDR: post-warpmotionbit: off=%ld\n",
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
 #endif
-    hdr->reduced_txtp_set = get_bits(gb, 1);
+    hdr->reduced_txtp_set = dav1d_get_bits(gb, 1);
 #if DEBUG_FRAME_HDR
     printf("HDR: post-reducedtxtpset: off=%ld\n",
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
@@ -811,19 +811,19 @@
 #endif
 
     for (int i = 0; i < 7; i++)
-        hdr->gmv[i] = default_wm_params;
+        hdr->gmv[i] = dav1d_default_wm_params;
 
     if (hdr->frame_type & 1) {
         for (int i = 0; i < 7; i++) {
-            hdr->gmv[i].type = !get_bits(gb, 1) ? WM_TYPE_IDENTITY :
-                                get_bits(gb, 1) ? WM_TYPE_ROT_ZOOM :
-                                get_bits(gb, 1) ? WM_TYPE_TRANSLATION :
+            hdr->gmv[i].type = !dav1d_get_bits(gb, 1) ? WM_TYPE_IDENTITY :
+                                dav1d_get_bits(gb, 1) ? WM_TYPE_ROT_ZOOM :
+                                dav1d_get_bits(gb, 1) ? WM_TYPE_TRANSLATION :
                                                   WM_TYPE_AFFINE;
 
             if (hdr->gmv[i].type == WM_TYPE_IDENTITY) continue;
 
             const WarpedMotionParams *const ref_gmv =
-                hdr->primary_ref_frame == PRIMARY_REF_NONE ? &default_wm_params :
+                hdr->primary_ref_frame == PRIMARY_REF_NONE ? &dav1d_default_wm_params :
                 &c->refs[hdr->refidx[hdr->primary_ref_frame]].gmv[i];
             int32_t *const mat = hdr->gmv[i].matrix;
             const int32_t *const ref_mat = ref_gmv->matrix;
@@ -831,8 +831,8 @@
 
             if (hdr->gmv[i].type >= WM_TYPE_ROT_ZOOM) {
                 mat[2] = (1 << 16) + 2 *
-                    get_bits_subexp(gb, (ref_mat[2] - (1 << 16)) >> 1, 12);
-                mat[3] = 2 * get_bits_subexp(gb, ref_mat[3] >> 1, 12);
+                    dav1d_get_bits_subexp(gb, (ref_mat[2] - (1 << 16)) >> 1, 12);
+                mat[3] = 2 * dav1d_get_bits_subexp(gb, ref_mat[3] >> 1, 12);
 
                 bits = 12;
                 shift = 10;
@@ -842,18 +842,18 @@
             }
 
             if (hdr->gmv[i].type == WM_TYPE_AFFINE) {
-                mat[4] = 2 * get_bits_subexp(gb, ref_mat[4] >> 1, 12);
+                mat[4] = 2 * dav1d_get_bits_subexp(gb, ref_mat[4] >> 1, 12);
                 mat[5] = (1 << 16) + 2 *
-                    get_bits_subexp(gb, (ref_mat[5] - (1 << 16)) >> 1, 12);
+                    dav1d_get_bits_subexp(gb, (ref_mat[5] - (1 << 16)) >> 1, 12);
             } else {
                 mat[4] = -mat[3];
                 mat[5] = mat[2];
             }
 
-            mat[0] = get_bits_subexp(gb, ref_mat[0] >> shift, bits) * (1 << shift);
-            mat[1] = get_bits_subexp(gb, ref_mat[1] >> shift, bits) * (1 << shift);
+            mat[0] = dav1d_get_bits_subexp(gb, ref_mat[0] >> shift, bits) * (1 << shift);
+            mat[1] = dav1d_get_bits_subexp(gb, ref_mat[1] >> shift, bits) * (1 << shift);
 
-            if (get_shear_params(&hdr->gmv[i]))
+            if (dav1d_get_shear_params(&hdr->gmv[i]))
                 goto error;
         }
     }
@@ -864,12 +864,12 @@
 
     hdr->film_grain.present = seqhdr->film_grain_present &&
                               (hdr->show_frame || hdr->showable_frame) &&
-                              get_bits(gb, 1);
+                              dav1d_get_bits(gb, 1);
     if (hdr->film_grain.present) {
-        hdr->film_grain.seed = get_bits(gb, 16);
-        hdr->film_grain.update = hdr->frame_type != DAV1D_FRAME_TYPE_INTER || get_bits(gb, 1);
+        hdr->film_grain.seed = dav1d_get_bits(gb, 16);
+        hdr->film_grain.update = hdr->frame_type != DAV1D_FRAME_TYPE_INTER || dav1d_get_bits(gb, 1);
         if (!hdr->film_grain.update) {
-            const int refidx = get_bits(gb, 3);
+            const int refidx = dav1d_get_bits(gb, 3);
             int i;
             for (i = 0; i < 7; i++)
                 if (hdr->refidx[i] == refidx)
@@ -879,17 +879,17 @@
         } else {
             Av1FilmGrainData *const fgd = &hdr->film_grain.data;
 
-            fgd->num_y_points = get_bits(gb, 4);
+            fgd->num_y_points = dav1d_get_bits(gb, 4);
             if (fgd->num_y_points > 14) goto error;
             for (int i = 0; i < fgd->num_y_points; i++) {
-                fgd->y_points[i][0] = get_bits(gb, 8);
+                fgd->y_points[i][0] = dav1d_get_bits(gb, 8);
                 if (i && fgd->y_points[i - 1][0] >= fgd->y_points[i][0])
                     goto error;
-                fgd->y_points[i][1] = get_bits(gb, 8);
+                fgd->y_points[i][1] = dav1d_get_bits(gb, 8);
             }
 
             fgd->chroma_scaling_from_luma =
-                seqhdr->layout != DAV1D_PIXEL_LAYOUT_I400 && get_bits(gb, 1);
+                seqhdr->layout != DAV1D_PIXEL_LAYOUT_I400 && dav1d_get_bits(gb, 1);
             if (seqhdr->layout == DAV1D_PIXEL_LAYOUT_I400 ||
                 fgd->chroma_scaling_from_luma ||
                 (seqhdr->layout == DAV1D_PIXEL_LAYOUT_I420 && !fgd->num_y_points))
@@ -896,13 +896,13 @@
             {
                 fgd->num_uv_points[0] = fgd->num_uv_points[1] = 0;
             } else for (int pl = 0; pl < 2; pl++) {
-                fgd->num_uv_points[pl] = get_bits(gb, 4);
+                fgd->num_uv_points[pl] = dav1d_get_bits(gb, 4);
                 if (fgd->num_uv_points[pl] > 10) goto error;
                 for (int i = 0; i < fgd->num_uv_points[pl]; i++) {
-                    fgd->uv_points[pl][i][0] = get_bits(gb, 8);
+                    fgd->uv_points[pl][i][0] = dav1d_get_bits(gb, 8);
                     if (i && fgd->uv_points[pl][i - 1][0] >= fgd->uv_points[pl][i][0])
                         goto error;
-                    fgd->uv_points[pl][i][1] = get_bits(gb, 8);
+                    fgd->uv_points[pl][i][1] = dav1d_get_bits(gb, 8);
                 }
             }
 
@@ -912,28 +912,28 @@
                 goto error;
             }
 
-            fgd->scaling_shift = get_bits(gb, 2) + 8;
-            fgd->ar_coeff_lag = get_bits(gb, 2);
+            fgd->scaling_shift = dav1d_get_bits(gb, 2) + 8;
+            fgd->ar_coeff_lag = dav1d_get_bits(gb, 2);
             const int num_y_pos = 2 * fgd->ar_coeff_lag * (fgd->ar_coeff_lag + 1);
             if (fgd->num_y_points)
                 for (int i = 0; i < num_y_pos; i++)
-                    fgd->ar_coeffs_y[i] = get_bits(gb, 8) - 128;
+                    fgd->ar_coeffs_y[i] = dav1d_get_bits(gb, 8) - 128;
             for (int pl = 0; pl < 2; pl++)
                 if (fgd->num_uv_points[pl] || fgd->chroma_scaling_from_luma) {
                     const int num_uv_pos = num_y_pos + !!fgd->num_y_points;
                     for (int i = 0; i < num_uv_pos; i++)
-                        fgd->ar_coeffs_uv[pl][i] = get_bits(gb, 8) - 128;
+                        fgd->ar_coeffs_uv[pl][i] = dav1d_get_bits(gb, 8) - 128;
                 }
-            fgd->ar_coeff_shift = get_bits(gb, 2) + 6;
-            fgd->grain_scale_shift = get_bits(gb, 2);
+            fgd->ar_coeff_shift = dav1d_get_bits(gb, 2) + 6;
+            fgd->grain_scale_shift = dav1d_get_bits(gb, 2);
             for (int pl = 0; pl < 2; pl++)
                 if (fgd->num_uv_points[pl]) {
-                    fgd->uv_mult[pl] = get_bits(gb, 8);
-                    fgd->uv_luma_mult[pl] = get_bits(gb, 8);
-                    fgd->uv_offset[pl] = get_bits(gb, 9);
+                    fgd->uv_mult[pl] = dav1d_get_bits(gb, 8);
+                    fgd->uv_luma_mult[pl] = dav1d_get_bits(gb, 8);
+                    fgd->uv_offset[pl] = dav1d_get_bits(gb, 9);
                 }
-            fgd->overlap_flag = get_bits(gb, 1);
-            fgd->clip_to_restricted_range = get_bits(gb, 1);
+            fgd->overlap_flag = dav1d_get_bits(gb, 1);
+            fgd->clip_to_restricted_range = dav1d_get_bits(gb, 1);
         }
     } else {
         memset(&hdr->film_grain.data, 0, sizeof(hdr->film_grain));
@@ -946,9 +946,9 @@
 end:
 
     if (have_trailing_bit)
-        get_bits(gb, 1); // dummy bit
+        dav1d_get_bits(gb, 1); // dummy bit
 
-    return flush_get_bits(gb) - init_ptr;
+    return dav1d_flush_get_bits(gb) - init_ptr;
 
 error:
     fprintf(stderr, "Error parsing frame header\n");
@@ -962,48 +962,48 @@
     const int n_bits = c->frame_hdr.tiling.log2_cols +
                        c->frame_hdr.tiling.log2_rows;
     if (n_bits)
-        have_tile_pos = get_bits(gb, 1);
+        have_tile_pos = dav1d_get_bits(gb, 1);
 
     if (have_tile_pos) {
-        c->tile[c->n_tile_data].start = get_bits(gb, n_bits);
-        c->tile[c->n_tile_data].end = get_bits(gb, n_bits);
+        c->tile[c->n_tile_data].start = dav1d_get_bits(gb, n_bits);
+        c->tile[c->n_tile_data].end = dav1d_get_bits(gb, n_bits);
     } else {
         c->tile[c->n_tile_data].start = 0;
         c->tile[c->n_tile_data].end = (1 << n_bits) - 1;
     }
 
-    return flush_get_bits(gb) - init_ptr;
+    return dav1d_flush_get_bits(gb) - init_ptr;
 }
 
-int parse_obus(Dav1dContext *const c, Dav1dData *const in) {
+int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in) {
     GetBits gb;
     int res;
 
-    init_get_bits(&gb, in->data, in->sz);
+    dav1d_init_get_bits(&gb, in->data, in->sz);
 
     // obu header
-    get_bits(&gb, 1); // obu_forbidden_bit
-    const enum ObuType type = get_bits(&gb, 4);
-    const int has_extension = get_bits(&gb, 1);
-    const int has_length_field = get_bits(&gb, 1);
+    dav1d_get_bits(&gb, 1); // obu_forbidden_bit
+    const enum ObuType type = dav1d_get_bits(&gb, 4);
+    const int has_extension = dav1d_get_bits(&gb, 1);
+    const int has_length_field = dav1d_get_bits(&gb, 1);
     if (!has_length_field) goto error;
-    get_bits(&gb, 1); // reserved
+    dav1d_get_bits(&gb, 1); // reserved
     if (has_extension) {
-        get_bits(&gb, 3); // temporal_layer_id
-        get_bits(&gb, 2); // enhancement_layer_id
-        get_bits(&gb, 3); // reserved
+        dav1d_get_bits(&gb, 3); // temporal_layer_id
+        dav1d_get_bits(&gb, 2); // enhancement_layer_id
+        dav1d_get_bits(&gb, 3); // reserved
     }
 
     // obu length field
     int len = 0, more, i = 0;
     do {
-        more = get_bits(&gb, 1);
-        len |= get_bits(&gb, 7) << (i * 7);
+        more = dav1d_get_bits(&gb, 1);
+        len |= dav1d_get_bits(&gb, 7) << (i * 7);
         if (more && ++i == 8) goto error;
     } while (more);
     if (gb.error) goto error;
 
-    int off = flush_get_bits(&gb) - in->data;
+    int off = dav1d_flush_get_bits(&gb) - in->data;
     const int init_off = off;
     if (len > in->sz - off) goto error;
 
@@ -1066,7 +1066,7 @@
         c->tile_mask == (1 << n_tiles) - 1)
     {
         assert(c->n_tile_data);
-        submit_frame(c);
+        dav1d_submit_frame(c);
         assert(!c->n_tile_data);
         c->have_frame_hdr = 0;
         c->tile_mask = 0;
--- a/src/obu.h
+++ b/src/obu.h
@@ -31,6 +31,6 @@
 #include "dav1d/data.h"
 #include "src/internal.h"
 
-int parse_obus(Dav1dContext *c, Dav1dData *in);
+int dav1d_parse_obus(Dav1dContext *c, Dav1dData *in);
 
 #endif /* __DAV1D_SRC_OBU_H__ */
--- a/src/qm.c
+++ b/src/qm.c
@@ -3063,7 +3063,7 @@
     },
 };
 
-const uint8_t *av1_qm_tbl[16][2][N_RECT_TX_SIZES];
+const uint8_t *dav1d_qm_tbl[16][2][N_RECT_TX_SIZES];
 static uint8_t pb_32x32[32 * 32];
 static uint8_t qm_tbl_4x4[15][2][16];
 static uint8_t qm_tbl_4x8[15][2][32];
@@ -3104,7 +3104,7 @@
     }
 }
 
-void av1_init_qm_tables(void) {
+void dav1d_init_qm_tables(void) {
     // This function is guaranteed to be called only once
 
     for (int i = 0; i < 15; i++)
@@ -3111,40 +3111,40 @@
         for (int j = 0; j < 2; j++) {
             // note that the w/h in the assignment is inverted, this is on purpose
             // because we store coefficients transposed
-            av1_qm_tbl[i][j][RTX_4X8  ] = qm_tbl_8x4[i][j];
-            av1_qm_tbl[i][j][RTX_8X4  ] = qm_tbl_4x8[i][j];
+            dav1d_qm_tbl[i][j][RTX_4X8  ] = qm_tbl_8x4[i][j];
+            dav1d_qm_tbl[i][j][RTX_8X4  ] = qm_tbl_4x8[i][j];
             transpose(qm_tbl_4x8[i][j], qm_tbl_8x4[i][j], 8, 4);
-            av1_qm_tbl[i][j][RTX_4X16 ] = qm_tbl_16x4[i][j];
-            av1_qm_tbl[i][j][RTX_16X4 ] = qm_tbl_4x16[i][j];
+            dav1d_qm_tbl[i][j][RTX_4X16 ] = qm_tbl_16x4[i][j];
+            dav1d_qm_tbl[i][j][RTX_16X4 ] = qm_tbl_4x16[i][j];
             transpose(qm_tbl_4x16[i][j], qm_tbl_16x4[i][j], 16, 4);
-            av1_qm_tbl[i][j][RTX_8X16 ] = qm_tbl_16x8[i][j];
-            av1_qm_tbl[i][j][RTX_16X8 ] = qm_tbl_8x16[i][j];
+            dav1d_qm_tbl[i][j][RTX_8X16 ] = qm_tbl_16x8[i][j];
+            dav1d_qm_tbl[i][j][RTX_16X8 ] = qm_tbl_8x16[i][j];
             transpose(qm_tbl_8x16[i][j], qm_tbl_16x8[i][j], 16, 8);
-            av1_qm_tbl[i][j][RTX_8X32 ] = qm_tbl_32x8[i][j];
-            av1_qm_tbl[i][j][RTX_32X8 ] = qm_tbl_8x32[i][j];
+            dav1d_qm_tbl[i][j][RTX_8X32 ] = qm_tbl_32x8[i][j];
+            dav1d_qm_tbl[i][j][RTX_32X8 ] = qm_tbl_8x32[i][j];
             transpose(qm_tbl_8x32[i][j], qm_tbl_32x8[i][j], 32, 8);
-            av1_qm_tbl[i][j][RTX_16X32] = qm_tbl_32x16[i][j];
-            av1_qm_tbl[i][j][RTX_32X16] = qm_tbl_16x32[i][j];
+            dav1d_qm_tbl[i][j][RTX_16X32] = qm_tbl_32x16[i][j];
+            dav1d_qm_tbl[i][j][RTX_32X16] = qm_tbl_16x32[i][j];
             transpose(qm_tbl_16x32[i][j], qm_tbl_32x16[i][j], 32, 16);
 
-            av1_qm_tbl[i][j][ TX_4X4  ] = qm_tbl_4x4[i][j];
-            av1_qm_tbl[i][j][ TX_8X8  ] = qm_tbl_8x8[i][j];
-            av1_qm_tbl[i][j][ TX_16X16] = qm_tbl_16x16[i][j];
-            av1_qm_tbl[i][j][ TX_32X32] = qm_tbl_32x32[i][j];
+            dav1d_qm_tbl[i][j][ TX_4X4  ] = qm_tbl_4x4[i][j];
+            dav1d_qm_tbl[i][j][ TX_8X8  ] = qm_tbl_8x8[i][j];
+            dav1d_qm_tbl[i][j][ TX_16X16] = qm_tbl_16x16[i][j];
+            dav1d_qm_tbl[i][j][ TX_32X32] = qm_tbl_32x32[i][j];
             untriangle(qm_tbl_4x4[i][j], qm_tbl_4x4_t[i][j], 4);
             untriangle(qm_tbl_8x8[i][j], qm_tbl_8x8_t[i][j], 8);
             untriangle(qm_tbl_32x32[i][j], qm_tbl_32x32_t[i][j], 32);
             subsample(qm_tbl_16x16[i][j], qm_tbl_32x32[i][j], 16, 2);
 
-            av1_qm_tbl[i][j][ TX_64X64] = av1_qm_tbl[i][j][ TX_32X32];
-            av1_qm_tbl[i][j][RTX_64X32] = av1_qm_tbl[i][j][ TX_32X32];
-            av1_qm_tbl[i][j][RTX_64X16] = av1_qm_tbl[i][j][RTX_32X16];
-            av1_qm_tbl[i][j][RTX_32X64] = av1_qm_tbl[i][j][ TX_32X32];
-            av1_qm_tbl[i][j][RTX_16X64] = av1_qm_tbl[i][j][RTX_16X32];
+            dav1d_qm_tbl[i][j][ TX_64X64] = dav1d_qm_tbl[i][j][ TX_32X32];
+            dav1d_qm_tbl[i][j][RTX_64X32] = dav1d_qm_tbl[i][j][ TX_32X32];
+            dav1d_qm_tbl[i][j][RTX_64X16] = dav1d_qm_tbl[i][j][RTX_32X16];
+            dav1d_qm_tbl[i][j][RTX_32X64] = dav1d_qm_tbl[i][j][ TX_32X32];
+            dav1d_qm_tbl[i][j][RTX_16X64] = dav1d_qm_tbl[i][j][RTX_16X32];
         }
 
     memset(pb_32x32, 32, sizeof(pb_32x32));
     for (int j = 0; j < 2; j++)
         for (int k = 0; k < N_RECT_TX_SIZES; k++)
-            av1_qm_tbl[15][j][k] = pb_32x32;
+            dav1d_qm_tbl[15][j][k] = pb_32x32;
 }
--- a/src/qm.h
+++ b/src/qm.h
@@ -30,8 +30,8 @@
 
 #include "src/levels.h"
 
-extern const uint8_t *av1_qm_tbl[16][2][N_RECT_TX_SIZES];
+extern const uint8_t *dav1d_qm_tbl[16][2][N_RECT_TX_SIZES];
 
-void av1_init_qm_tables(void);
+void dav1d_init_qm_tables(void);
 
 #endif /* __DAV1D_SRC_QM_H__ */
--- a/src/recon.c
+++ b/src/recon.c
@@ -65,7 +65,7 @@
     Dav1dTileState *const ts = t->ts;
     const int chroma = !!plane;
     const Dav1dFrameContext *const f = t->f;
-    const TxfmInfo *const t_dim = &av1_txfm_dimensions[tx];
+    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx];
     const int dbg = DEBUG_BLOCK_INFO && plane && 0;
 
     if (dbg) printf("Start: r=%d\n", ts->msac.rng);
@@ -95,14 +95,14 @@
     } else {
         const enum TxfmTypeSet set = get_ext_txtp_set(tx, !intra,
                                                       &f->frame_hdr, b->seg_id);
-        const unsigned set_cnt = av1_tx_type_count[set];
+        const unsigned set_cnt = dav1d_tx_type_count[set];
         unsigned idx;
         if (set_cnt == 1) {
             idx = 0;
         } else {
-            const int set_idx = av1_tx_type_set_index[!intra][set];
+            const int set_idx = dav1d_tx_type_set_index[!intra][set];
             const enum IntraPredMode y_mode_nofilt = b->y_mode == FILTER_PRED ?
-                av1_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
+                dav1d_filter_mode_to_y_mode[b->y_angle] : b->y_mode;
             uint16_t *const txtp_cdf = intra ?
                        ts->cdf.m.txtp_intra[set_idx][t_dim->min][y_mode_nofilt] :
                        ts->cdf.m.txtp_inter[set_idx][t_dim->min];
@@ -110,15 +110,15 @@
             if (dbg)
             printf("Post-txtp[%d->%d][%d->%d][%d][%d->%d]: r=%d\n",
                    set, set_idx, tx, t_dim->min, b->intra ? y_mode_nofilt : -1,
-                   idx, av1_tx_types_per_set[set][idx], ts->msac.rng);
+                   idx, dav1d_tx_types_per_set[set][idx], ts->msac.rng);
         }
-        *txtp = av1_tx_types_per_set[set][idx];
+        *txtp = dav1d_tx_types_per_set[set][idx];
     }
 
     // find end-of-block (eob)
     int eob_bin;
     const int tx2dszctx = imin(t_dim->lw, TX_32X32) + imin(t_dim->lh, TX_32X32);
-    const enum TxClass tx_class = av1_tx_type_class[*txtp];
+    const enum TxClass tx_class = dav1d_tx_type_class[*txtp];
     const int is_1d = tx_class != TX_CLASS_2D;
     switch (tx2dszctx) {
 #define case_sz(sz, bin) \
@@ -163,7 +163,7 @@
     // base tokens
     uint16_t (*const br_cdf)[5] =
         ts->cdf.coef.br_tok[imin(t_dim->ctx, 3)][chroma];
-    const int16_t *const scan = av1_scans[tx][tx_class];
+    const int16_t *const scan = dav1d_scans[tx][tx_class];
     uint8_t levels[36 * 36];
     ptrdiff_t stride = 4 * (imin(t_dim->h, 8) + 1);
     memset(levels, 0, stride * 4 * (imin(t_dim->w, 8) + 1));
@@ -262,12 +262,12 @@
     const Dav1dFrameContext *const f = t->f;
     Dav1dTileState *const ts = t->ts;
     const Dav1dDSPContext *const dsp = f->dsp;
-    const TxfmInfo *const t_dim = &av1_txfm_dimensions[ytx];
+    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[ytx];
     const int txw = t_dim->w, txh = t_dim->h;
 
     if (depth < 2 && tx_split[depth] & (1 << (y_off * 4 + x_off))) {
         const enum RectTxfmSize sub = t_dim->sub;
-        const TxfmInfo *const sub_t_dim = &av1_txfm_dimensions[sub];
+        const TxfmInfo *const sub_t_dim = &dav1d_txfm_dimensions[sub];
         const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
 
         read_coef_tree(t, bs, b, sub, depth + 1, tx_split,
@@ -336,8 +336,8 @@
     }
 }
 
-void bytefn(read_coef_blocks)(Dav1dTileContext *const t,
-                              const enum BlockSize bs, const Av1Block *const b)
+void bytefn(dav1d_read_coef_blocks)(Dav1dTileContext *const t,
+                                    const enum BlockSize bs, const Av1Block *const b)
 {
     const Dav1dFrameContext *const f = t->f;
     const int ss_ver = f->cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
@@ -344,7 +344,7 @@
     const int ss_hor = f->cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
     const int bx4 = t->bx & 31, by4 = t->by & 31;
     const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
-    const uint8_t *const b_dim = av1_block_dimensions[bs];
+    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
     const int bw4 = b_dim[0], bh4 = b_dim[1];
     const int cbw4 = (bw4 + 1) >> ss_hor, cbh4 = (bh4 + 1) >> ss_ver;
     const int has_chroma = f->seq_hdr.layout != DAV1D_PIXEL_LAYOUT_I400 &&
@@ -366,8 +366,8 @@
     const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
     assert(f->frame_thread.pass == 1);
     assert(!b->skip);
-    const TxfmInfo *const uv_t_dim = &av1_txfm_dimensions[b->uvtx];
-    const TxfmInfo *const t_dim = &av1_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
+    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
+    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->intra ? b->tx : b->max_ytx];
 
     for (int init_y = 0; init_y < h4; init_y += 16) {
         for (int init_x = 0; init_x < w4; init_x += 16) {
@@ -576,7 +576,7 @@
             // only odd blocks are considered for overlap handling, hence +1
             const refmvs *const a_r = &r[x - f->b4_stride + 1];
             const uint8_t *const a_b_dim =
-                av1_block_dimensions[sbtype_to_bs[a_r->sb_type]];
+                dav1d_block_dimensions[sbtype_to_bs[a_r->sb_type]];
 
             if (a_r->ref[0] > 0) {
                 mc(t, lap, NULL, 128 * sizeof(pixel),
@@ -583,7 +583,7 @@
                    iclip(a_b_dim[0], 2, b_dim[0]), imin(b_dim[1], 16) >> 1,
                    t->bx + x, t->by, pl, a_r->mv[0],
                    &f->refp[a_r->ref[0] - 1],
-                   av1_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
+                   dav1d_filter_2d[t->a->filter[1][bx4 + x + 1]][t->a->filter[0][bx4 + x + 1]]);
                 f->dsp->mc.blend(&dst[x * h_mul], dst_stride,
                                  lap, 128 * sizeof(pixel),
                                  h_mul * iclip(a_b_dim[0], 2, b_dim[0]),
@@ -600,7 +600,7 @@
             // only odd blocks are considered for overlap handling, hence +1
             const refmvs *const l_r = &r[(y + 1) * f->b4_stride - 1];
             const uint8_t *const l_b_dim =
-                av1_block_dimensions[sbtype_to_bs[l_r->sb_type]];
+                dav1d_block_dimensions[sbtype_to_bs[l_r->sb_type]];
 
             if (l_r->ref[0] > 0) {
                 mc(t, lap, NULL, 32 * sizeof(pixel),
@@ -608,7 +608,7 @@
                    iclip(l_b_dim[1], 2, b_dim[1]),
                    t->bx, t->by + y, pl, l_r->mv[0],
                    &f->refp[l_r->ref[0] - 1],
-                   av1_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
+                   dav1d_filter_2d[t->l.filter[1][by4 + y + 1]][t->l.filter[0][by4 + y + 1]]);
                 f->dsp->mc.blend(&dst[y * v_mul * PXSTRIDE(dst_stride)], dst_stride,
                                  lap, 32 * sizeof(pixel),
                                  h_mul * imin(b_dim[0], 16) >> 1,
@@ -678,9 +678,9 @@
     }
 }
 
-void bytefn(recon_b_intra)(Dav1dTileContext *const t, const enum BlockSize bs,
-                           const enum EdgeFlags intra_edge_flags,
-                           const Av1Block *const b)
+void bytefn(dav1d_recon_b_intra)(Dav1dTileContext *const t, const enum BlockSize bs,
+                                 const enum EdgeFlags intra_edge_flags,
+                                 const Av1Block *const b)
 {
     Dav1dTileState *const ts = t->ts;
     const Dav1dFrameContext *const f = t->f;
@@ -689,7 +689,7 @@
     const int ss_ver = f->cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
     const int ss_hor = f->cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
     const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
-    const uint8_t *const b_dim = av1_block_dimensions[bs];
+    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
     const int bw4 = b_dim[0], bh4 = b_dim[1];
     const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
     const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
@@ -696,8 +696,8 @@
     const int has_chroma = f->seq_hdr.layout != DAV1D_PIXEL_LAYOUT_I400 &&
                            (bw4 > ss_hor || t->bx & 1) &&
                            (bh4 > ss_ver || t->by & 1);
-    const TxfmInfo *const t_dim = &av1_txfm_dimensions[b->tx];
-    const TxfmInfo *const uv_t_dim = &av1_txfm_dimensions[b->uvtx];
+    const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[b->tx];
+    const TxfmInfo *const uv_t_dim = &dav1d_txfm_dimensions[b->uvtx];
 
     // coefficient coding
     pixel edge_mem[257], *const edge = &edge_mem[128];
@@ -757,16 +757,16 @@
                         top_sb_edge += f->sb128w * 128 * (sby - 1);
                     }
                     const enum IntraPredMode m =
-                        bytefn(prepare_intra_edges)(t->bx,
-                                                    t->bx > ts->tiling.col_start,
-                                                    t->by,
-                                                    t->by > ts->tiling.row_start,
-                                                    ts->tiling.col_end,
-                                                    ts->tiling.row_end,
-                                                    edge_flags, dst,
-                                                    f->cur.p.stride[0], top_sb_edge,
-                                                    b->y_mode, &angle,
-                                                    t_dim->w, t_dim->h, edge);
+                        bytefn(dav1d_prepare_intra_edges)(t->bx,
+                                                          t->bx > ts->tiling.col_start,
+                                                          t->by,
+                                                          t->by > ts->tiling.row_start,
+                                                          ts->tiling.col_end,
+                                                          ts->tiling.row_end,
+                                                          edge_flags, dst,
+                                                          f->cur.p.stride[0], top_sb_edge,
+                                                          b->y_mode, &angle,
+                                                          t_dim->w, t_dim->h, edge);
                     dsp->ipred.intra_pred[b->tx][m](dst, f->cur.p.stride[0],
                                                     edge, angle | sm_fl);
 
@@ -844,9 +844,9 @@
                                            ((pixel *) f->cur.p.data[2]) + uv_off };
                 // cfl_uvtx can be different from uvtx in case of lossless
                 const enum RectTxfmSize cfl_uvtx =
-                    av1_max_txfm_size_for_bs[bs][f->cur.p.p.layout];
+                    dav1d_max_txfm_size_for_bs[bs][f->cur.p.p.layout];
                 const TxfmInfo *const cfl_uv_t_dim =
-                    &av1_txfm_dimensions[cfl_uvtx];
+                    &dav1d_txfm_dimensions[cfl_uvtx];
 
                 for (int pl = 0; pl < 2; pl++) {
                     int angle = 0;
@@ -857,18 +857,18 @@
                         top_sb_edge += f->sb128w * 128 * (sby - 1);
                     }
                     const enum IntraPredMode m =
-                        bytefn(prepare_intra_edges)(t->bx >> ss_hor,
-                                                    (t->bx >> ss_hor) >
-                                                        (ts->tiling.col_start >> ss_hor),
-                                                    t->by >> ss_ver,
-                                                    (t->by >> ss_ver) >
-                                                        (ts->tiling.row_start >> ss_ver),
-                                                    ts->tiling.col_end >> ss_hor,
-                                                    ts->tiling.row_end >> ss_ver,
-                                                    0, uv_dst[pl], stride,
-                                                    top_sb_edge, DC_PRED, &angle,
-                                                    cfl_uv_t_dim->w,
-                                                    cfl_uv_t_dim->h, edge);
+                        bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
+                                                          (t->bx >> ss_hor) >
+                                                              (ts->tiling.col_start >> ss_hor),
+                                                          t->by >> ss_ver,
+                                                          (t->by >> ss_ver) >
+                                                              (ts->tiling.row_start >> ss_ver),
+                                                          ts->tiling.col_end >> ss_hor,
+                                                          ts->tiling.row_end >> ss_ver,
+                                                          0, uv_dst[pl], stride,
+                                                          top_sb_edge, DC_PRED, &angle,
+                                                          cfl_uv_t_dim->w,
+                                                          cfl_uv_t_dim->h, edge);
                     dsp->ipred.intra_pred[cfl_uvtx][m](uv_dst[pl], stride, edge, 0);
                 }
                 const int furthest_r =
@@ -969,18 +969,18 @@
                             top_sb_edge += f->sb128w * 128 * (sby - 1);
                         }
                         const enum IntraPredMode m =
-                            bytefn(prepare_intra_edges)(t->bx >> ss_hor,
-                                                        (t->bx >> ss_hor) >
-                                                            (ts->tiling.col_start >> ss_hor),
-                                                        t->by >> ss_ver,
-                                                        (t->by >> ss_ver) >
-                                                            (ts->tiling.row_start >> ss_ver),
-                                                        ts->tiling.col_end >> ss_hor,
-                                                        ts->tiling.row_end >> ss_ver,
-                                                        edge_flags, dst, stride,
-                                                        top_sb_edge, b->uv_mode,
-                                                        &angle, uv_t_dim->w,
-                                                        uv_t_dim->h, edge);
+                            bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
+                                                              (t->bx >> ss_hor) >
+                                                                  (ts->tiling.col_start >> ss_hor),
+                                                              t->by >> ss_ver,
+                                                              (t->by >> ss_ver) >
+                                                                  (ts->tiling.row_start >> ss_ver),
+                                                              ts->tiling.col_end >> ss_hor,
+                                                              ts->tiling.row_end >> ss_ver,
+                                                              edge_flags, dst, stride,
+                                                              top_sb_edge, b->uv_mode,
+                                                              &angle, uv_t_dim->w,
+                                                              uv_t_dim->h, edge);
                         dsp->ipred.intra_pred[b->uvtx][m](dst, stride,
                                                           edge, angle | sm_uv_fl);
                         if (DEBUG_BLOCK_INFO && DEBUG_B_PIXELS) {
@@ -1046,8 +1046,8 @@
     }
 }
 
-void bytefn(recon_b_inter)(Dav1dTileContext *const t, const enum BlockSize bs,
-                           const Av1Block *const b)
+void bytefn(dav1d_recon_b_inter)(Dav1dTileContext *const t, const enum BlockSize bs,
+                                 const Av1Block *const b)
 {
     Dav1dTileState *const ts = t->ts;
     const Dav1dFrameContext *const f = t->f;
@@ -1056,7 +1056,7 @@
     const int ss_ver = f->cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
     const int ss_hor = f->cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
     const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
-    const uint8_t *const b_dim = av1_block_dimensions[bs];
+    const uint8_t *const b_dim = dav1d_block_dimensions[bs];
     const int bw4 = b_dim[0], bh4 = b_dim[1];
     const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
     const int has_chroma = f->seq_hdr.layout != DAV1D_PIXEL_LAYOUT_I400 &&
@@ -1100,7 +1100,7 @@
                 obmc(t, dst, f->cur.p.stride[0], b_dim, 0, bx4, by4, w4, h4);
         }
         if (b->interintra_type) {
-            const enum RectTxfmSize ii_tx = av1_max_txfm_size_for_bs[bs][0];
+            const enum RectTxfmSize ii_tx = dav1d_max_txfm_size_for_bs[bs][0];
             pixel tl_edge_px[65], *const tl_edge = &tl_edge_px[32];
             enum IntraPredMode m = b->interintra_mode == II_SMOOTH_PRED ?
                                    SMOOTH_PRED : b->interintra_mode;
@@ -1112,16 +1112,16 @@
                 const int sby = t->by >> f->sb_shift;
                 top_sb_edge += f->sb128w * 128 * (sby - 1);
             }
-            m = bytefn(prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
-                                            t->by, t->by > ts->tiling.row_start,
-                                            ts->tiling.col_end, ts->tiling.row_end,
-                                            0, dst, f->cur.p.stride[0], top_sb_edge,
-                                            m, &angle, bw4, bh4, tl_edge);
+            m = bytefn(dav1d_prepare_intra_edges)(t->bx, t->bx > ts->tiling.col_start,
+                                                  t->by, t->by > ts->tiling.row_start,
+                                                  ts->tiling.col_end, ts->tiling.row_end,
+                                                  0, dst, f->cur.p.stride[0], top_sb_edge,
+                                                  m, &angle, bw4, bh4, tl_edge);
             dsp->ipred.intra_pred[ii_tx][m](tmp, 4 * bw4 * sizeof(pixel), tl_edge, 0);
             const uint8_t *const ii_mask =
                 b->interintra_type == INTER_INTRA_BLEND ?
-                     ii_masks[bs][0][b->interintra_mode] :
-                     wedge_masks[bs][0][0][b->wedge_idx];
+                     dav1d_ii_masks[bs][0][b->interintra_mode] :
+                     dav1d_wedge_masks[bs][0][0][b->wedge_idx];
             dsp->mc.blend(dst, f->cur.p.stride[0], tmp, bw4 * 4 * sizeof(pixel),
                           bw4 * 4, bh4 * 4, ii_mask, bw4 * 4);
         }
@@ -1158,7 +1158,7 @@
             }
             if (bw4 == 1) {
                 const enum Filter2d left_filter_2d =
-                    av1_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
+                    dav1d_filter_2d[t->l.filter[1][by4]][t->l.filter[0][by4]];
                 for (int pl = 0; pl < 2; pl++)
                     mc(t, ((pixel *) f->cur.p.data[1 + pl]) + uvdstoff + v_off, NULL,
                        f->cur.p.stride[1], bw4, bh4, t->bx - 1,
@@ -1169,7 +1169,7 @@
             }
             if (bh4 == ss_ver) {
                 const enum Filter2d top_filter_2d =
-                    av1_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
+                    dav1d_filter_2d[t->a->filter[1][bx4]][t->a->filter[0][bx4]];
                 for (int pl = 0; pl < 2; pl++)
                     mc(t, ((pixel *) f->cur.p.data[1 + pl]) + uvdstoff + h_off, NULL,
                        f->cur.p.stride[1], bw4, bh4, t->bx, t->by - 1,
@@ -1211,11 +1211,11 @@
                 // the wrong thing since it will select 4x16, not 4x32, as a
                 // transform size...
                 const enum RectTxfmSize ii_tx =
-                    av1_max_txfm_size_for_bs[bs][f->cur.p.p.layout];
+                    dav1d_max_txfm_size_for_bs[bs][f->cur.p.p.layout];
                 const uint8_t *const ii_mask =
                     b->interintra_type == INTER_INTRA_BLEND ?
-                         ii_masks[bs][chr_layout_idx][b->interintra_mode] :
-                         wedge_masks[bs][chr_layout_idx][0][b->wedge_idx];
+                         dav1d_ii_masks[bs][chr_layout_idx][b->interintra_mode] :
+                         dav1d_wedge_masks[bs][chr_layout_idx][0][b->wedge_idx];
 
                 for (int pl = 0; pl < 2; pl++) {
                     pixel *const tmp = t->scratch.interintra;
@@ -1231,17 +1231,17 @@
                         const int sby = t->by >> f->sb_shift;
                         top_sb_edge += f->sb128w * 128 * (sby - 1);
                     }
-                    m = bytefn(prepare_intra_edges)(t->bx >> ss_hor,
-                                                    (t->bx >> ss_hor) >
-                                                        (ts->tiling.col_start >> ss_hor),
-                                                    t->by >> ss_ver,
-                                                    (t->by >> ss_ver) >
-                                                        (ts->tiling.row_start >> ss_ver),
-                                                    ts->tiling.col_end >> ss_hor,
-                                                    ts->tiling.row_end >> ss_ver,
-                                                    0, uvdst, f->cur.p.stride[1],
-                                                    top_sb_edge, m,
-                                                    &angle, cbw4, cbh4, tl_edge);
+                    m = bytefn(dav1d_prepare_intra_edges)(t->bx >> ss_hor,
+                                                          (t->bx >> ss_hor) >
+                                                              (ts->tiling.col_start >> ss_hor),
+                                                          t->by >> ss_ver,
+                                                          (t->by >> ss_ver) >
+                                                              (ts->tiling.row_start >> ss_ver),
+                                                          ts->tiling.col_end >> ss_hor,
+                                                          ts->tiling.row_end >> ss_ver,
+                                                          0, uvdst, f->cur.p.stride[1],
+                                                          top_sb_edge, m,
+                                                          &angle, cbw4, cbh4, tl_edge);
                     dsp->ipred.intra_pred[ii_tx][m](tmp, cbw4 * 4 * sizeof(pixel), tl_edge, 0);
                     dsp->mc.blend(uvdst, f->cur.p.stride[1], tmp, cbw4 * 4 * sizeof(pixel),
                                   cbw4 * 4, cbh4 * 4, ii_mask, cbw4 * 4);
@@ -1289,12 +1289,12 @@
             mask = seg_mask;
             break;
         case COMP_INTER_WEDGE:
-            mask = wedge_masks[bs][0][0][b->wedge_idx];
+            mask = dav1d_wedge_masks[bs][0][0][b->wedge_idx];
             dsp->mc.mask(dst, f->cur.p.stride[0],
                          tmp[b->mask_sign], tmp[!b->mask_sign],
                          bw4 * 4, bh4 * 4, mask);
             if (has_chroma)
-                mask = wedge_masks[bs][chr_layout_idx][b->mask_sign][b->wedge_idx];
+                mask = dav1d_wedge_masks[bs][chr_layout_idx][b->mask_sign][b->wedge_idx];
             break;
         }
 
@@ -1358,8 +1358,8 @@
         return;
     }
 
-    const TxfmInfo *const uvtx = &av1_txfm_dimensions[b->uvtx];
-    const TxfmInfo *const ytx = &av1_txfm_dimensions[b->max_ytx];
+    const TxfmInfo *const uvtx = &dav1d_txfm_dimensions[b->uvtx];
+    const TxfmInfo *const ytx = &dav1d_txfm_dimensions[b->max_ytx];
 
     for (int init_y = 0; init_y < bh4; init_y += 16) {
         for (int init_x = 0; init_x < bw4; init_x += 16) {
@@ -1446,7 +1446,7 @@
     }
 }
 
-void bytefn(filter_sbrow)(Dav1dFrameContext *const f, const int sby) {
+void bytefn(dav1d_filter_sbrow)(Dav1dFrameContext *const f, const int sby) {
     const int ss_ver = f->cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
     const int sbsz = f->sb_step, sbh = f->sbh;
 
@@ -1491,7 +1491,7 @@
     }
 }
 
-void bytefn(backup_ipred_edge)(Dav1dTileContext *const t) {
+void bytefn(dav1d_backup_ipred_edge)(Dav1dTileContext *const t) {
     const Dav1dFrameContext *const f = t->f;
     Dav1dTileState *const ts = t->ts;
     const int sby = t->by >> f->sb_shift;
--- a/src/recon.h
+++ b/src/recon.h
@@ -57,19 +57,19 @@
 void (name)(Dav1dTileContext *t, enum BlockSize bs, const Av1Block *b)
 typedef decl_read_coef_blocks_fn(*read_coef_blocks_fn);
 
-decl_recon_b_intra_fn(recon_b_intra_8bpc);
-decl_recon_b_intra_fn(recon_b_intra_16bpc);
+decl_recon_b_intra_fn(dav1d_recon_b_intra_8bpc);
+decl_recon_b_intra_fn(dav1d_recon_b_intra_16bpc);
 
-decl_recon_b_inter_fn(recon_b_inter_8bpc);
-decl_recon_b_inter_fn(recon_b_inter_16bpc);
+decl_recon_b_inter_fn(dav1d_recon_b_inter_8bpc);
+decl_recon_b_inter_fn(dav1d_recon_b_inter_16bpc);
 
-decl_filter_sbrow_fn(filter_sbrow_8bpc);
-decl_filter_sbrow_fn(filter_sbrow_16bpc);
+decl_filter_sbrow_fn(dav1d_filter_sbrow_8bpc);
+decl_filter_sbrow_fn(dav1d_filter_sbrow_16bpc);
 
-decl_backup_ipred_edge_fn(backup_ipred_edge_8bpc);
-decl_backup_ipred_edge_fn(backup_ipred_edge_16bpc);
+decl_backup_ipred_edge_fn(dav1d_backup_ipred_edge_8bpc);
+decl_backup_ipred_edge_fn(dav1d_backup_ipred_edge_16bpc);
 
-decl_read_coef_blocks_fn(read_coef_blocks_8bpc);
-decl_read_coef_blocks_fn(read_coef_blocks_16bpc);
+decl_read_coef_blocks_fn(dav1d_read_coef_blocks_8bpc);
+decl_read_coef_blocks_fn(dav1d_read_coef_blocks_16bpc);
 
 #endif /* __DAV1D_SRC_RECON_H__ */
--- a/src/ref_mvs.c
+++ b/src/ref_mvs.c
@@ -3235,7 +3235,7 @@
     BS_4x4,
     N_BS_SIZES,
 };
-extern const uint8_t av1_block_dimensions[N_BS_SIZES][4];
+extern const uint8_t dav1d_block_dimensions[N_BS_SIZES][4];
 const uint8_t bs_to_sbtype[N_BS_SIZES] = {
     [BS_128x128] = BLOCK_128X128,
     [BS_128x64] = BLOCK_128X64,
@@ -3308,8 +3308,8 @@
                       int tile_row_start4, int tile_row_end4,
                       AV1_COMMON *cm)
 {
-    const int bw4 = av1_block_dimensions[bs][0];
-    const int bh4 = av1_block_dimensions[bs][1];
+    const int bw4 = dav1d_block_dimensions[bs][0];
+    const int bh4 = dav1d_block_dimensions[bs][1];
     int stride = cm->cur_frame.mv_stride;
     MACROBLOCKD xd = (MACROBLOCKD) {
         .n8_w = bw4,
--- a/src/ref_mvs.h
+++ b/src/ref_mvs.h
@@ -71,8 +71,8 @@
                                    const int ref, const mv mv,
                                    const int is_interintra)
 {
-    const int bw4 = av1_block_dimensions[bs][0];
-    int bh4 = av1_block_dimensions[bs][1];
+    const int bw4 = dav1d_block_dimensions[bs][0];
+    int bh4 = dav1d_block_dimensions[bs][1];
 
     r += by4 * stride + bx4;
     const refmvs tmpl = (refmvs) {
@@ -92,8 +92,8 @@
                                     const int by4, const int bx4,
                                     const enum BlockSize bs, const mv mv)
 {
-    const int bw4 = av1_block_dimensions[bs][0];
-    int bh4 = av1_block_dimensions[bs][1];
+    const int bw4 = dav1d_block_dimensions[bs][0];
+    int bh4 = dav1d_block_dimensions[bs][1];
 
     r += by4 * stride + bx4;
     const refmvs tmpl = (refmvs) {
@@ -116,8 +116,8 @@
                                    const int ref1, const int ref2,
                                    const mv mv1, const mv mv2)
 {
-    const int bw4 = av1_block_dimensions[bs][0];
-    int bh4 = av1_block_dimensions[bs][1];
+    const int bw4 = dav1d_block_dimensions[bs][0];
+    int bh4 = dav1d_block_dimensions[bs][1];
 
     r += by4 * stride + bx4;
     const refmvs tmpl = (refmvs) {
@@ -138,8 +138,8 @@
                                   const enum BlockSize bs,
                                   const enum IntraPredMode mode)
 {
-    const int bw4 = av1_block_dimensions[bs][0];
-    int bh4 = av1_block_dimensions[bs][1];
+    const int bw4 = dav1d_block_dimensions[bs][0];
+    int bh4 = dav1d_block_dimensions[bs][1];
 
     r += by4 * stride + bx4;
     do {
--- a/src/scan.c
+++ b/src/scan.c
@@ -467,7 +467,7 @@
      892,  861,  830,  799,  831,  862,  893,  924,  955,  986, 1017, 1018,  987,  956,  925,  894,  863,  895,  926,  957,  988, 1019, 1020,  989,  958,  927,  959,  990, 1021, 1022,  991, 1023,
 };
 
-const int16_t *const av1_scans[N_RECT_TX_SIZES][3] = {
+const int16_t *const dav1d_scans[N_RECT_TX_SIZES][3] = {
     [TX_4X4] = {
         [TX_CLASS_2D] = av1_default_scan_4x4,
         [TX_CLASS_V]  = av1_mrow_scan_4x4,
--- a/src/scan.h
+++ b/src/scan.h
@@ -32,6 +32,6 @@
 
 #include "src/levels.h"
 
-extern const int16_t *const av1_scans[N_RECT_TX_SIZES][3];
+extern const int16_t *const dav1d_scans[N_RECT_TX_SIZES][3];
 
 #endif /* __DAV1D_SCAN_H__ */
--- a/src/tables.c
+++ b/src/tables.c
@@ -34,7 +34,7 @@
 #include "src/levels.h"
 #include "src/tables.h"
 
-const uint8_t av1_al_part_ctx[2][N_BL_LEVELS][N_PARTITIONS] = {
+const uint8_t dav1d_al_part_ctx[2][N_BL_LEVELS][N_PARTITIONS] = {
     {
         // partitions:
         // none,  h,    v, split,  tts,  tbs,  tls,  trs,   h4,   v4
@@ -53,7 +53,7 @@
 };
 
 const uint8_t /* enum BlockSize */
-    av1_block_sizes[N_BL_LEVELS][N_PARTITIONS][2] =
+    dav1d_block_sizes[N_BL_LEVELS][N_PARTITIONS][2] =
 {
     [BL_128X128] = {
         [PARTITION_NONE]           = { BS_128x128 },
@@ -101,7 +101,7 @@
     }
 };
 
-const uint8_t av1_block_dimensions[N_BS_SIZES][4] = {
+const uint8_t dav1d_block_dimensions[N_BS_SIZES][4] = {
     [BS_128x128] = { 32, 32, 5, 5 },
     [BS_128x64]  = { 32, 16, 5, 4 },
     [BS_64x128]  = { 16, 32, 4, 5 },
@@ -126,7 +126,7 @@
     [BS_4x4]     = {  1,  1, 0, 0 },
 };
 
-const TxfmInfo av1_txfm_dimensions[N_RECT_TX_SIZES] = {
+const TxfmInfo dav1d_txfm_dimensions[N_RECT_TX_SIZES] = {
     [ TX_4X4]   = { .w = 1, .h = 1, .lw = 0, .lh = 0,
                     .min = 0, .max = 0, .ctx = 0 },
     [ TX_8X8]   = { .w = 2, .h = 2, .lw = 1, .lh = 1,
@@ -168,7 +168,7 @@
 };
 
 const uint8_t /* enum (Rect)TxfmSize */
-    av1_max_txfm_size_for_bs[N_BS_SIZES][4 /* y, 420, 422, 444 */] =
+    dav1d_max_txfm_size_for_bs[N_BS_SIZES][4 /* y, 420, 422, 444 */] =
 {
     [BS_128x128] = {  TX_64X64,  TX_32X32,  TX_32X32,  TX_32X32 },
     [BS_128x64]  = {  TX_64X64,  TX_32X32,  TX_32X32,  TX_32X32 },
@@ -195,7 +195,7 @@
 };
 
 const uint8_t /* enum TxfmType */
-    av1_txtp_from_uvmode[N_UV_INTRA_PRED_MODES] =
+    dav1d_txtp_from_uvmode[N_UV_INTRA_PRED_MODES] =
 {
     [DC_PRED]              = DCT_DCT,
     [VERT_PRED]            = ADST_DCT,
@@ -213,7 +213,7 @@
 };
 
 const uint8_t /* enum InterPredMode */
-    av1_comp_inter_pred_modes[N_COMP_INTER_PRED_MODES][2] =
+    dav1d_comp_inter_pred_modes[N_COMP_INTER_PRED_MODES][2] =
 {
     [NEARESTMV_NEARESTMV] = { NEARESTMV, NEARESTMV },
     [NEARMV_NEARMV]       = { NEARMV,    NEARMV    },
@@ -225,7 +225,7 @@
     [NEARMV_NEWMV]        = { NEARMV,    NEWMV     },
 };
 
-const uint8_t av1_tx_type_count[N_TXTP_SETS] = {
+const uint8_t dav1d_tx_type_count[N_TXTP_SETS] = {
     [TXTP_SET_DCT] = 1,
     [TXTP_SET_DCT_ID] = 2,
     [TXTP_SET_DT4_ID] = 5,
@@ -236,7 +236,7 @@
 };
 
 const uint8_t /* enum TxfmType */
-              av1_tx_types_per_set[N_TXTP_SETS][N_TX_TYPES] =
+              dav1d_tx_types_per_set[N_TXTP_SETS][N_TX_TYPES] =
 {
     [TXTP_SET_DCT]       = { DCT_DCT },
     [TXTP_SET_DCT_ID]    = { IDTX, DCT_DCT },
@@ -253,12 +253,12 @@
     [TXTP_SET_LOSSLESS]  = { WHT_WHT },
 };
 
-const uint8_t av1_tx_type_set_index[2][N_TXTP_SETS] = {
+const uint8_t dav1d_tx_type_set_index[2][N_TXTP_SETS] = {
     { 0, -1,  2,  1, -1, -1, 3 },
     { 0,  3, -1, -1,  2,  1, 4 },
 };
 
-const uint8_t av1_ymode_size_context[N_BS_SIZES] = {
+const uint8_t dav1d_ymode_size_context[N_BS_SIZES] = {
     [BS_128x128] = 3,
     [BS_128x64]  = 3,
     [BS_64x128]  = 3,
@@ -283,7 +283,7 @@
     [BS_4x4  ]   = 0,
 };
 
-const uint8_t av1_nz_map_ctx_offset[N_RECT_TX_SIZES][5][5] = {
+const uint8_t dav1d_nz_map_ctx_offset[N_RECT_TX_SIZES][5][5] = {
     [TX_4X4] = {
         { 0, 1, 6, 6 },
         { 1, 6, 6, 21 },
@@ -398,7 +398,7 @@
     }
 };
 
-const uint8_t /* enum TxClass */ av1_tx_type_class[N_TX_TYPES_PLUS_LL] = {
+const uint8_t /* enum TxClass */ dav1d_tx_type_class[N_TX_TYPES_PLUS_LL] = {
     [DCT_DCT]           = TX_CLASS_2D,
     [ADST_DCT]          = TX_CLASS_2D,
     [DCT_ADST]          = TX_CLASS_2D,
@@ -418,7 +418,7 @@
     [WHT_WHT]           = TX_CLASS_2D,
 };
 
-const uint8_t /* enum Filter2d */ av1_filter_2d[N_FILTERS][N_FILTERS] = {
+const uint8_t /* enum Filter2d */ dav1d_filter_2d[N_FILTERS][N_FILTERS] = {
     [FILTER_8TAP_REGULAR] = {
         [FILTER_8TAP_REGULAR] = FILTER_2D_8TAP_REGULAR,
         [FILTER_8TAP_SHARP]   = FILTER_2D_8TAP_REGULAR_SHARP,
@@ -436,7 +436,7 @@
     }
 };
 
-const uint8_t /* enum FilterMode */ eve_av1_filter_dir[N_2D_FILTERS][2] = {
+const uint8_t /* enum FilterMode */ dav1d_filter_dir[N_2D_FILTERS][2] = {
     [FILTER_2D_8TAP_REGULAR]        = { FILTER_8TAP_REGULAR, FILTER_8TAP_REGULAR },
     [FILTER_2D_8TAP_REGULAR_SMOOTH] = { FILTER_8TAP_SMOOTH,  FILTER_8TAP_REGULAR },
     [FILTER_2D_8TAP_REGULAR_SHARP]  = { FILTER_8TAP_SHARP,   FILTER_8TAP_REGULAR },
@@ -449,11 +449,11 @@
     [FILTER_2D_BILINEAR]            = { FILTER_2D_BILINEAR,  FILTER_2D_BILINEAR  },
 };
 
-const uint8_t av1_filter_mode_to_y_mode[5] = {
+const uint8_t dav1d_filter_mode_to_y_mode[5] = {
     DC_PRED, VERT_PRED, HOR_PRED, HOR_DOWN_PRED, DC_PRED
 };
 
-const uint8_t intra_mode_context[N_INTRA_PRED_MODES] = {
+const uint8_t dav1d_intra_mode_context[N_INTRA_PRED_MODES] = {
     [DC_PRED]              = 0,
     [VERT_PRED]            = 1,
     [HOR_PRED]             = 2,
@@ -469,43 +469,7 @@
     [PAETH_PRED]           = 0,
 };
 
-const unsigned cfl_allowed_mask =
-    (1 << BS_32x32) |
-    (1 << BS_32x16) |
-    (1 << BS_32x8) |
-    (1 << BS_16x32) |
-    (1 << BS_16x16) |
-    (1 << BS_16x8) |
-    (1 << BS_16x4) |
-    (1 << BS_8x32) |
-    (1 << BS_8x16) |
-    (1 << BS_8x8) |
-    (1 << BS_8x4) |
-    (1 << BS_4x16) |
-    (1 << BS_4x8) |
-    (1 << BS_4x4);
-
-const unsigned wedge_allowed_mask =
-    (1 << BS_32x32) |
-    (1 << BS_32x16) |
-    (1 << BS_32x8) |
-    (1 << BS_16x32) |
-    (1 << BS_16x16) |
-    (1 << BS_16x8) |
-    (1 << BS_8x32) |
-    (1 << BS_8x16) |
-    (1 << BS_8x8);
-
-const unsigned interintra_allowed_mask =
-    (1 << BS_32x32) |
-    (1 << BS_32x16) |
-    (1 << BS_16x32) |
-    (1 << BS_16x16) |
-    (1 << BS_16x8) |
-    (1 << BS_8x16) |
-    (1 << BS_8x8);
-
-const uint8_t av1_wedge_ctx_lut[N_BS_SIZES] = {
+const uint8_t dav1d_wedge_ctx_lut[N_BS_SIZES] = {
     [BS_32x32] = 6,
     [BS_32x16] = 5,
     [BS_32x8]  = 8,
@@ -517,7 +481,7 @@
     [BS_8x8]   = 0,
 };
 
-const WarpedMotionParams default_wm_params = {
+const WarpedMotionParams dav1d_default_wm_params = {
     .type = WM_TYPE_IDENTITY,
     .matrix = {
         0, 0, 1 << 16,
@@ -529,7 +493,7 @@
     .delta = 0,
 };
 
-const int16_t sgr_params[16][4] = { // r0, r1, e0, e1
+const int16_t dav1d_sgr_params[16][4] = { // r0, r1, e0, e1
     { 2, 1, 140, 3236 }, { 2, 1, 112, 2158 }, { 2, 1, 93, 1618 },
     { 2, 1,  80, 1438 }, { 2, 1,  70, 1295 }, { 2, 1, 58, 1177 },
     { 2, 1,  47, 1079 }, { 2, 1,  37,  996 }, { 2, 1, 30,  925 },
@@ -538,7 +502,7 @@
     { 2, 0,  22,   -1 },
 };
 
-const int16_t sgr_x_by_xplus1[256] = {
+const int16_t dav1d_sgr_x_by_xplus1[256] = {
   1,   128, 171, 192, 205, 213, 219, 224, 228, 230, 233, 235, 236, 238, 239,
   240, 241, 242, 243, 243, 244, 244, 245, 245, 246, 246, 247, 247, 247, 247,
   248, 248, 248, 248, 249, 249, 249, 249, 249, 250, 250, 250, 250, 250, 250,
@@ -559,12 +523,12 @@
   256,
 };
 
-const int16_t sgr_one_by_x[] = {
+const int16_t dav1d_sgr_one_by_x[25] = {
   4096, 2048, 1365, 1024, 819, 683, 585, 512, 455, 410, 372, 341, 315,
   293,  273,  256,  241,  228, 216, 205, 195, 186, 178, 171, 164,
 };
 
-ALIGN(const int8_t dav1d_mc_subpel_filters[5][15][8], 8 ) = {
+const int8_t ALIGN(dav1d_mc_subpel_filters[5][15][8], 8) = {
     [FILTER_8TAP_REGULAR] = {
         {   0,   1,  -3,  63,   4,  -1,   0,   0 },
         {   0,   1,  -5,  61,   9,  -2,   0,   0 },
--- a/src/tables.h
+++ b/src/tables.h
@@ -34,49 +34,81 @@
 
 #include "src/levels.h"
 
-extern const uint8_t av1_al_part_ctx[2][N_BL_LEVELS][N_PARTITIONS];
+extern const uint8_t dav1d_al_part_ctx[2][N_BL_LEVELS][N_PARTITIONS];
 extern const uint8_t /* enum BlockSize */
-                     av1_block_sizes[N_BL_LEVELS][N_PARTITIONS][2];
+                     dav1d_block_sizes[N_BL_LEVELS][N_PARTITIONS][2];
 // width, height (in 4px blocks), log2 versions of these two
-extern const uint8_t av1_block_dimensions[N_BS_SIZES][4];
+extern const uint8_t dav1d_block_dimensions[N_BS_SIZES][4];
 typedef struct TxfmInfo {
     // width, height (in 4px blocks), log2 of them, min/max of log2, sub, pad
     uint8_t w, h, lw, lh, min, max, sub, ctx;
 } TxfmInfo;
-extern const TxfmInfo av1_txfm_dimensions[N_RECT_TX_SIZES];
+extern const TxfmInfo dav1d_txfm_dimensions[N_RECT_TX_SIZES];
 extern const uint8_t /* enum (Rect)TxfmSize */
-                     av1_max_txfm_size_for_bs[N_BS_SIZES][4 /* y, 420, 422, 444 */];
+                     dav1d_max_txfm_size_for_bs[N_BS_SIZES][4 /* y, 420, 422, 444 */];
 extern const uint8_t /* enum TxfmType */
-                     av1_txtp_from_uvmode[N_UV_INTRA_PRED_MODES];
+                     dav1d_txtp_from_uvmode[N_UV_INTRA_PRED_MODES];
 
 extern const uint8_t /* enum InterPredMode */
-                     av1_comp_inter_pred_modes[N_COMP_INTER_PRED_MODES][2];
+                     dav1d_comp_inter_pred_modes[N_COMP_INTER_PRED_MODES][2];
 
-extern const uint8_t av1_tx_type_count[N_TXTP_SETS];
+extern const uint8_t dav1d_tx_type_count[N_TXTP_SETS];
 extern const uint8_t /* enum TxfmType */
-                     av1_tx_types_per_set[N_TXTP_SETS][N_TX_TYPES];
-extern const uint8_t av1_tx_type_set_index[2][N_TXTP_SETS];
+                     dav1d_tx_types_per_set[N_TXTP_SETS][N_TX_TYPES];
+extern const uint8_t dav1d_tx_type_set_index[2][N_TXTP_SETS];
 
-extern const uint8_t av1_filter_mode_to_y_mode[5];
-extern const uint8_t av1_ymode_size_context[N_BS_SIZES];
-extern const uint8_t av1_nz_map_ctx_offset[N_RECT_TX_SIZES][5][5];
+extern const uint8_t dav1d_filter_mode_to_y_mode[5];
+extern const uint8_t dav1d_ymode_size_context[N_BS_SIZES];
+extern const uint8_t dav1d_nz_map_ctx_offset[N_RECT_TX_SIZES][5][5];
 extern const uint8_t /* enum TxClass */
-                     av1_tx_type_class[N_TX_TYPES_PLUS_LL];
+                     dav1d_tx_type_class[N_TX_TYPES_PLUS_LL];
 extern const uint8_t /* enum Filter2d */
-                     av1_filter_2d[N_FILTERS /* h */][N_FILTERS /* v */];
-extern const uint8_t /* enum FilterMode */ eve_av1_filter_dir[N_2D_FILTERS][2];
-extern const uint8_t intra_mode_context[N_INTRA_PRED_MODES];
-extern const uint8_t av1_wedge_ctx_lut[N_BS_SIZES];
+                     dav1d_filter_2d[N_FILTERS /* h */][N_FILTERS /* v */];
+extern const uint8_t /* enum FilterMode */ dav1d_filter_dir[N_2D_FILTERS][2];
+extern const uint8_t dav1d_intra_mode_context[N_INTRA_PRED_MODES];
+extern const uint8_t dav1d_wedge_ctx_lut[N_BS_SIZES];
 
-extern const unsigned cfl_allowed_mask;
-extern const unsigned wedge_allowed_mask;
-extern const unsigned interintra_allowed_mask;
+static const unsigned cfl_allowed_mask =
+    (1 << BS_32x32) |
+    (1 << BS_32x16) |
+    (1 << BS_32x8) |
+    (1 << BS_16x32) |
+    (1 << BS_16x16) |
+    (1 << BS_16x8) |
+    (1 << BS_16x4) |
+    (1 << BS_8x32) |
+    (1 << BS_8x16) |
+    (1 << BS_8x8) |
+    (1 << BS_8x4) |
+    (1 << BS_4x16) |
+    (1 << BS_4x8) |
+    (1 << BS_4x4);
 
-extern const WarpedMotionParams default_wm_params;
+static const unsigned wedge_allowed_mask =
+    (1 << BS_32x32) |
+    (1 << BS_32x16) |
+    (1 << BS_32x8) |
+    (1 << BS_16x32) |
+    (1 << BS_16x16) |
+    (1 << BS_16x8) |
+    (1 << BS_8x32) |
+    (1 << BS_8x16) |
+    (1 << BS_8x8);
 
-extern const int16_t sgr_params[16][4];
-extern const int16_t sgr_x_by_xplus1[256];
-extern const int16_t sgr_one_by_x[25];
+static const unsigned interintra_allowed_mask =
+    (1 << BS_32x32) |
+    (1 << BS_32x16) |
+    (1 << BS_16x32) |
+    (1 << BS_16x16) |
+    (1 << BS_16x8) |
+    (1 << BS_8x16) |
+    (1 << BS_8x8);
+
+extern const WarpedMotionParams dav1d_default_wm_params;
+
+extern const int16_t dav1d_sgr_params[16][4];
+extern const int16_t dav1d_sgr_x_by_xplus1[256];
+extern const int16_t dav1d_sgr_one_by_x[25];
 
 extern const int8_t dav1d_mc_subpel_filters[5][15][8];
 extern const int8_t dav1d_mc_warp_filter[][8];
--- a/src/thread_task.c
+++ b/src/thread_task.c
@@ -50,7 +50,7 @@
         }
         pthread_mutex_unlock(&f->frame_thread.td.lock);
 
-        decode_frame(f);
+        dav1d_decode_frame(f);
     }
 
     return NULL;
@@ -89,7 +89,7 @@
             for (t->by = ts->tiling.row_start; t->by < ts->tiling.row_end;
                  t->by += f->sb_step)
             {
-                decode_tile_sbrow(t);
+                dav1d_decode_tile_sbrow(t);
 
                 // signal progress
                 pthread_mutex_lock(&ts->tile_thread.lock);
@@ -121,7 +121,7 @@
             // waiting for the post-filter to complete
             t->ts = ts;
             t->by = sby << f->sb_shift;
-            decode_tile_sbrow(t);
+            dav1d_decode_tile_sbrow(t);
 
             // signal progress
             pthread_mutex_lock(&ts->tile_thread.lock);
--- a/src/thread_task.h
+++ b/src/thread_task.h
@@ -30,10 +30,10 @@
 
 #include "src/internal.h"
 
-int decode_frame(Dav1dFrameContext *f);
+int dav1d_decode_frame(Dav1dFrameContext *f);
 void *dav1d_frame_task(void *data);
 
-int decode_tile_sbrow(Dav1dTileContext *t);
+int dav1d_decode_tile_sbrow(Dav1dTileContext *t);
 void *dav1d_tile_task(void *data);
 
 #endif /* __DAV1D_SRC_THREAD_TASK_H__ */
--- a/src/warpmv.c
+++ b/src/warpmv.c
@@ -82,7 +82,7 @@
     return div_lut[f];
 }
 
-int get_shear_params(WarpedMotionParams *const wm) {
+int dav1d_get_shear_params(WarpedMotionParams *const wm) {
     const int32_t *const mat = wm->matrix;
 
     if (mat[2] <= 0) return 1;
@@ -131,10 +131,10 @@
     return iclip(v2, 0xe001, 0x11fff);
 }
 
-int find_affine_int(const int (*pts)[2][2], const int np,
-                    const int bw4, const int bh4,
-                    const mv mv, WarpedMotionParams *const wm,
-                    const int bx4, const int by4)
+int dav1d_find_affine_int(const int (*pts)[2][2], const int np,
+                          const int bw4, const int bh4,
+                          const mv mv, WarpedMotionParams *const wm,
+                          const int bx4, const int by4)
 {
     int32_t *const mat = wm->matrix;
     int a[2][2] = { { 0, 0 }, { 0, 0 } };
--- a/src/warpmv.h
+++ b/src/warpmv.h
@@ -30,8 +30,8 @@
 
 #include "src/levels.h"
 
-int get_shear_params(WarpedMotionParams *wm);
-int find_affine_int(const int (*pts)[2][2], int np, int bw4, int bh4,
-                    mv mv, WarpedMotionParams *wm, int by, int bx);
+int dav1d_get_shear_params(WarpedMotionParams *wm);
+int dav1d_find_affine_int(const int (*pts)[2][2], int np, int bw4, int bh4,
+                          mv mv, WarpedMotionParams *wm, int by, int bx);
 
 #endif /* __DAV1D_SRC_WARPMV_H__ */
--- a/src/wedge.c
+++ b/src/wedge.c
@@ -113,7 +113,7 @@
 static uint8_t wedge_masks_420_4x8[  2 * 16 *  4 *  8];
 static uint8_t wedge_masks_420_4x4[  2 * 16 *  4 *  4];
 
-const uint8_t *wedge_masks[N_BS_SIZES][3][2][16];
+const uint8_t *dav1d_wedge_masks[N_BS_SIZES][3][2][16];
 
 static void insert_border(uint8_t *const dst, const uint8_t *src,
                           const int ctr)
@@ -194,14 +194,14 @@
     // assign pointers in externally visible array
     for (int n = 0; n < 16; n++) {
         const int sign = (signs >> n) & 1;
-        wedge_masks[bs][0][0][n] = &masks_444[ sign * sign_stride_444];
+        dav1d_wedge_masks[bs][0][0][n] = &masks_444[ sign * sign_stride_444];
         // not using !sign is intentional here, since 444 does not require
         // any rounding since no chroma subsampling is applied.
-        wedge_masks[bs][0][1][n] = &masks_444[ sign * sign_stride_444];
-        wedge_masks[bs][1][0][n] = &masks_422[ sign * sign_stride_422];
-        wedge_masks[bs][1][1][n] = &masks_422[!sign * sign_stride_422];
-        wedge_masks[bs][2][0][n] = &masks_420[ sign * sign_stride_420];
-        wedge_masks[bs][2][1][n] = &masks_420[!sign * sign_stride_420];
+        dav1d_wedge_masks[bs][0][1][n] = &masks_444[ sign * sign_stride_444];
+        dav1d_wedge_masks[bs][1][0][n] = &masks_422[ sign * sign_stride_422];
+        dav1d_wedge_masks[bs][1][1][n] = &masks_422[!sign * sign_stride_422];
+        dav1d_wedge_masks[bs][2][0][n] = &masks_420[ sign * sign_stride_420];
+        dav1d_wedge_masks[bs][2][1][n] = &masks_420[!sign * sign_stride_420];
         masks_444 += n_stride_444;
         masks_422 += n_stride_422;
         masks_420 += n_stride_420;
@@ -211,18 +211,18 @@
         // means we would have to duplicate the sign correction
         // logic in two places, which isn't very nice, or mark
         // the table faced externally as non-const, which also sucks
-        init_chroma((uint8_t *) wedge_masks[bs][1][0][n],
-                    wedge_masks[bs][0][0][n], 0, w, h, 0);
-        init_chroma((uint8_t *) wedge_masks[bs][1][1][n],
-                    wedge_masks[bs][0][0][n], 1, w, h, 0);
-        init_chroma((uint8_t *) wedge_masks[bs][2][0][n],
-                    wedge_masks[bs][0][0][n], 0, w, h, 1);
-        init_chroma((uint8_t *) wedge_masks[bs][2][1][n],
-                    wedge_masks[bs][0][0][n], 1, w, h, 1);
+        init_chroma((uint8_t *)dav1d_wedge_masks[bs][1][0][n],
+                    dav1d_wedge_masks[bs][0][0][n], 0, w, h, 0);
+        init_chroma((uint8_t *)dav1d_wedge_masks[bs][1][1][n],
+                    dav1d_wedge_masks[bs][0][0][n], 1, w, h, 0);
+        init_chroma((uint8_t *)dav1d_wedge_masks[bs][2][0][n],
+                    dav1d_wedge_masks[bs][0][0][n], 0, w, h, 1);
+        init_chroma((uint8_t *)dav1d_wedge_masks[bs][2][1][n],
+                    dav1d_wedge_masks[bs][0][0][n], 1, w, h, 1);
     }
 }
 
-void av1_init_wedge_masks(void) {
+void dav1d_init_wedge_masks(void) {
     // This function is guaranteed to be called only once
 
     enum WedgeMasterLineType {
@@ -290,7 +290,7 @@
     [II_SMOOTH_PRED] = ii_nondc_mask_##sz[II_SMOOTH_PRED - 1]
 #define set(sz_444, sz_422, sz_420) \
     { { set1(sz_444) }, { set1(sz_422) }, { set1(sz_420) } }
-const uint8_t *const ii_masks[N_BS_SIZES][3][N_INTER_INTRA_PRED_MODES] = {
+const uint8_t *dav1d_ii_masks[N_BS_SIZES][3][N_INTER_INTRA_PRED_MODES] = {
     [BS_8x8]   = set( 8x8,   4x8,   4x4),
     [BS_8x16]  = set( 8x16,  4x16,  4x8),
     [BS_16x8]  = set(16x16,  8x8,   8x8),
@@ -321,7 +321,7 @@
     }
 }
 
-void av1_init_interintra_masks(void) {
+void dav1d_init_interintra_masks(void) {
     // This function is guaranteed to be called only once
 
     memset(ii_dc_mask, 32, 32 * 32);
--- a/src/wedge.h
+++ b/src/wedge.h
@@ -30,12 +30,12 @@
 
 #include "src/levels.h"
 
-void av1_init_wedge_masks(void);
-extern const uint8_t *wedge_masks[N_BS_SIZES][3 /* 444/luma, 422, 420 */]
+void dav1d_init_wedge_masks(void);
+extern const uint8_t *dav1d_wedge_masks[N_BS_SIZES][3 /* 444/luma, 422, 420 */]
                                  [2 /* sign */][16 /* wedge_idx */];
 
-void av1_init_interintra_masks(void);
-extern const uint8_t *const ii_masks[N_BS_SIZES][3 /* 444/luma, 422, 420 */]
+void dav1d_init_interintra_masks(void);
+extern const uint8_t *dav1d_ii_masks[N_BS_SIZES][3 /* 444/luma, 422, 420 */]
                                     [N_INTER_INTRA_PRED_MODES];
 
 #endif /* __DAV1D_SRC_WEDGE_H__ */
--- a/tests/checkasm/itx.c
+++ b/tests/checkasm/itx.c
@@ -138,7 +138,7 @@
      * dimensions are non-zero. This leads to braching to specific optimized
      * simd versions (e.g. dc-only) so that we get full asm coverage in this
      * test */
-    const int16_t *const scan = av1_scans[tx][av1_tx_type_class[txtp]];
+    const int16_t *const scan = dav1d_scans[tx][dav1d_tx_type_class[txtp]];
     const int sub_high = subsh > 0 ? subsh * 8 - 1 : 0;
     const int sub_low  = subsh > 1 ? sub_high - 8 : 0;
     int n, eob;
@@ -242,11 +242,11 @@
 
     for (int i = 0; i < N_RECT_TX_SIZES; i++) {
         const enum RectTxfmSize tx = txfm_size_order[i];
-        const int w = av1_txfm_dimensions[tx].w * 4;
-        const int h = av1_txfm_dimensions[tx].h * 4;
+        const int w = dav1d_txfm_dimensions[tx].w * 4;
+        const int h = dav1d_txfm_dimensions[tx].h * 4;
         const int sw = imin(w, 32), sh = imin(h, 32);
-        const int subsh_max = subsh_iters[imax(av1_txfm_dimensions[tx].lw,
-                                               av1_txfm_dimensions[tx].lh)];
+        const int subsh_max = subsh_iters[imax(dav1d_txfm_dimensions[tx].lw,
+                                               dav1d_txfm_dimensions[tx].lh)];
 
         for (enum TxfmType txtp = 0; txtp < N_TX_TYPES_PLUS_LL; txtp++)
             for (int subsh = 0; subsh < subsh_max; subsh++)