shithub: dav1d

Download patch

ref: 7cc54b91a4f5351a70149eb1e97ea2f71b0bf873
parent: 03d4ede0656490a384e2a2ffe10b16c5aabdc8ec
author: Ronald S. Bultje <[email protected]>
date: Sat Nov 17 15:55:44 EST 2018

Move Av1FrameHeader and Av1SequenceHeader into public headers

Add DAV1D_/Dav1d prefix to everything.

--- /dev/null
+++ b/include/dav1d/headers.h
@@ -1,0 +1,356 @@
+/*
+ * Copyright © 2018, VideoLAN and dav1d authors
+ * Copyright © 2018, Two Orioles, LLC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ *    list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __DAV1D_HEADERS_H__
+#define __DAV1D_HEADERS_H__
+
+// Constants from Section 3. "Symbols and abbreviated terms"
+#define DAV1D_MAX_TILE_COLS 64
+#define DAV1D_MAX_TILE_ROWS 64
+
+enum Dav1dTxfmMode {
+    DAV1D_TX_4X4_ONLY,
+    DAV1D_TX_LARGEST,
+    DAV1D_TX_SWITCHABLE,
+    DAV1D_N_TX_MODES,
+};
+
+enum Dav1dFilterMode {
+    DAV1D_FILTER_8TAP_REGULAR,
+    DAV1D_FILTER_8TAP_SMOOTH,
+    DAV1D_FILTER_8TAP_SHARP,
+    DAV1D_N_SWITCHABLE_FILTERS,
+    DAV1D_FILTER_BILINEAR = DAV1D_N_SWITCHABLE_FILTERS,
+    DAV1D_N_FILTERS,
+    DAV1D_FILTER_SWITCHABLE = DAV1D_N_FILTERS,
+};
+
+enum Dav1dAdaptiveBoolean {
+    DAV1D_OFF = 0,
+    DAV1D_ON = 1,
+    DAV1D_ADAPTIVE = 2,
+};
+
+enum Dav1dRestorationType {
+    DAV1D_RESTORATION_NONE,
+    DAV1D_RESTORATION_SWITCHABLE,
+    DAV1D_RESTORATION_WIENER,
+    DAV1D_RESTORATION_SGRPROJ,
+};
+
+enum Dav1dWarpedMotionType {
+    DAV1D_WM_TYPE_IDENTITY,
+    DAV1D_WM_TYPE_TRANSLATION,
+    DAV1D_WM_TYPE_ROT_ZOOM,
+    DAV1D_WM_TYPE_AFFINE,
+};
+
+typedef struct Dav1dWarpedMotionParams {
+    enum Dav1dWarpedMotionType type;
+    int32_t matrix[6];
+    union {
+        struct {
+            int16_t alpha, beta, gamma, delta;
+        };
+        int16_t abcd[4];
+    };
+} Dav1dWarpedMotionParams;
+
+enum Dav1dPixelLayout {
+    DAV1D_PIXEL_LAYOUT_I400, ///< monochrome
+    DAV1D_PIXEL_LAYOUT_I420, ///< 4:2:0 planar
+    DAV1D_PIXEL_LAYOUT_I422, ///< 4:2:2 planar
+    DAV1D_PIXEL_LAYOUT_I444, ///< 4:4:4 planar
+};
+
+enum Dav1dFrameType {
+    DAV1D_FRAME_TYPE_KEY = 0,    ///< Key Intra frame
+    DAV1D_FRAME_TYPE_INTER = 1,  ///< Inter frame
+    DAV1D_FRAME_TYPE_INTRA = 2,  ///< Non key Intra frame
+    DAV1D_FRAME_TYPE_SWITCH = 3, ///< Switch Inter frame
+};
+
+enum Dav1dColorPrimaries {
+    DAV1D_COLOR_PRI_BT709 = 1,
+    DAV1D_COLOR_PRI_UNKNOWN = 2,
+    DAV1D_COLOR_PRI_BT470M = 4,
+    DAV1D_COLOR_PRI_BT470BG = 5,
+    DAV1D_COLOR_PRI_BT601 = 6,
+    DAV1D_COLOR_PRI_SMPTE240 = 7,
+    DAV1D_COLOR_PRI_FILM = 8,
+    DAV1D_COLOR_PRI_BT2020 = 9,
+    DAV1D_COLOR_PRI_XYZ = 10,
+    DAV1D_COLOR_PRI_SMPTE431 = 11,
+    DAV1D_COLOR_PRI_SMPTE432 = 12,
+    DAV1D_COLOR_PRI_EBU3213 = 22,
+};
+
+enum Dav1dTransferCharacteristics {
+    DAV1D_TRC_BT709 = 1,
+    DAV1D_TRC_UNKNOWN = 2,
+    DAV1D_TRC_BT470M = 4,
+    DAV1D_TRC_BT470BG = 5,
+    DAV1D_TRC_BT601 = 6,
+    DAV1D_TRC_SMPTE240 = 7,
+    DAV1D_TRC_LINEAR = 8,
+    DAV1D_TRC_LOG100 = 9,         ///< logarithmic (100:1 range)
+    DAV1D_TRC_LOG100_SQRT10 = 10, ///< lograithmic (100*sqrt(10):1 range)
+    DAV1D_TRC_IEC61966 = 11,
+    DAV1D_TRC_BT1361 = 12,
+    DAV1D_TRC_SRGB = 13,
+    DAV1D_TRC_BT2020_10BIT = 14,
+    DAV1D_TRC_BT2020_12BIT = 15,
+    DAV1D_TRC_SMPTE2084 = 16,     ///< PQ
+    DAV1D_TRC_SMPTE428 = 17,
+    DAV1D_TRC_HLG = 18,           ///< hybrid log/gamma (BT.2100 / ARIB STD-B67)
+};
+
+enum Dav1dMatrixCoefficients {
+    DAV1D_MC_IDENTITY = 0,
+    DAV1D_MC_BT709 = 1,
+    DAV1D_MC_UNKNOWN = 2,
+    DAV1D_MC_FCC = 4,
+    DAV1D_MC_BT470BG = 5,
+    DAV1D_MC_BT601 = 6,
+    DAV1D_MC_SMPTE240 = 7,
+    DAV1D_MC_SMPTE_YCGCO = 8,
+    DAV1D_MC_BT2020_NCL = 9,
+    DAV1D_MC_BT2020_CL = 10,
+    DAV1D_MC_SMPTE2085 = 11,
+    DAV1D_MC_CHROMAT_NCL = 12, ///< Chromaticity-derived
+    DAV1D_MC_CHROMAT_CL = 13,
+    DAV1D_MC_ICTCP = 14,
+};
+
+enum Dav1dChromaSamplePosition {
+    DAV1D_CHR_UNKNOWN = 0,
+    DAV1D_CHR_VERTICAL = 1,  ///< Horizontally co-located with luma(0, 0)
+                           ///< sample, between two vertical samples
+    DAV1D_CHR_COLOCATED = 2, ///< Co-located with luma(0, 0) sample
+};
+
+typedef struct Dav1dSequenceHeader {
+    int profile;
+    int still_picture;
+    int reduced_still_picture_header;
+    int timing_info_present;
+    int num_units_in_tick;
+    int time_scale;
+    int equal_picture_interval;
+    int num_ticks_per_picture;
+    int decoder_model_info_present;
+    int encoder_decoder_buffer_delay_length;
+    int num_units_in_decoding_tick;
+    int buffer_removal_delay_length;
+    int frame_presentation_delay_length;
+    int display_model_info_present;
+    int num_operating_points;
+    struct Dav1dSequenceHeaderOperatingPoint {
+        int idc;
+        int major_level, minor_level;
+        int tier;
+        int decoder_model_param_present;
+        int decoder_buffer_delay;
+        int encoder_buffer_delay;
+        int low_delay_mode;
+        int display_model_param_present;
+        int initial_display_delay;
+    } operating_points[32];
+    int max_width, max_height, width_n_bits, height_n_bits;
+    int frame_id_numbers_present;
+    int delta_frame_id_n_bits;
+    int frame_id_n_bits;
+    int sb128;
+    int filter_intra;
+    int intra_edge_filter;
+    int inter_intra;
+    int masked_compound;
+    int warped_motion;
+    int dual_filter;
+    int order_hint;
+    int jnt_comp;
+    int ref_frame_mvs;
+    enum Dav1dAdaptiveBoolean screen_content_tools;
+    enum Dav1dAdaptiveBoolean force_integer_mv;
+    int order_hint_n_bits;
+    int super_res;
+    int cdef;
+    int restoration;
+    int bpc;
+    int hbd;
+    int color_description_present;
+    enum Dav1dPixelLayout layout;
+    enum Dav1dColorPrimaries pri;
+    enum Dav1dTransferCharacteristics trc;
+    enum Dav1dMatrixCoefficients mtrx;
+    enum Dav1dChromaSamplePosition chr;
+    int color_range;
+    int separate_uv_delta_q;
+    int film_grain_present;
+} Dav1dSequenceHeader;
+
+#define DAV1D_NUM_SEGMENTS 8
+
+typedef struct Dav1dSegmentationData {
+    int delta_q;
+    int delta_lf_y_v, delta_lf_y_h, delta_lf_u, delta_lf_v;
+    int ref;
+    int skip;
+    int globalmv;
+} Dav1dSegmentationData;
+
+typedef struct Dav1dSegmentationDataSet {
+    Dav1dSegmentationData d[DAV1D_NUM_SEGMENTS];
+    int preskip;
+    int last_active_segid;
+} Dav1dSegmentationDataSet;
+
+typedef struct Dav1dLoopfilterModeRefDeltas {
+    int mode_delta[2];
+    int ref_delta[8];
+} Dav1dLoopfilterModeRefDeltas;
+
+typedef struct Dav1dFilmGrainData {
+    uint16_t seed;
+    int num_y_points;
+    uint8_t y_points[14][2 /* value, scaling */];
+    int chroma_scaling_from_luma;
+    int num_uv_points[2];
+    uint8_t uv_points[2][10][2 /* value, scaling */];
+    int scaling_shift;
+    int ar_coeff_lag;
+    int8_t ar_coeffs_y[24];
+    int8_t ar_coeffs_uv[2][25];
+    int ar_coeff_shift;
+    int grain_scale_shift;
+    int uv_mult[2];
+    int uv_luma_mult[2];
+    int uv_offset[2];
+    int overlap_flag;
+    int clip_to_restricted_range;
+} Dav1dFilmGrainData;
+
+typedef struct Dav1dFrameHeader {
+    int show_existing_frame;
+    int existing_frame_idx;
+    int frame_id;
+    int frame_presentation_delay;
+    enum Dav1dFrameType frame_type;
+    int show_frame;
+    int showable_frame;
+    int error_resilient_mode;
+    int disable_cdf_update;
+    int allow_screen_content_tools;
+    int force_integer_mv;
+    int frame_size_override;
+#define DAV1D_PRIMARY_REF_NONE 7
+    int primary_ref_frame;
+    int buffer_removal_time_present;
+    struct Dav1dFrameHeaderOperatingPoint {
+        int buffer_removal_time;
+    } operating_points[32];
+    int frame_offset;
+    int refresh_frame_flags;
+    int width[2 /* { coded_width, superresolution_upscaled_width } */], height;
+    int render_width, render_height;
+    struct {
+        int width_scale_denominator;
+        int enabled;
+    } super_res;
+    int have_render_size;
+    int allow_intrabc;
+    int frame_ref_short_signaling;
+    int refidx[7];
+    int hp;
+    enum Dav1dFilterMode subpel_filter_mode;
+    int switchable_motion_mode;
+    int use_ref_frame_mvs;
+    int refresh_context;
+    struct {
+        int uniform;
+        unsigned n_bytes;
+        int min_log2_cols, max_log2_cols, log2_cols, cols;
+        int min_log2_rows, max_log2_rows, log2_rows, rows;
+        uint16_t col_start_sb[DAV1D_MAX_TILE_COLS + 1];
+        uint16_t row_start_sb[DAV1D_MAX_TILE_ROWS + 1];
+        int update;
+    } tiling;
+    struct {
+        int yac;
+        int ydc_delta;
+        int udc_delta, uac_delta, vdc_delta, vac_delta;
+        int qm, qm_y, qm_u, qm_v;
+    } quant;
+    struct {
+        int enabled, update_map, temporal, update_data;
+        Dav1dSegmentationDataSet seg_data;
+        int lossless[DAV1D_NUM_SEGMENTS], qidx[DAV1D_NUM_SEGMENTS];
+    } segmentation;
+    struct {
+        struct {
+            int present;
+            int res_log2;
+        } q;
+        struct {
+            int present;
+            int res_log2;
+            int multi;
+        } lf;
+    } delta;
+    int all_lossless;
+    struct {
+        int level_y[2];
+        int level_u, level_v;
+        int mode_ref_delta_enabled;
+        int mode_ref_delta_update;
+        Dav1dLoopfilterModeRefDeltas mode_ref_deltas;
+        int sharpness;
+    } loopfilter;
+    struct {
+        int damping;
+        int n_bits;
+        int y_strength[8];
+        int uv_strength[8];
+    } cdef;
+    struct {
+        enum Dav1dRestorationType type[3];
+        int unit_size[2];
+    } restoration;
+    enum Dav1dTxfmMode txfm_mode;
+    int switchable_comp_refs;
+    int skip_mode_allowed, skip_mode_enabled, skip_mode_refs[2];
+    int warp_motion;
+    int reduced_txtp_set;
+    Dav1dWarpedMotionParams gmv[7];
+    struct {
+        int present, update;
+        Dav1dFilmGrainData data;
+    } film_grain;
+    int temporal_id, spatial_id;
+} Dav1dFrameHeader;
+
+#endif /* __DAV1D_HEADERS_H__ */
--- a/include/dav1d/picture.h
+++ b/include/dav1d/picture.h
@@ -32,99 +32,7 @@
 #include <stdint.h>
 
 #include "common.h"
-
-enum Dav1dPixelLayout {
-    DAV1D_PIXEL_LAYOUT_I400, ///< monochrome
-    DAV1D_PIXEL_LAYOUT_I420, ///< 4:2:0 planar
-    DAV1D_PIXEL_LAYOUT_I422, ///< 4:2:2 planar
-    DAV1D_PIXEL_LAYOUT_I444, ///< 4:4:4 planar
-};
-
-enum Dav1dFrameType {
-    DAV1D_FRAME_TYPE_KEY = 0,    ///< Key Intra frame
-    DAV1D_FRAME_TYPE_INTER = 1,  ///< Inter frame
-    DAV1D_FRAME_TYPE_INTRA = 2,  ///< Non key Intra frame
-    DAV1D_FRAME_TYPE_SWITCH = 3, ///< Switch Inter frame
-};
-
-enum Dav1dColorPrimaries {
-    DAV1D_COLOR_PRI_BT709 = 1,
-    DAV1D_COLOR_PRI_UNKNOWN = 2,
-    DAV1D_COLOR_PRI_BT470M = 4,
-    DAV1D_COLOR_PRI_BT470BG = 5,
-    DAV1D_COLOR_PRI_BT601 = 6,
-    DAV1D_COLOR_PRI_SMPTE240 = 7,
-    DAV1D_COLOR_PRI_FILM = 8,
-    DAV1D_COLOR_PRI_BT2020 = 9,
-    DAV1D_COLOR_PRI_XYZ = 10,
-    DAV1D_COLOR_PRI_SMPTE431 = 11,
-    DAV1D_COLOR_PRI_SMPTE432 = 12,
-    DAV1D_COLOR_PRI_EBU3213 = 22,
-};
-
-enum Dav1dTransferCharacteristics {
-    DAV1D_TRC_BT709 = 1,
-    DAV1D_TRC_UNKNOWN = 2,
-    DAV1D_TRC_BT470M = 4,
-    DAV1D_TRC_BT470BG = 5,
-    DAV1D_TRC_BT601 = 6,
-    DAV1D_TRC_SMPTE240 = 7,
-    DAV1D_TRC_LINEAR = 8,
-    DAV1D_TRC_LOG100 = 9,         ///< logarithmic (100:1 range)
-    DAV1D_TRC_LOG100_SQRT10 = 10, ///< lograithmic (100*sqrt(10):1 range)
-    DAV1D_TRC_IEC61966 = 11,
-    DAV1D_TRC_BT1361 = 12,
-    DAV1D_TRC_SRGB = 13,
-    DAV1D_TRC_BT2020_10BIT = 14,
-    DAV1D_TRC_BT2020_12BIT = 15,
-    DAV1D_TRC_SMPTE2084 = 16,     ///< PQ
-    DAV1D_TRC_SMPTE428 = 17,
-    DAV1D_TRC_HLG = 18,           ///< hybrid log/gamma (BT.2100 / ARIB STD-B67)
-};
-
-enum Dav1dMatrixCoefficients {
-    DAV1D_MC_IDENTITY = 0,
-    DAV1D_MC_BT709 = 1,
-    DAV1D_MC_UNKNOWN = 2,
-    DAV1D_MC_FCC = 4,
-    DAV1D_MC_BT470BG = 5,
-    DAV1D_MC_BT601 = 6,
-    DAV1D_MC_SMPTE240 = 7,
-    DAV1D_MC_SMPTE_YCGCO = 8,
-    DAV1D_MC_BT2020_NCL = 9,
-    DAV1D_MC_BT2020_CL = 10,
-    DAV1D_MC_SMPTE2085 = 11,
-    DAV1D_MC_CHROMAT_NCL = 12, ///< Chromaticity-derived
-    DAV1D_MC_CHROMAT_CL = 13,
-    DAV1D_MC_ICTCP = 14,
-};
-
-enum Dav1dChromaSamplePosition {
-    DAV1D_CHR_UNKNOWN = 0,
-    DAV1D_CHR_VERTICAL = 1,  ///< Horizontally co-located with luma(0, 0)
-                           ///< sample, between two vertical samples
-    DAV1D_CHR_COLOCATED = 2, ///< Co-located with luma(0, 0) sample
-};
-
-typedef struct Dav1dFilmGrainData {
-    uint16_t seed;
-    int num_y_points;
-    uint8_t y_points[14][2 /* value, scaling */];
-    int chroma_scaling_from_luma;
-    int num_uv_points[2];
-    uint8_t uv_points[2][10][2 /* value, scaling */];
-    int scaling_shift;
-    int ar_coeff_lag;
-    int8_t ar_coeffs_y[24];
-    int8_t ar_coeffs_uv[2][25];
-    int ar_coeff_shift;
-    int grain_scale_shift;
-    int8_t uv_mult[2];
-    int8_t uv_luma_mult[2];
-    int16_t uv_offset[2];
-    int overlap_flag;
-    int clip_to_restricted_range;
-} Dav1dFilmGrainData;
+#include "headers.h"
 
 typedef struct Dav1dPictureParameters {
     int w; ///< width (in pixels)
--- a/src/cdf.c
+++ b/src/cdf.c
@@ -4072,7 +4072,7 @@
     dav1d_cdf_thread_ref(cdf, &cdf_init[qcat]);
 }
 
-void dav1d_update_tile_cdf(const Av1FrameHeader *const hdr,
+void dav1d_update_tile_cdf(const Dav1dFrameHeader *const hdr,
                            CdfContext *const dst,
                            const CdfContext *const src)
 {
@@ -4138,7 +4138,7 @@
     update_cdf_4d(N_TX_SIZES, 2, 41 /*42*/, 4, coef.base_tok);
     update_bit_2d(2, 3, coef.dc_sign);
     update_cdf_4d(4, 2, 21, 4, coef.br_tok);
-    update_cdf_2d(3, NUM_SEGMENTS, m.seg_id);
+    update_cdf_2d(3, DAV1D_NUM_SEGMENTS, m.seg_id);
     update_cdf_1d(8, m.cfl_sign);
     update_cdf_2d(6, 16, m.cfl_alpha);
     update_bit_0d(m.restore_wiener);
@@ -4171,7 +4171,7 @@
 
     update_bit_1d(3, m.skip_mode);
     update_cdf_2d(4, N_INTRA_PRED_MODES, m.y_mode);
-    update_cdf_3d(2, 8, N_SWITCHABLE_FILTERS, m.filter);
+    update_cdf_3d(2, 8, DAV1D_N_SWITCHABLE_FILTERS, m.filter);
     update_bit_1d(6, m.newmv_mode);
     update_bit_1d(2, m.globalmv_mode);
     update_bit_1d(6, m.refmv_mode);
--- a/src/cdf.h
+++ b/src/cdf.h
@@ -40,7 +40,7 @@
     uint16_t filter_intra[5 + 1];
     uint16_t uv_mode[2][N_INTRA_PRED_MODES][N_UV_INTRA_PRED_MODES + 1];
     uint16_t angle_delta[8][8];
-    uint16_t filter[2][8][N_SWITCHABLE_FILTERS + 1];
+    uint16_t filter[2][8][DAV1D_N_SWITCHABLE_FILTERS + 1];
     uint16_t newmv_mode[6][2];
     uint16_t globalmv_mode[2][2];
     uint16_t refmv_mode[6][2];
@@ -68,7 +68,7 @@
     uint16_t skip_mode[3][2];
     uint16_t partition[N_BL_LEVELS][4][N_PARTITIONS + 1];
     uint16_t seg_pred[3][2];
-    uint16_t seg_id[3][NUM_SEGMENTS + 1];
+    uint16_t seg_id[3][DAV1D_NUM_SEGMENTS + 1];
     uint16_t cfl_sign[8 + 1];
     uint16_t cfl_alpha[6][16 + 1];
     uint16_t restore_wiener[2];
@@ -132,7 +132,7 @@
 } CdfThreadContext;
 
 void dav1d_init_states(CdfThreadContext *cdf, int qidx);
-void dav1d_update_tile_cdf(const Av1FrameHeader *hdr, CdfContext *dst,
+void dav1d_update_tile_cdf(const Dav1dFrameHeader *hdr, CdfContext *dst,
                          const CdfContext *src);
 
 void dav1d_cdf_thread_alloc(CdfThreadContext *cdf, struct thread_data *t);
--- a/src/decode.c
+++ b/src/decode.c
@@ -49,8 +49,8 @@
 #include "src/thread_task.h"
 #include "src/warpmv.h"
 
-static void init_quant_tables(const Av1SequenceHeader *const seq_hdr,
-                              const Av1FrameHeader *const frame_hdr,
+static void init_quant_tables(const Dav1dSequenceHeader *const seq_hdr,
+                              const Dav1dFrameHeader *const frame_hdr,
                               const int qidx, uint16_t (*dq)[3][2])
 {
     for (int i = 0; i < (frame_hdr->segmentation.enabled ? 8 : 1); i++) {
@@ -283,7 +283,7 @@
 static void derive_warpmv(const Dav1dTileContext *const t,
                           const int bw4, const int bh4,
                           const uint64_t masks[2], const struct mv mv,
-                          WarpedMotionParams *const wmp)
+                          Dav1dWarpedMotionParams *const wmp)
 {
     int pts[8][2 /* in, out */][2 /* x, y */], np = 0;
     const Dav1dFrameContext *const f = t->f;
@@ -352,9 +352,9 @@
     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;
+        wmp->type = DAV1D_WM_TYPE_AFFINE;
     } else
-        wmp->type = WM_TYPE_IDENTITY;
+        wmp->type = DAV1D_WM_TYPE_IDENTITY;
 }
 
 static inline int findoddzero(const uint8_t *buf, int len) {
@@ -617,7 +617,7 @@
         b->max_ytx == TX_4X4)
     {
         b->max_ytx = b->uvtx = TX_4X4;
-        if (f->frame_hdr->txfm_mode == TX_SWITCHABLE) {
+        if (f->frame_hdr->txfm_mode == DAV1D_TX_SWITCHABLE) {
 #define set_ctx(type, dir, diridx, off, mul, rep_macro) \
             rep_macro(type, t->dir tx, off, TX_4X4)
             case_set(bh4, l., 1, by4);
@@ -624,8 +624,8 @@
             case_set(bw4, a->, 0, bx4);
 #undef set_ctx
         }
-    } else if (f->frame_hdr->txfm_mode != TX_SWITCHABLE || b->skip) {
-        if (f->frame_hdr->txfm_mode == TX_SWITCHABLE) {
+    } else if (f->frame_hdr->txfm_mode != DAV1D_TX_SWITCHABLE || b->skip) {
+        if (f->frame_hdr->txfm_mode == DAV1D_TX_SWITCHABLE) {
 #define set_ctx(type, dir, diridx, off, mul, rep_macro) \
             rep_macro(type, t->dir tx, off, mul * b_dim[2 + diridx])
             case_set(bh4, l., 1, by4);
@@ -632,7 +632,7 @@
             case_set(bw4, a->, 0, bx4);
 #undef set_ctx
         } else {
-            assert(f->frame_hdr->txfm_mode == TX_LARGEST);
+            assert(f->frame_hdr->txfm_mode == DAV1D_TX_LARGEST);
         }
         b->uvtx = dav1d_max_txfm_size_for_bs[bs][f->cur.p.layout];
     } else {
@@ -664,7 +664,7 @@
 {
     unsigned seg_id = 8;
 
-    assert(f->frame_hdr->primary_ref_frame != PRIMARY_REF_NONE);
+    assert(f->frame_hdr->primary_ref_frame != DAV1D_PRIMARY_REF_NONE);
     if (dav1d_thread_picture_wait(&f->refp[f->frame_hdr->primary_ref_frame],
                                   (by + h4) * 4, PLANE_TYPE_BLOCK))
     {
@@ -763,7 +763,7 @@
     b->bp = bp;
     b->bs = bs;
 
-    const Av1SegmentationData *seg = NULL;
+    const Dav1dSegmentationData *seg = NULL;
 
     // segment_id (if seg_feature for skip/ref/gmv is enabled)
     int seg_pred = 0;
@@ -803,13 +803,13 @@
                                         &seg_ctx, f->cur_segmap, f->b4_stride);
                 const unsigned diff = msac_decode_symbol_adapt(&ts->msac,
                                                    ts->cdf.m.seg_id[seg_ctx],
-                                                   NUM_SEGMENTS);
+                                                   DAV1D_NUM_SEGMENTS);
                 const unsigned last_active_seg_id =
                     f->frame_hdr->segmentation.seg_data.last_active_segid;
                 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?
-                if (b->seg_id >= NUM_SEGMENTS) b->seg_id = 0; // error?
+                if (b->seg_id >= DAV1D_NUM_SEGMENTS) b->seg_id = 0; // error?
             }
 
             if (DEBUG_BLOCK_INFO)
@@ -875,7 +875,7 @@
             } else {
                 const unsigned diff = msac_decode_symbol_adapt(&ts->msac,
                                                    ts->cdf.m.seg_id[seg_ctx],
-                                                   NUM_SEGMENTS);
+                                                   DAV1D_NUM_SEGMENTS);
                 const unsigned last_active_seg_id =
                     f->frame_hdr->segmentation.seg_data.last_active_segid;
                 b->seg_id = neg_deinterleave(diff, pred_seg_id,
@@ -882,7 +882,7 @@
                                              last_active_seg_id + 1);
                 if (b->seg_id > last_active_seg_id) b->seg_id = 0; // error?
             }
-            if (b->seg_id >= NUM_SEGMENTS) b->seg_id = 0; // error?
+            if (b->seg_id >= DAV1D_NUM_SEGMENTS) b->seg_id = 0; // error?
         }
 
         seg = &f->frame_hdr->segmentation.seg_data.d[b->seg_id];
@@ -1140,7 +1140,7 @@
             b->tx = dav1d_max_txfm_size_for_bs[bs][0];
             b->uvtx = dav1d_max_txfm_size_for_bs[bs][f->cur.p.layout];
             t_dim = &dav1d_txfm_dimensions[b->tx];
-            if (f->frame_hdr->txfm_mode == TX_SWITCHABLE && t_dim->max > TX_4X4) {
+            if (f->frame_hdr->txfm_mode == DAV1D_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];
                 int depth = msac_decode_symbol_adapt(&ts->msac, tx_cdf,
@@ -1187,8 +1187,8 @@
             rep_macro(type, t->dir comp_type, off, mul * COMP_INTER_NONE); \
             rep_macro(type, t->dir ref[0], off, mul * ((uint8_t) -1)); \
             rep_macro(type, t->dir ref[1], off, mul * ((uint8_t) -1)); \
-            rep_macro(type, t->dir filter[0], off, mul * N_SWITCHABLE_FILTERS); \
-            rep_macro(type, t->dir filter[1], off, mul * N_SWITCHABLE_FILTERS); \
+            rep_macro(type, t->dir filter[0], off, mul * DAV1D_N_SWITCHABLE_FILTERS); \
+            rep_macro(type, t->dir filter[1], off, mul * DAV1D_N_SWITCHABLE_FILTERS); \
         }
         const enum IntraPredMode y_mode_nofilt =
             b->y_mode == FILTER_PRED ? DC_PRED : b->y_mode;
@@ -1506,7 +1506,7 @@
                 break; \
             case GLOBALMV: \
                 has_subpel_filter |= \
-                    f->frame_hdr->gmv[b->ref[idx]].type == WM_TYPE_TRANSLATION; \
+                    f->frame_hdr->gmv[b->ref[idx]].type == DAV1D_WM_TYPE_TRANSLATION; \
                 b->mv[idx] = get_gmv_2d(&f->frame_hdr->gmv[b->ref[idx]], \
                                         t->bx, t->by, bw4, bh4, f->frame_hdr); \
                 fix_mv_precision(f->frame_hdr, &b->mv[idx]); \
@@ -1640,7 +1640,7 @@
                                           t->bx, t->by, bw4, bh4, f->frame_hdr);
                     fix_mv_precision(f->frame_hdr, &b->mv[0]);
                     has_subpel_filter = imin(bw4, bh4) == 1 ||
-                        f->frame_hdr->gmv[b->ref[0]].type == WM_TYPE_TRANSLATION;
+                        f->frame_hdr->gmv[b->ref[0]].type == DAV1D_WM_TYPE_TRANSLATION;
                 } else {
                     has_subpel_filter = 1;
                     if (msac_decode_bool_adapt(&ts->msac,
@@ -1737,7 +1737,7 @@
                 b->interintra_type == INTER_INTRA_NONE && imin(bw4, bh4) >= 2 &&
                 // is not warped global motion
                 !(!f->frame_hdr->force_integer_mv && b->inter_mode == GLOBALMV &&
-                  f->frame_hdr->gmv[b->ref[0]].type > WM_TYPE_TRANSLATION) &&
+                  f->frame_hdr->gmv[b->ref[0]].type > DAV1D_WM_TYPE_TRANSLATION) &&
                 // has overlappable neighbours
                 ((have_left && findoddzero(&t->l.intra[by4 + 1], h4 >> 1)) ||
                  (have_top && findoddzero(&t->a->intra[bx4 + 1], w4 >> 1))))
@@ -1784,14 +1784,14 @@
         }
 
         // subpel filter
-        enum FilterMode filter[2];
-        if (f->frame_hdr->subpel_filter_mode == FILTER_SWITCHABLE) {
+        enum Dav1dFilterMode filter[2];
+        if (f->frame_hdr->subpel_filter_mode == DAV1D_FILTER_SWITCHABLE) {
             if (has_subpel_filter) {
                 const int comp = b->comp_type != COMP_INTER_NONE;
                 const int ctx1 = get_filter_ctx(t->a, &t->l, comp, 0, b->ref[0],
                                                 by4, bx4);
                 filter[0] = msac_decode_symbol_adapt(&ts->msac,
-                    ts->cdf.m.filter[0][ctx1], N_SWITCHABLE_FILTERS);
+                    ts->cdf.m.filter[0][ctx1], DAV1D_N_SWITCHABLE_FILTERS);
                 if (f->seq_hdr->dual_filter) {
                     const int ctx2 = get_filter_ctx(t->a, &t->l, comp, 1,
                                                     b->ref[0], by4, bx4);
@@ -1799,7 +1799,7 @@
                         printf("Post-subpel_filter1[%d,ctx=%d]: r=%d\n",
                                filter[0], ctx1, ts->msac.rng);
                     filter[1] = msac_decode_symbol_adapt(&ts->msac,
-                        ts->cdf.m.filter[1][ctx2], N_SWITCHABLE_FILTERS);
+                        ts->cdf.m.filter[1][ctx2], DAV1D_N_SWITCHABLE_FILTERS);
                     if (DEBUG_BLOCK_INFO)
                         printf("Post-subpel_filter2[%d,ctx=%d]: r=%d\n",
                                filter[1], ctx2, ts->msac.rng);
@@ -1810,7 +1810,7 @@
                                filter[0], ctx1, ts->msac.rng);
                 }
             } else {
-                filter[0] = filter[1] = FILTER_8TAP_REGULAR;
+                filter[0] = filter[1] = DAV1D_FILTER_8TAP_REGULAR;
             }
         } else {
             filter[0] = filter[1] = f->frame_hdr->subpel_filter_mode;
@@ -2194,7 +2194,7 @@
     }
     memset(ctx->lcoef, 0x40, sizeof(ctx->lcoef));
     memset(ctx->ccoef, 0x40, sizeof(ctx->ccoef));
-    memset(ctx->filter, N_SWITCHABLE_FILTERS, sizeof(ctx->filter));
+    memset(ctx->filter, DAV1D_N_SWITCHABLE_FILTERS, sizeof(ctx->filter));
     memset(ctx->seg_pred, 0, sizeof(ctx->seg_pred));
     memset(ctx->pal_sz, 0, sizeof(ctx->pal_sz));
 }
@@ -2239,7 +2239,7 @@
                    ((ts->tiling.col_start & 16) >> 4);
     }
     for (int p = 0; p < 3; p++) {
-        if (f->frame_hdr->restoration.type[p] == RESTORATION_NONE)
+        if (f->frame_hdr->restoration.type[p] == DAV1D_RESTORATION_NONE)
             continue;
 
         if (f->frame_hdr->super_res.enabled) {
@@ -2273,28 +2273,28 @@
 
 static void read_restoration_info(Dav1dTileContext *const t,
                                   Av1RestorationUnit *const lr, const int p,
-                                  const enum RestorationType frame_type)
+                                  const enum Dav1dRestorationType frame_type)
 {
     const Dav1dFrameContext *const f = t->f;
     Dav1dTileState *const ts = t->ts;
 
-    if (frame_type == RESTORATION_SWITCHABLE) {
+    if (frame_type == DAV1D_RESTORATION_SWITCHABLE) {
         const int filter =
             msac_decode_symbol_adapt(&ts->msac,
                                      ts->cdf.m.restore_switchable, 3);
-        lr->type = filter ? filter == 2 ? RESTORATION_SGRPROJ :
-                                          RESTORATION_WIENER :
-                            RESTORATION_NONE;
+        lr->type = filter ? filter == 2 ? DAV1D_RESTORATION_SGRPROJ :
+                                          DAV1D_RESTORATION_WIENER :
+                            DAV1D_RESTORATION_NONE;
     } else {
         const unsigned type =
             msac_decode_bool_adapt(&ts->msac,
-                                   frame_type == RESTORATION_WIENER ?
+                                   frame_type == DAV1D_RESTORATION_WIENER ?
                                        ts->cdf.m.restore_wiener :
                                        ts->cdf.m.restore_sgrproj);
-        lr->type = type ? frame_type : RESTORATION_NONE;
+        lr->type = type ? frame_type : DAV1D_RESTORATION_NONE;
     }
 
-    if (lr->type == RESTORATION_WIENER) {
+    if (lr->type == DAV1D_RESTORATION_WIENER) {
         lr->filter_v[0] =
             !p ? msac_decode_subexp(&ts->msac,
                                     ts->lr_ref[p]->filter_v[0] + 5, 16,
@@ -2329,7 +2329,7 @@
                    p, lr->filter_v[0], lr->filter_v[1],
                    lr->filter_v[2], lr->filter_h[0],
                    lr->filter_h[1], lr->filter_h[2], ts->msac.rng);
-    } else if (lr->type == RESTORATION_SGRPROJ) {
+    } else if (lr->type == DAV1D_RESTORATION_SGRPROJ) {
         const unsigned idx = msac_decode_bools(&ts->msac, 4);
         lr->sgr_idx = idx;
         lr->sgr_weights[0] = dav1d_sgr_params[idx][0] ?
@@ -2415,7 +2415,7 @@
         }
         // Restoration filter
         for (int p = 0; p < 3; p++) {
-            if (f->frame_hdr->restoration.type[p] == RESTORATION_NONE)
+            if (f->frame_hdr->restoration.type[p] == DAV1D_RESTORATION_NONE)
                 continue;
 
             const int ss_ver = p && f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
@@ -2432,7 +2432,7 @@
             // restoration unit
             if (y && y + half_unit > h) continue;
 
-            const enum RestorationType frame_type = f->frame_hdr->restoration.type[p];
+            const enum Dav1dRestorationType frame_type = f->frame_hdr->restoration.type[p];
 
             if (f->frame_hdr->super_res.enabled) {
                 const int w = (f->sr_cur.p.p.w + ss_hor) >> ss_hor;
@@ -3044,7 +3044,7 @@
 #undef assign_bitdepth_case
 
     if (f->frame_hdr->frame_type & 1) {
-        if (f->frame_hdr->primary_ref_frame != PRIMARY_REF_NONE) {
+        if (f->frame_hdr->primary_ref_frame != DAV1D_PRIMARY_REF_NONE) {
             const int pri_ref = f->frame_hdr->refidx[f->frame_hdr->primary_ref_frame];
             if (!c->refs[pri_ref].p.p.data[0]) {
                 res = -EINVAL;
@@ -3082,7 +3082,7 @@
             } else {
                 f->svc[i][0].scale = 0;
             }
-            f->gmv_warp_allowed[i] = f->frame_hdr->gmv[i].type > WM_TYPE_TRANSLATION &&
+            f->gmv_warp_allowed[i] = f->frame_hdr->gmv[i].type > DAV1D_WM_TYPE_TRANSLATION &&
                                      !f->frame_hdr->force_integer_mv &&
                                      !dav1d_get_shear_params(&f->frame_hdr->gmv[i]);
         }
@@ -3089,7 +3089,7 @@
     }
 
     // setup entropy
-    if (f->frame_hdr->primary_ref_frame == PRIMARY_REF_NONE) {
+    if (f->frame_hdr->primary_ref_frame == DAV1D_PRIMARY_REF_NONE) {
         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];
@@ -3207,7 +3207,7 @@
         // happens if there is either no update or a temporal update.
         if (f->frame_hdr->segmentation.temporal || !f->frame_hdr->segmentation.update_map) {
             const int pri_ref = f->frame_hdr->primary_ref_frame;
-            assert(pri_ref != PRIMARY_REF_NONE);
+            assert(pri_ref != DAV1D_PRIMARY_REF_NONE);
             const int ref_w = ((f->ref_coded_width[pri_ref] + 7) >> 3) << 1;
             const int ref_h = ((f->refp[pri_ref].p.p.h + 7) >> 3) << 1;
             if (ref_w == f->bw && ref_h == f->bh) {
--- a/src/env.h
+++ b/src/env.h
@@ -123,7 +123,7 @@
 
 static inline enum TxfmTypeSet get_ext_txtp_set(const enum RectTxfmSize tx,
                                                 const int inter,
-                                                const Av1FrameHeader *const hdr,
+                                                const Dav1dFrameHeader *const hdr,
                                                 const int seg_id)
 {
     if (!hdr->segmentation.qidx[seg_id]) {
@@ -156,7 +156,7 @@
 
 static inline enum TxfmType get_uv_intra_txtp(const enum IntraPredMode uv_mode,
                                               const enum RectTxfmSize tx,
-                                              const Av1FrameHeader *const hdr,
+                                              const Dav1dFrameHeader *const hdr,
                                               const int seg_id)
 {
     if (hdr->segmentation.lossless[seg_id]) {
@@ -171,7 +171,7 @@
 
 static inline enum TxfmType get_uv_inter_txtp(const TxfmInfo *const uvt_dim,
                                               const enum TxfmType ytxtp,
-                                              const Av1FrameHeader *const hdr,
+                                              const Dav1dFrameHeader *const hdr,
                                               const int seg_id)
 {
     if (hdr->segmentation.lossless[seg_id]) {
@@ -197,18 +197,18 @@
                                  const int yb4, const int xb4)
 {
     const int a_filter = (a->ref[0][xb4] == ref || a->ref[1][xb4] == ref) ?
-                         a->filter[dir][xb4] : N_SWITCHABLE_FILTERS;
+                         a->filter[dir][xb4] : DAV1D_N_SWITCHABLE_FILTERS;
     const int l_filter = (l->ref[0][yb4] == ref || l->ref[1][yb4] == ref) ?
-                         l->filter[dir][yb4] : N_SWITCHABLE_FILTERS;
+                         l->filter[dir][yb4] : DAV1D_N_SWITCHABLE_FILTERS;
 
     if (a_filter == l_filter) {
         return comp * 4 + a_filter;
-    } else if (a_filter == N_SWITCHABLE_FILTERS) {
+    } else if (a_filter == DAV1D_N_SWITCHABLE_FILTERS) {
         return comp * 4 + l_filter;
-    } else if (l_filter == N_SWITCHABLE_FILTERS) {
+    } else if (l_filter == DAV1D_N_SWITCHABLE_FILTERS) {
         return comp * 4 + a_filter;
     } else {
-        return comp * 4 + N_SWITCHABLE_FILTERS;
+        return comp * 4 + DAV1D_N_SWITCHABLE_FILTERS;
     }
 }
 
@@ -719,18 +719,18 @@
     return mag + 14;
 }
 
-static inline mv get_gmv_2d(const WarpedMotionParams *const gmv,
+static inline mv get_gmv_2d(const Dav1dWarpedMotionParams *const gmv,
                             const int bx4, const int by4,
                             const int bw4, const int bh4,
-                            const Av1FrameHeader *const hdr)
+                            const Dav1dFrameHeader *const hdr)
 {
     switch (gmv->type) {
-    case WM_TYPE_ROT_ZOOM:
+    case DAV1D_WM_TYPE_ROT_ZOOM:
         assert(gmv->matrix[5] ==  gmv->matrix[2]);
         assert(gmv->matrix[4] == -gmv->matrix[3]);
         // fall-through
     default:
-    case WM_TYPE_AFFINE: {
+    case DAV1D_WM_TYPE_AFFINE: {
         const int x = bx4 * 4 + bw4 * 2 - 1;
         const int y = by4 * 4 + bh4 * 2 - 1;
         const int xc = (gmv->matrix[2] - (1 << 16)) * x +
@@ -744,12 +744,12 @@
             .x = apply_sign(((abs(xc) + round) >> shift) << !hdr->hp, xc),
         };
     }
-    case WM_TYPE_TRANSLATION:
+    case DAV1D_WM_TYPE_TRANSLATION:
         return (mv) {
             .y = gmv->matrix[0] >> 13,
             .x = gmv->matrix[1] >> 13,
         };
-    case WM_TYPE_IDENTITY:
+    case DAV1D_WM_TYPE_IDENTITY:
         return (mv) { .x = 0, .y = 0 };
     }
 }
--- a/src/internal.h
+++ b/src/internal.h
@@ -78,9 +78,9 @@
     int n_tile_data;
     int n_tiles;
     Dav1dRef *seq_hdr_ref;
-    Av1SequenceHeader *seq_hdr;
+    Dav1dSequenceHeader *seq_hdr;
     Dav1dRef *frame_hdr_ref;
-    Av1FrameHeader *frame_hdr;
+    Dav1dFrameHeader *frame_hdr;
 
     // decoded output picture queue
     Dav1dData in;
@@ -94,11 +94,11 @@
     struct {
         Dav1dThreadPicture p;
         Dav1dRef *segmap;
-        Av1SegmentationDataSet seg_data;
+        Dav1dSegmentationDataSet seg_data;
         Dav1dRef *refmvs;
         unsigned refpoc[7];
-        WarpedMotionParams gmv[7];
-        Av1LoopfilterModeRefDeltas lf_mode_ref_deltas;
+        Dav1dWarpedMotionParams gmv[7];
+        Dav1dLoopfilterModeRefDeltas lf_mode_ref_deltas;
         Dav1dFilmGrainData film_grain;
         uint8_t qidx;
         unsigned coded_width;
@@ -125,9 +125,9 @@
 
 struct Dav1dFrameContext {
     Dav1dRef *seq_hdr_ref;
-    Av1SequenceHeader *seq_hdr;
+    Dav1dSequenceHeader *seq_hdr;
     Dav1dRef *frame_hdr_ref;
-    Av1FrameHeader *frame_hdr;
+    Dav1dFrameHeader *frame_hdr;
     Dav1dThreadPicture refp[7];
     Dav1dPicture cur; // during block coding / reconstruction
     Dav1dThreadPicture sr_cur; // after super-resolution upscaling
@@ -172,7 +172,7 @@
     pixel *ipred_edge[3];
     ptrdiff_t b4_stride;
     int w4, h4, bw, bh, sb128w, sb128h, sbh, sb_shift, sb_step, sr_sb128w;
-    uint16_t dq[NUM_SEGMENTS][3 /* plane */][2 /* dc/ac */];
+    uint16_t dq[DAV1D_NUM_SEGMENTS][3 /* plane */][2 /* dc/ac */];
     const uint8_t *qm[2 /* is_1d */][N_RECT_TX_SIZES][3 /* plane */];
     BlockContext *a;
     int a_sz /* w*tile_rows */;
@@ -250,7 +250,7 @@
         coef *cf;
     } frame_thread;
 
-    uint16_t dqmem[NUM_SEGMENTS][3 /* plane */][2 /* dc/ac */];
+    uint16_t dqmem[DAV1D_NUM_SEGMENTS][3 /* plane */][2 /* dc/ac */];
     const uint16_t (*dq)[3][2];
     int last_qidx;
 
@@ -274,7 +274,7 @@
     uint16_t pal[3 /* plane */][8 /* palette_idx */];
     uint8_t pal_sz_uv[2 /* a/l */][32 /* bx4/by4 */];
     uint8_t txtp_map[32 * 32]; // inter-only
-    WarpedMotionParams warpmv;
+    Dav1dWarpedMotionParams warpmv;
     union {
         void *mem;
         uint8_t *pal_idx;
--- a/src/intra_edge.c
+++ b/src/intra_edge.c
@@ -28,6 +28,7 @@
 #include "config.h"
 
 #include <assert.h>
+#include <stdlib.h>
 
 #include "src/intra_edge.h"
 #include "src/levels.h"
--- a/src/ipred.h
+++ b/src/ipred.h
@@ -28,6 +28,8 @@
 #ifndef __DAV1D_SRC_IPRED_H__
 #define __DAV1D_SRC_IPRED_H__
 
+#include <stddef.h>
+
 #include "common/bitdepth.h"
 
 #include "src/levels.h"
--- a/src/itx.h
+++ b/src/itx.h
@@ -28,6 +28,8 @@
 #ifndef __DAV1D_SRC_ITX_H__
 #define __DAV1D_SRC_ITX_H__
 
+#include <stddef.h>
+
 #include "common/bitdepth.h"
 
 #include "src/levels.h"
--- a/src/levels.h
+++ b/src/levels.h
@@ -28,8 +28,10 @@
 #ifndef __DAV1D_SRC_LEVELS_H__
 #define __DAV1D_SRC_LEVELS_H__
 
-#include "dav1d/picture.h"
+#include <stdint.h>
 
+#include "dav1d/headers.h"
+
 enum ObuType {
     OBU_SEQ_HDR   = 1,
     OBU_TD        = 2,
@@ -41,10 +43,6 @@
     OBU_PADDING   = 15,
 };
 
-// Constants from Section 3. "Symbols and abbreviated terms"
-#define MAX_TILE_COLS 64
-#define MAX_TILE_ROWS 64
-
 enum TxfmSize {
     TX_4X4,
     TX_8X8,
@@ -63,13 +61,6 @@
     N_BL_LEVELS,
 };
 
-enum TxfmMode {
-    TX_4X4_ONLY,
-    TX_LARGEST,
-    TX_SWITCHABLE,
-    N_TX_MODES,
-};
-
 enum RectTxfmSize {
     RTX_4X8 = N_TX_SIZES,
     RTX_8X4,
@@ -203,16 +194,6 @@
     N_BS_SIZES,
 };
 
-enum FilterMode {
-    FILTER_8TAP_REGULAR,
-    FILTER_8TAP_SMOOTH,
-    FILTER_8TAP_SHARP,
-    N_SWITCHABLE_FILTERS,
-    FILTER_BILINEAR = N_SWITCHABLE_FILTERS,
-    N_FILTERS,
-    FILTER_SWITCHABLE = N_FILTERS,
-};
-
 enum Filter2d { // order is horizontal, vertical
     FILTER_2D_8TAP_REGULAR,
     FILTER_2D_8TAP_REGULAR_SMOOTH,
@@ -269,226 +250,15 @@
     INTER_INTRA_WEDGE,
 };
 
-enum AdaptiveBoolean {
-    OFF = 0,
-    ON = 1,
-    ADAPTIVE = 2,
-};
-
-enum RestorationType {
-    RESTORATION_NONE,
-    RESTORATION_SWITCHABLE,
-    RESTORATION_WIENER,
-    RESTORATION_SGRPROJ,
-};
-
 typedef struct mv {
     int16_t y, x;
 } mv;
 
-enum WarpedMotionType {
-    WM_TYPE_IDENTITY,
-    WM_TYPE_TRANSLATION,
-    WM_TYPE_ROT_ZOOM,
-    WM_TYPE_AFFINE,
-};
-
-typedef struct WarpedMotionParams {
-    enum WarpedMotionType type;
-    int32_t matrix[6];
-    union {
-        struct {
-            int16_t alpha, beta, gamma, delta;
-        };
-        int16_t abcd[4];
-    };
-} WarpedMotionParams;
-
 enum MotionMode {
     MM_TRANSLATION,
     MM_OBMC,
     MM_WARP,
 };
-
-typedef struct Av1SequenceHeader {
-    int profile;
-    int still_picture;
-    int reduced_still_picture_header;
-    int timing_info_present;
-    int num_units_in_tick;
-    int time_scale;
-    int equal_picture_interval;
-    int num_ticks_per_picture;
-    int decoder_model_info_present;
-    int encoder_decoder_buffer_delay_length;
-    int num_units_in_decoding_tick;
-    int buffer_removal_delay_length;
-    int frame_presentation_delay_length;
-    int display_model_info_present;
-    int num_operating_points;
-    struct Av1SequenceHeaderOperatingPoint {
-        int idc;
-        int major_level, minor_level;
-        int tier;
-        int decoder_model_param_present;
-        int decoder_buffer_delay;
-        int encoder_buffer_delay;
-        int low_delay_mode;
-        int display_model_param_present;
-        int initial_display_delay;
-    } operating_points[32];
-    int max_width, max_height, width_n_bits, height_n_bits;
-    int frame_id_numbers_present;
-    int delta_frame_id_n_bits;
-    int frame_id_n_bits;
-    int sb128;
-    int filter_intra;
-    int intra_edge_filter;
-    int inter_intra;
-    int masked_compound;
-    int warped_motion;
-    int dual_filter;
-    int order_hint;
-    int jnt_comp;
-    int ref_frame_mvs;
-    enum AdaptiveBoolean screen_content_tools;
-    enum AdaptiveBoolean force_integer_mv;
-    int order_hint_n_bits;
-    int super_res;
-    int cdef;
-    int restoration;
-    int bpc;
-    int hbd;
-    int color_description_present;
-    enum Dav1dPixelLayout layout;
-    enum Dav1dColorPrimaries pri;
-    enum Dav1dTransferCharacteristics trc;
-    enum Dav1dMatrixCoefficients mtrx;
-    enum Dav1dChromaSamplePosition chr;
-    int color_range;
-    int separate_uv_delta_q;
-    int film_grain_present;
-} Av1SequenceHeader;
-
-#define NUM_SEGMENTS 8
-
-typedef struct Av1SegmentationData {
-    int delta_q;
-    int delta_lf_y_v, delta_lf_y_h, delta_lf_u, delta_lf_v;
-    int ref;
-    int skip;
-    int globalmv;
-} Av1SegmentationData;
-
-typedef struct Av1SegmentationDataSet {
-    Av1SegmentationData d[NUM_SEGMENTS];
-    int preskip;
-    int last_active_segid;
-} Av1SegmentationDataSet;
-
-typedef struct Av1LoopfilterModeRefDeltas {
-    int mode_delta[2];
-    int ref_delta[8];
-} Av1LoopfilterModeRefDeltas;
-
-typedef struct Av1FrameHeader {
-    int show_existing_frame;
-    int existing_frame_idx;
-    int frame_id;
-    int frame_presentation_delay;
-    enum Dav1dFrameType frame_type;
-    int show_frame;
-    int showable_frame;
-    int error_resilient_mode;
-    int disable_cdf_update;
-    int allow_screen_content_tools;
-    int force_integer_mv;
-    int frame_size_override;
-#define PRIMARY_REF_NONE 7
-    int primary_ref_frame;
-    int buffer_removal_time_present;
-    struct Av1FrameHeaderOperatingPoint {
-        int buffer_removal_time;
-    } operating_points[32];
-    int frame_offset;
-    int refresh_frame_flags;
-    int width[2 /* { coded_width, superresolution_upscaled_width } */], height;
-    int render_width, render_height;
-    struct {
-        int width_scale_denominator;
-        int enabled;
-    } super_res;
-    int have_render_size;
-    int allow_intrabc;
-    int frame_ref_short_signaling;
-    int refidx[7];
-    int hp;
-    enum FilterMode subpel_filter_mode;
-    int switchable_motion_mode;
-    int use_ref_frame_mvs;
-    int refresh_context;
-    struct {
-        int uniform;
-        unsigned n_bytes;
-        int min_log2_cols, max_log2_cols, log2_cols, cols;
-        int min_log2_rows, max_log2_rows, log2_rows, rows;
-        uint16_t col_start_sb[MAX_TILE_COLS + 1];
-        uint16_t row_start_sb[MAX_TILE_ROWS + 1];
-        int update;
-    } tiling;
-    struct {
-        int yac;
-        int ydc_delta;
-        int udc_delta, uac_delta, vdc_delta, vac_delta;
-        int qm, qm_y, qm_u, qm_v;
-    } quant;
-    struct {
-        int enabled, update_map, temporal, update_data;
-        Av1SegmentationDataSet seg_data;
-        int lossless[NUM_SEGMENTS], qidx[NUM_SEGMENTS];
-    } segmentation;
-    struct {
-        struct {
-            int present;
-            int res_log2;
-        } q;
-        struct {
-            int present;
-            int res_log2;
-            int multi;
-        } lf;
-    } delta;
-    int all_lossless;
-    struct {
-        int level_y[2];
-        int level_u, level_v;
-        int mode_ref_delta_enabled;
-        int mode_ref_delta_update;
-        Av1LoopfilterModeRefDeltas mode_ref_deltas;
-        int sharpness;
-    } loopfilter;
-    struct {
-        int damping;
-        int n_bits;
-        int y_strength[8];
-        int uv_strength[8];
-    } cdef;
-    struct {
-        enum RestorationType type[3];
-        int unit_size[2];
-    } restoration;
-    enum TxfmMode txfm_mode;
-    int switchable_comp_refs;
-    int skip_mode_allowed, skip_mode_enabled, skip_mode_refs[2];
-    int warp_motion;
-    int reduced_txtp_set;
-    WarpedMotionParams gmv[7];
-    struct {
-        int present, update;
-        Dav1dFilmGrainData data;
-    } film_grain;
-    int temporal_id, spatial_id;
-} Av1FrameHeader;
 
 #define QINDEX_RANGE 256
 
--- a/src/lf_mask.c
+++ b/src/lf_mask.c
@@ -287,7 +287,7 @@
 void dav1d_create_lf_mask_intra(Av1Filter *const lflvl,
                                 uint8_t (*const level_cache)[4],
                                 const ptrdiff_t b4_stride,
-                                const Av1FrameHeader *const hdr,
+                                const Dav1dFrameHeader *const hdr,
                                 const uint8_t (*filter_level)[8][2],
                                 const int bx, const int by,
                                 const int iw, const int ih,
@@ -351,7 +351,7 @@
 void dav1d_create_lf_mask_inter(Av1Filter *const lflvl,
                                 uint8_t (*const level_cache)[4],
                                 const ptrdiff_t b4_stride,
-                                const Av1FrameHeader *const hdr,
+                                const Dav1dFrameHeader *const hdr,
                                 const uint8_t (*filter_level)[8][2],
                                 const int bx, const int by,
                                 const int iw, const int ih,
@@ -435,7 +435,7 @@
 static inline void calc_lf_value(uint8_t (*const lflvl_values)[2],
                                  const int is_chroma, const int base_lvl,
                                  const int lf_delta, const int seg_delta,
-                                 const Av1LoopfilterModeRefDeltas *const mr_delta)
+                                 const Dav1dLoopfilterModeRefDeltas *const mr_delta)
 {
     const int base = iclip(iclip(base_lvl + lf_delta, 0, 63) + seg_delta, 0, 63);
 
@@ -458,7 +458,7 @@
 }
 
 void dav1d_calc_lf_values(uint8_t (*const lflvl_values)[4][8][2],
-                          const Av1FrameHeader *const hdr,
+                          const Dav1dFrameHeader *const hdr,
                           const int8_t lf_delta[4])
 {
     const int n_seg = hdr->segmentation.enabled ? 8 : 1;
@@ -468,11 +468,11 @@
         return;
     }
 
-    const Av1LoopfilterModeRefDeltas *const mr_deltas =
+    const Dav1dLoopfilterModeRefDeltas *const mr_deltas =
         hdr->loopfilter.mode_ref_delta_enabled ?
         &hdr->loopfilter.mode_ref_deltas : NULL;
     for (int s = 0; s < n_seg; s++) {
-        const Av1SegmentationData *const segd =
+        const Dav1dSegmentationData *const segd =
             hdr->segmentation.enabled ? &hdr->segmentation.seg_data.d[s] : NULL;
 
         calc_lf_value(lflvl_values[s][0], 0, hdr->loopfilter.level_y[0],
--- a/src/lf_mask.h
+++ b/src/lf_mask.h
@@ -40,7 +40,7 @@
 } Av1FilterLUT;
 
 typedef struct Av1RestorationUnit {
-    enum RestorationType type;
+    enum Dav1dRestorationType type;
     int16_t filter_h[3];
     int16_t filter_v[3];
     uint8_t sgr_idx;
@@ -63,7 +63,7 @@
 
 void dav1d_create_lf_mask_intra(Av1Filter *lflvl, uint8_t (*level_cache)[4],
                                 const ptrdiff_t b4_stride,
-                                const Av1FrameHeader *hdr,
+                                const Dav1dFrameHeader *hdr,
                                 const uint8_t (*level)[8][2], int bx, int by,
                                 int iw, int ih, enum BlockSize bs,
                                 enum RectTxfmSize ytx, enum RectTxfmSize uvtx,
@@ -71,7 +71,7 @@
                                 uint8_t *ly, uint8_t *auv, uint8_t *luv);
 void dav1d_create_lf_mask_inter(Av1Filter *lflvl, uint8_t (*level_cache)[4],
                                 const ptrdiff_t b4_stride,
-                                const Av1FrameHeader *hdr,
+                                const Dav1dFrameHeader *hdr,
                                 const uint8_t (*level)[8][2], int bx, int by,
                                 int iw, int ih, int skip_inter,
                                 enum BlockSize bs, const uint16_t *tx_mask,
@@ -79,7 +79,7 @@
                                 enum Dav1dPixelLayout layout, uint8_t *ay,
                                 uint8_t *ly, uint8_t *auv, uint8_t *luv);
 void dav1d_calc_eih(Av1FilterLUT *lim_lut, int filter_sharpness);
-void dav1d_calc_lf_values(uint8_t (*values)[4][8][2], const Av1FrameHeader *hdr,
+void dav1d_calc_lf_values(uint8_t (*values)[4][8][2], const Dav1dFrameHeader *hdr,
                           const int8_t lf_delta[4]);
 
 #endif /* __DAV1D_SRC_LF_MASK_H__ */
--- a/src/lr_apply_tmpl.c
+++ b/src/lr_apply_tmpl.c
@@ -103,9 +103,9 @@
 
     // TODO Also check block level restore type to reduce copying.
     const int restore_planes =
-        ((f->frame_hdr->restoration.type[0] != RESTORATION_NONE) << 0) +
-        ((f->frame_hdr->restoration.type[1] != RESTORATION_NONE) << 1) +
-        ((f->frame_hdr->restoration.type[2] != RESTORATION_NONE) << 2);
+        ((f->frame_hdr->restoration.type[0] != DAV1D_RESTORATION_NONE) << 0) +
+        ((f->frame_hdr->restoration.type[1] != DAV1D_RESTORATION_NONE) << 1) +
+        ((f->frame_hdr->restoration.type[2] != DAV1D_RESTORATION_NONE) << 2);
 
     if (restore_planes & LR_RESTORE_Y) {
         const int h = f->bh << 2;
@@ -157,7 +157,7 @@
 
     // FIXME [8] might be easier for SIMD
     int16_t filterh[7], filterv[7];
-    if (lr->type == RESTORATION_WIENER) {
+    if (lr->type == DAV1D_RESTORATION_WIENER) {
         filterh[0] = filterh[6] = lr->filter_h[0];
         filterh[1] = filterh[5] = lr->filter_h[1];
         filterh[2] = filterh[4] = lr->filter_h[2];
@@ -176,11 +176,11 @@
         } else {
             edges |= LR_HAVE_BOTTOM;
         }
-        if (lr->type == RESTORATION_WIENER) {
+        if (lr->type == DAV1D_RESTORATION_WIENER) {
             dsp->lr.wiener(p, p_stride, left, lpf, lpf_stride, unit_w, stripe_h,
                            filterh, filterv, edges);
         } else {
-            assert(lr->type == RESTORATION_SGRPROJ);
+            assert(lr->type == DAV1D_RESTORATION_SGRPROJ);
             dsp->lr.selfguided(p, p_stride, left, lpf, lpf_stride, unit_w, stripe_h,
                                lr->sgr_idx, lr->sgr_weights, edges);
         }
@@ -257,7 +257,7 @@
         if (edges & LR_HAVE_RIGHT) {
             backup4xU(pre_lr_border[bit], p + unit_w - 4, p_stride, row_h - y);
         }
-        if (lr->type != RESTORATION_NONE) {
+        if (lr->type != DAV1D_RESTORATION_NONE) {
             lr_stripe(f, p, pre_lr_border[!bit], x, y, plane, unit_w, row_h, lr, edges);
         }
         p += unit_w;
@@ -271,9 +271,9 @@
     const ptrdiff_t *const dst_stride = f->sr_cur.p.stride;
 
     const int restore_planes =
-        ((f->frame_hdr->restoration.type[0] != RESTORATION_NONE) << 0) +
-        ((f->frame_hdr->restoration.type[1] != RESTORATION_NONE) << 1) +
-        ((f->frame_hdr->restoration.type[2] != RESTORATION_NONE) << 2);
+        ((f->frame_hdr->restoration.type[0] != DAV1D_RESTORATION_NONE) << 0) +
+        ((f->frame_hdr->restoration.type[1] != DAV1D_RESTORATION_NONE) << 1) +
+        ((f->frame_hdr->restoration.type[2] != DAV1D_RESTORATION_NONE) << 2);
 
     if (restore_planes & LR_RESTORE_Y) {
         const int h = f->sr_cur.p.p.h;
--- a/src/mc_tmpl.c
+++ b/src/mc_tmpl.c
@@ -72,11 +72,11 @@
      F[6] * src[x + +3 * stride] + \
      F[7] * src[x + +4 * stride])
 
-#define FILTER_8TAP_RND(src, x, F, stride, sh) \
+#define DAV1D_FILTER_8TAP_RND(src, x, F, stride, sh) \
     ((FILTER_8TAP(src, x, F, stride) + ((1 << sh) >> 1)) >> sh)
 
-#define FILTER_8TAP_CLIP(src, x, F, stride, sh) \
-    iclip_pixel(FILTER_8TAP_RND(src, x, F, stride, sh))
+#define DAV1D_FILTER_8TAP_CLIP(src, x, F, stride, sh) \
+    iclip_pixel(DAV1D_FILTER_8TAP_RND(src, x, F, stride, sh))
 
 #define GET_H_FILTER(mx) \
     const int8_t *const fh = !(mx) ? NULL : w > 4 ? \
@@ -110,7 +110,7 @@
             src -= src_stride * 3;
             do {
                 for (int x = 0; x < w; x++)
-                    mid_ptr[x] = FILTER_8TAP_RND(src, x, fh, 1, 2);
+                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1, 2);
 
                 mid_ptr += 128;
                 src += src_stride;
@@ -119,7 +119,7 @@
             mid_ptr = mid + 128 * 3;
             do {
                 for (int x = 0; x < w; x++)
-                    dst[x] = FILTER_8TAP_CLIP(mid_ptr, x, fv, 128, 10);
+                    dst[x] = DAV1D_FILTER_8TAP_CLIP(mid_ptr, x, fv, 128, 10);
 
                 mid_ptr += 128;
                 dst += dst_stride;
@@ -127,7 +127,7 @@
         } else {
             do {
                 for (int x = 0; x < w; x++) {
-                    const int px = FILTER_8TAP_RND(src, x, fh, 1, 2);
+                    const int px = DAV1D_FILTER_8TAP_RND(src, x, fh, 1, 2);
                     dst[x] = iclip_pixel((px + 8) >> 4);
                 }
 
@@ -138,7 +138,7 @@
     } else if (fv) {
         do {
             for (int x = 0; x < w; x++)
-                dst[x] = FILTER_8TAP_CLIP(src, x, fv, src_stride, 6);
+                dst[x] = DAV1D_FILTER_8TAP_CLIP(src, x, fv, src_stride, 6);
 
             dst += dst_stride;
             src += src_stride;
@@ -164,7 +164,7 @@
 
         for (x = 0; x < w; x++) {
             GET_H_FILTER(imx >> 6);
-            mid_ptr[x] = fh ? FILTER_8TAP_RND(src, ioff, fh, 1, 2) : src[ioff] << 4;
+            mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1, 2) : src[ioff] << 4;
             imx += dx;
             ioff += imx >> 10;
             imx &= 0x3ff;
@@ -180,7 +180,7 @@
         GET_V_FILTER(my >> 6);
 
         for (x = 0; x < w; x++)
-            dst[x] = fv ? FILTER_8TAP_CLIP(mid_ptr, x, fv, 128, 10) :
+            dst[x] = fv ? DAV1D_FILTER_8TAP_CLIP(mid_ptr, x, fv, 128, 10) :
                           iclip_pixel((mid_ptr[x] + 8) >> 4);
 
         my += dy;
@@ -206,7 +206,7 @@
             src -= src_stride * 3;
             do {
                 for (int x = 0; x < w; x++)
-                    mid_ptr[x] = FILTER_8TAP_RND(src, x, fh, 1, 2);
+                    mid_ptr[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1, 2);
 
                 mid_ptr += 128;
                 src += src_stride;
@@ -215,7 +215,7 @@
             mid_ptr = mid + 128 * 3;
             do {
                 for (int x = 0; x < w; x++)
-                    tmp[x] = FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6);
+                    tmp[x] = DAV1D_FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6);
 
                 mid_ptr += 128;
                 tmp += w;
@@ -223,7 +223,7 @@
         } else {
             do {
                 for (int x = 0; x < w; x++)
-                    tmp[x] = FILTER_8TAP_RND(src, x, fh, 1, 2);
+                    tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fh, 1, 2);
 
                 tmp += w;
                 src += src_stride;
@@ -232,7 +232,7 @@
     } else if (fv) {
         do {
             for (int x = 0; x < w; x++)
-                tmp[x] = FILTER_8TAP_RND(src, x, fv, src_stride, 2);
+                tmp[x] = DAV1D_FILTER_8TAP_RND(src, x, fv, src_stride, 2);
 
             tmp += w;
             src += src_stride;
@@ -257,7 +257,7 @@
 
         for (x = 0; x < w; x++) {
             GET_H_FILTER(imx >> 6);
-            mid_ptr[x] = fh ? FILTER_8TAP_RND(src, ioff, fh, 1, 2) : src[ioff] << 4;
+            mid_ptr[x] = fh ? DAV1D_FILTER_8TAP_RND(src, ioff, fh, 1, 2) : src[ioff] << 4;
             imx += dx;
             ioff += imx >> 10;
             imx &= 0x3ff;
@@ -273,7 +273,7 @@
         GET_V_FILTER(my >> 6);
 
         for (x = 0; x < w; x++)
-            tmp[x] = fv ? FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6) : mid_ptr[x];
+            tmp[x] = fv ? DAV1D_FILTER_8TAP_RND(mid_ptr, x, fv, 128, 6) : mid_ptr[x];
 
         my += dy;
         mid_ptr += (my >> 10) * 128;
@@ -324,15 +324,15 @@
                        type_h | (type_v << 2)); \
 }
 
-filter_fns(regular,        FILTER_8TAP_REGULAR, FILTER_8TAP_REGULAR)
-filter_fns(regular_sharp,  FILTER_8TAP_REGULAR, FILTER_8TAP_SHARP)
-filter_fns(regular_smooth, FILTER_8TAP_REGULAR, FILTER_8TAP_SMOOTH)
-filter_fns(smooth,         FILTER_8TAP_SMOOTH,  FILTER_8TAP_SMOOTH)
-filter_fns(smooth_regular, FILTER_8TAP_SMOOTH,  FILTER_8TAP_REGULAR)
-filter_fns(smooth_sharp,   FILTER_8TAP_SMOOTH,  FILTER_8TAP_SHARP)
-filter_fns(sharp,          FILTER_8TAP_SHARP,   FILTER_8TAP_SHARP)
-filter_fns(sharp_regular,  FILTER_8TAP_SHARP,   FILTER_8TAP_REGULAR)
-filter_fns(sharp_smooth,   FILTER_8TAP_SHARP,   FILTER_8TAP_SMOOTH)
+filter_fns(regular,        DAV1D_FILTER_8TAP_REGULAR, DAV1D_FILTER_8TAP_REGULAR)
+filter_fns(regular_sharp,  DAV1D_FILTER_8TAP_REGULAR, DAV1D_FILTER_8TAP_SHARP)
+filter_fns(regular_smooth, DAV1D_FILTER_8TAP_REGULAR, DAV1D_FILTER_8TAP_SMOOTH)
+filter_fns(smooth,         DAV1D_FILTER_8TAP_SMOOTH,  DAV1D_FILTER_8TAP_SMOOTH)
+filter_fns(smooth_regular, DAV1D_FILTER_8TAP_SMOOTH,  DAV1D_FILTER_8TAP_REGULAR)
+filter_fns(smooth_sharp,   DAV1D_FILTER_8TAP_SMOOTH,  DAV1D_FILTER_8TAP_SHARP)
+filter_fns(sharp,          DAV1D_FILTER_8TAP_SHARP,   DAV1D_FILTER_8TAP_SHARP)
+filter_fns(sharp_regular,  DAV1D_FILTER_8TAP_SHARP,   DAV1D_FILTER_8TAP_REGULAR)
+filter_fns(sharp_smooth,   DAV1D_FILTER_8TAP_SHARP,   DAV1D_FILTER_8TAP_SMOOTH)
 
 #define FILTER_BILIN(src, x, mxy, stride) \
     (16 * src[x] + ((mxy) * (src[x + stride] - src[x])))
--- a/src/obu.c
+++ b/src/obu.c
@@ -44,7 +44,7 @@
 #include "src/thread_task.h"
 
 static int parse_seq_hdr(Dav1dContext *const c, GetBits *const gb,
-                         Av1SequenceHeader *const hdr)
+                         Dav1dSequenceHeader *const hdr)
 {
 #define DEBUG_SEQ_HDR 0
 
@@ -105,7 +105,7 @@
         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 < hdr->num_operating_points; i++) {
-            struct Av1SequenceHeaderOperatingPoint *const op =
+            struct Dav1dSequenceHeaderOperatingPoint *const op =
                 &hdr->operating_points[i];
             op->idc = dav1d_get_bits(gb, 12);
             op->major_level = 2 + dav1d_get_bits(gb, 3);
@@ -167,8 +167,8 @@
         hdr->jnt_comp = 0;
         hdr->ref_frame_mvs = 0;
         hdr->order_hint_n_bits = 0;
-        hdr->screen_content_tools = ADAPTIVE;
-        hdr->force_integer_mv = ADAPTIVE;
+        hdr->screen_content_tools = DAV1D_ADAPTIVE;
+        hdr->force_integer_mv = DAV1D_ADAPTIVE;
     } else {
         hdr->inter_intra = dav1d_get_bits(gb, 1);
         hdr->masked_compound = dav1d_get_bits(gb, 1);
@@ -183,13 +183,13 @@
             hdr->ref_frame_mvs = 0;
             hdr->order_hint_n_bits = 0;
         }
-        hdr->screen_content_tools = dav1d_get_bits(gb, 1) ? ADAPTIVE : dav1d_get_bits(gb, 1);
+        hdr->screen_content_tools = dav1d_get_bits(gb, 1) ? DAV1D_ADAPTIVE : dav1d_get_bits(gb, 1);
     #if DEBUG_SEQ_HDR
         printf("SEQHDR: post-screentools: off=%ld\n",
                dav1d_get_bits_pos(gb) - init_bit_pos);
     #endif
         hdr->force_integer_mv = hdr->screen_content_tools ?
-                                dav1d_get_bits(gb, 1) ? ADAPTIVE : dav1d_get_bits(gb, 1) : 2;
+                                dav1d_get_bits(gb, 1) ? DAV1D_ADAPTIVE : dav1d_get_bits(gb, 1) : 2;
         if (hdr->order_hint)
             hdr->order_hint_n_bits = dav1d_get_bits(gb, 3) + 1;
     }
@@ -274,8 +274,8 @@
 static int read_frame_size(Dav1dContext *const c, GetBits *const gb,
                            const int use_ref)
 {
-    const Av1SequenceHeader *const seqhdr = c->seq_hdr;
-    Av1FrameHeader *const hdr = c->frame_hdr;
+    const Dav1dSequenceHeader *const seqhdr = c->seq_hdr;
+    Dav1dFrameHeader *const hdr = c->frame_hdr;
 
     if (use_ref) {
         for (int i = 0; i < 7; i++) {
@@ -333,7 +333,7 @@
     return k;
 }
 
-static const Av1LoopfilterModeRefDeltas default_mode_ref_deltas = {
+static const Dav1dLoopfilterModeRefDeltas default_mode_ref_deltas = {
     .mode_delta = { 0, 0 },
     .ref_delta = { 1, 0, 0, 0, -1, 0, -1, -1 },
 };
@@ -344,8 +344,8 @@
 #if DEBUG_FRAME_HDR
     const uint8_t *const init_ptr = gb->ptr;
 #endif
-    const Av1SequenceHeader *const seqhdr = c->seq_hdr;
-    Av1FrameHeader *const hdr = c->frame_hdr;
+    const Dav1dSequenceHeader *const seqhdr = c->seq_hdr;
+    Dav1dFrameHeader *const hdr = c->frame_hdr;
     int res;
 
     hdr->show_existing_frame =
@@ -379,10 +379,10 @@
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
 #endif
     hdr->disable_cdf_update = dav1d_get_bits(gb, 1);
-    hdr->allow_screen_content_tools = seqhdr->screen_content_tools == ADAPTIVE ?
+    hdr->allow_screen_content_tools = seqhdr->screen_content_tools == DAV1D_ADAPTIVE ?
                                  dav1d_get_bits(gb, 1) : seqhdr->screen_content_tools;
     if (hdr->allow_screen_content_tools)
-        hdr->force_integer_mv = seqhdr->force_integer_mv == ADAPTIVE ?
+        hdr->force_integer_mv = seqhdr->force_integer_mv == DAV1D_ADAPTIVE ?
                                 dav1d_get_bits(gb, 1) : seqhdr->force_integer_mv;
     else
         hdr->force_integer_mv = 0;
@@ -402,14 +402,14 @@
     hdr->frame_offset = seqhdr->order_hint ?
                         dav1d_get_bits(gb, seqhdr->order_hint_n_bits) : 0;
     hdr->primary_ref_frame = !hdr->error_resilient_mode && hdr->frame_type & 1 ?
-                             dav1d_get_bits(gb, 3) : PRIMARY_REF_NONE;
+                             dav1d_get_bits(gb, 3) : DAV1D_PRIMARY_REF_NONE;
 
     if (seqhdr->decoder_model_info_present) {
         hdr->buffer_removal_time_present = dav1d_get_bits(gb, 1);
         if (hdr->buffer_removal_time_present) {
             for (int i = 0; i < c->seq_hdr->num_operating_points; i++) {
-                const struct Av1SequenceHeaderOperatingPoint *const seqop = &seqhdr->operating_points[i];
-                struct Av1FrameHeaderOperatingPoint *const op = &hdr->operating_points[i];
+                const struct Dav1dSequenceHeaderOperatingPoint *const seqop = &seqhdr->operating_points[i];
+                struct Dav1dFrameHeaderOperatingPoint *const op = &hdr->operating_points[i];
                 if (seqop->decoder_model_param_present) {
                     int in_temporal_layer = (seqop->idc >> hdr->temporal_id) & 1;
                     int in_spatial_layer  = (seqop->idc >> (hdr->spatial_id + 8)) & 1;
@@ -537,7 +537,7 @@
                             hdr->frame_size_override;
         if ((res = read_frame_size(c, gb, use_ref)) < 0) goto error;
         hdr->hp = !hdr->force_integer_mv && dav1d_get_bits(gb, 1);
-        hdr->subpel_filter_mode = dav1d_get_bits(gb, 1) ? FILTER_SWITCHABLE :
+        hdr->subpel_filter_mode = dav1d_get_bits(gb, 1) ? DAV1D_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 &&
@@ -565,8 +565,8 @@
     int max_tile_width_sb = 4096 >> sbsz_log2;
     int max_tile_area_sb = 4096 * 2304 >> (2 * sbsz_log2);
     hdr->tiling.min_log2_cols = tile_log2(max_tile_width_sb, sbw);
-    hdr->tiling.max_log2_cols = tile_log2(1, imin(sbw, MAX_TILE_COLS));
-    hdr->tiling.max_log2_rows = tile_log2(1, imin(sbh, MAX_TILE_ROWS));
+    hdr->tiling.max_log2_cols = tile_log2(1, imin(sbw, DAV1D_MAX_TILE_COLS));
+    hdr->tiling.max_log2_rows = tile_log2(1, imin(sbh, DAV1D_MAX_TILE_ROWS));
     int min_log2_tiles = imax(tile_log2(max_tile_area_sb, sbw * sbh),
                               hdr->tiling.min_log2_cols);
     if (hdr->tiling.uniform) {
@@ -590,7 +590,7 @@
     } else {
         hdr->tiling.cols = 0;
         int widest_tile = 0, max_tile_area_sb = sbw * sbh;
-        for (int sbx = 0; sbx < sbw && hdr->tiling.cols < MAX_TILE_COLS; hdr->tiling.cols++) {
+        for (int sbx = 0; sbx < sbw && hdr->tiling.cols < DAV1D_MAX_TILE_COLS; hdr->tiling.cols++) {
             const int tile_width_sb = imin(sbw - sbx, max_tile_width_sb);
             const int tile_w = (tile_width_sb > 1) ?
                                    1 + dav1d_get_uniform(gb, tile_width_sb) :
@@ -604,7 +604,7 @@
         int max_tile_height_sb = imax(max_tile_area_sb / widest_tile, 1);
 
         hdr->tiling.rows = 0;
-        for (int sby = 0; sby < sbh && hdr->tiling.rows < MAX_TILE_ROWS; hdr->tiling.rows++) {
+        for (int sby = 0; sby < sbh && hdr->tiling.rows < DAV1D_MAX_TILE_ROWS; hdr->tiling.rows++) {
             const int tile_height_sb = imin(sbh - sby, max_tile_height_sb);
             const int tile_h = (tile_height_sb > 1) ?
                                    1 + dav1d_get_uniform(gb, tile_height_sb) :
@@ -668,7 +668,7 @@
     // segmentation data
     hdr->segmentation.enabled = dav1d_get_bits(gb, 1);
     if (hdr->segmentation.enabled) {
-        if (hdr->primary_ref_frame == PRIMARY_REF_NONE) {
+        if (hdr->primary_ref_frame == DAV1D_PRIMARY_REF_NONE) {
             hdr->segmentation.update_map = 1;
             hdr->segmentation.temporal = 0;
             hdr->segmentation.update_data = 1;
@@ -682,8 +682,8 @@
         if (hdr->segmentation.update_data) {
             hdr->segmentation.seg_data.preskip = 0;
             hdr->segmentation.seg_data.last_active_segid = -1;
-            for (int i = 0; i < NUM_SEGMENTS; i++) {
-                Av1SegmentationData *const seg =
+            for (int i = 0; i < DAV1D_NUM_SEGMENTS; i++) {
+                Dav1dSegmentationData *const seg =
                     &hdr->segmentation.seg_data.d[i];
                 if (dav1d_get_bits(gb, 1)) {
                     seg->delta_q = dav1d_get_sbits(gb, 8);
@@ -734,13 +734,13 @@
         } else {
             // segmentation.update_data was false so we should copy
             // segmentation data from the reference frame.
-            assert(hdr->primary_ref_frame != PRIMARY_REF_NONE);
+            assert(hdr->primary_ref_frame != DAV1D_PRIMARY_REF_NONE);
             const int pri_ref = hdr->refidx[hdr->primary_ref_frame];
             hdr->segmentation.seg_data = c->refs[pri_ref].seg_data;
         }
     } else {
-        memset(&hdr->segmentation.seg_data, 0, sizeof(Av1SegmentationDataSet));
-        for (int i = 0; i < NUM_SEGMENTS; i++)
+        memset(&hdr->segmentation.seg_data, 0, sizeof(Dav1dSegmentationDataSet));
+        for (int i = 0; i < DAV1D_NUM_SEGMENTS; i++)
             hdr->segmentation.seg_data.d[i].ref = -1;
     }
 #if DEBUG_FRAME_HDR
@@ -764,7 +764,7 @@
     const int delta_lossless = !hdr->quant.ydc_delta && !hdr->quant.udc_delta &&
         !hdr->quant.uac_delta && !hdr->quant.vdc_delta && !hdr->quant.vac_delta;
     hdr->all_lossless = 1;
-    for (int i = 0; i < NUM_SEGMENTS; i++) {
+    for (int i = 0; i < DAV1D_NUM_SEGMENTS; i++) {
         hdr->segmentation.qidx[i] = hdr->segmentation.enabled ?
             iclip_u8(hdr->quant.yac + hdr->segmentation.seg_data.d[i].delta_q) :
             hdr->quant.yac;
@@ -792,7 +792,7 @@
         }
         hdr->loopfilter.sharpness = dav1d_get_bits(gb, 3);
 
-        if (hdr->primary_ref_frame == PRIMARY_REF_NONE) {
+        if (hdr->primary_ref_frame == DAV1D_PRIMARY_REF_NONE) {
             hdr->loopfilter.mode_ref_deltas = default_mode_ref_deltas;
         } else {
             const int ref = hdr->refidx[hdr->primary_ref_frame];
@@ -847,7 +847,7 @@
             hdr->restoration.type[2] = dav1d_get_bits(gb, 2);
         } else {
             hdr->restoration.type[1] =
-            hdr->restoration.type[2] = RESTORATION_NONE;
+            hdr->restoration.type[2] = DAV1D_RESTORATION_NONE;
         }
 
         if (hdr->restoration.type[0] || hdr->restoration.type[1] ||
@@ -870,9 +870,9 @@
             hdr->restoration.unit_size[0] = 8;
         }
     } else {
-        hdr->restoration.type[0] = RESTORATION_NONE;
-        hdr->restoration.type[1] = RESTORATION_NONE;
-        hdr->restoration.type[2] = RESTORATION_NONE;
+        hdr->restoration.type[0] = DAV1D_RESTORATION_NONE;
+        hdr->restoration.type[1] = DAV1D_RESTORATION_NONE;
+        hdr->restoration.type[2] = DAV1D_RESTORATION_NONE;
     }
 #if DEBUG_FRAME_HDR
     printf("HDR: post-restoration: off=%ld\n",
@@ -879,8 +879,8 @@
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
 #endif
 
-    hdr->txfm_mode = hdr->all_lossless ? TX_4X4_ONLY :
-                     dav1d_get_bits(gb, 1) ? TX_SWITCHABLE : TX_LARGEST;
+    hdr->txfm_mode = hdr->all_lossless ? DAV1D_TX_4X4_ONLY :
+                     dav1d_get_bits(gb, 1) ? DAV1D_TX_SWITCHABLE : DAV1D_TX_LARGEST;
 #if DEBUG_FRAME_HDR
     printf("HDR: post-txfmmode: off=%ld\n",
            (gb->ptr - init_ptr) * 8 - gb->bits_left);
@@ -961,21 +961,21 @@
 
     if (hdr->frame_type & 1) {
         for (int i = 0; i < 7; i++) {
-            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;
+            hdr->gmv[i].type = !dav1d_get_bits(gb, 1) ? DAV1D_WM_TYPE_IDENTITY :
+                                dav1d_get_bits(gb, 1) ? DAV1D_WM_TYPE_ROT_ZOOM :
+                                dav1d_get_bits(gb, 1) ? DAV1D_WM_TYPE_TRANSLATION :
+                                                  DAV1D_WM_TYPE_AFFINE;
 
-            if (hdr->gmv[i].type == WM_TYPE_IDENTITY) continue;
+            if (hdr->gmv[i].type == DAV1D_WM_TYPE_IDENTITY) continue;
 
-            const WarpedMotionParams *const ref_gmv =
-                hdr->primary_ref_frame == PRIMARY_REF_NONE ? &dav1d_default_wm_params :
+            const Dav1dWarpedMotionParams *const ref_gmv =
+                hdr->primary_ref_frame == DAV1D_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;
             int bits, shift;
 
-            if (hdr->gmv[i].type >= WM_TYPE_ROT_ZOOM) {
+            if (hdr->gmv[i].type >= DAV1D_WM_TYPE_ROT_ZOOM) {
                 mat[2] = (1 << 16) + 2 *
                     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);
@@ -987,7 +987,7 @@
                 shift = 13 + !hdr->hp;
             }
 
-            if (hdr->gmv[i].type == WM_TYPE_AFFINE) {
+            if (hdr->gmv[i].type == DAV1D_WM_TYPE_AFFINE) {
                 mat[4] = 2 * dav1d_get_bits_subexp(gb, ref_mat[4] >> 1, 12);
                 mat[5] = (1 << 16) + 2 *
                     dav1d_get_bits_subexp(gb, (ref_mat[5] - (1 << 16)) >> 1, 12);
@@ -1203,9 +1203,9 @@
 
     switch (type) {
     case OBU_SEQ_HDR: {
-        Dav1dRef *ref = dav1d_ref_create(sizeof(Av1SequenceHeader));
+        Dav1dRef *ref = dav1d_ref_create(sizeof(Dav1dSequenceHeader));
         if (!ref) return -ENOMEM;
-        Av1SequenceHeader *seq_hdr = ref->data;
+        Dav1dSequenceHeader *seq_hdr = ref->data;
         memset(seq_hdr, 0, sizeof(*seq_hdr));
         c->frame_hdr = NULL;
         if ((res = parse_seq_hdr(c, &gb, seq_hdr)) < 0) {
@@ -1241,7 +1241,7 @@
     case OBU_FRAME_HDR:
         if (!c->seq_hdr) goto error;
         if (!c->frame_hdr_ref) {
-            c->frame_hdr_ref = dav1d_ref_create(sizeof(Av1FrameHeader));
+            c->frame_hdr_ref = dav1d_ref_create(sizeof(Dav1dFrameHeader));
             if (!c->frame_hdr_ref) return -ENOMEM;
         }
         c->frame_hdr = c->frame_hdr_ref->data;
--- a/src/recon_tmpl.c
+++ b/src/recon_tmpl.c
@@ -674,7 +674,7 @@
                        pixel *dst8, coef *dst16, const ptrdiff_t dstride,
                        const uint8_t *const b_dim, const int pl,
                        const Dav1dThreadPicture *const refp,
-                       const WarpedMotionParams *const wmp)
+                       const Dav1dWarpedMotionParams *const wmp)
 {
     assert((dst8 != NULL) ^ (dst16 != NULL));
     const Dav1dFrameContext *const f = t->f;
@@ -1171,7 +1171,7 @@
 
         if (imin(bw4, bh4) > 1 &&
             ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
-             (b->motion_mode == MM_WARP && t->warpmv.type > WM_TYPE_TRANSLATION)))
+             (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
         {
             res = warp_affine(t, dst, NULL, f->cur.stride[0], b_dim, 0, refp,
                               b->motion_mode == MM_WARP ? &t->warpmv :
@@ -1285,7 +1285,7 @@
         } else {
             if (imin(cbw4, cbh4) > 1 &&
                 ((b->inter_mode == GLOBALMV && f->gmv_warp_allowed[b->ref[0]]) ||
-                 (b->motion_mode == MM_WARP && t->warpmv.type > WM_TYPE_TRANSLATION)))
+                 (b->motion_mode == MM_WARP && t->warpmv.type > DAV1D_WM_TYPE_TRANSLATION)))
             {
                 for (int pl = 0; pl < 2; pl++) {
                     res = warp_affine(t, ((pixel *) f->cur.data[1 + pl]) + uvdstoff, NULL,
--- a/src/ref_mvs.c
+++ b/src/ref_mvs.c
@@ -309,7 +309,7 @@
   TransformationType wmtype;
   int32_t wmmat[6];
   int16_t alpha, beta, gamma, delta;
-} WarpedMotionParams;
+} Dav1dWarpedMotionParams;
 
 #define REF_FRAMES_LOG2 3
 #define REF_FRAMES (1 << REF_FRAMES_LOG2)
@@ -381,7 +381,7 @@
   // External BufferPool passed from outside.
   BufferPool buffer_pool;
 
-  WarpedMotionParams global_motion[TOTAL_REFS_PER_FRAME];
+  Dav1dWarpedMotionParams global_motion[TOTAL_REFS_PER_FRAME];
   struct {
     BLOCK_SIZE sb_size;
     int enable_order_hint;
@@ -501,7 +501,7 @@
 // allow_hp is zero, the bottom bit will always be zero. If CONFIG_AMVR and
 // is_integer is true, the bottom three bits will be zero (so the motion vector
 // represents an integer)
-static INLINE int_mv gm_get_motion_vector(const WarpedMotionParams *gm,
+static INLINE int_mv gm_get_motion_vector(const Dav1dWarpedMotionParams *gm,
                                           int allow_hp, BLOCK_SIZE bsize,
                                           int mi_col, int mi_row,
                                           int is_integer) {
@@ -836,7 +836,7 @@
     const MB_MODE_INFO *const candidate, const MV_REFERENCE_FRAME rf[2],
     uint8_t *refmv_count, uint8_t *ref_match_count, uint8_t *newmv_count,
     CANDIDATE_MV *ref_mv_stack, int_mv *gm_mv_candidates,
-    const WarpedMotionParams *gm_params, int col, int weight) {
+    const Dav1dWarpedMotionParams *gm_params, int col, int weight) {
   if (!is_inter_block(candidate)) return;  // for intrabc
   int index = 0, ref;
   assert(weight % 2 == 0);
@@ -1989,7 +1989,7 @@
                            const unsigned cur_poc,
                            const unsigned ref_poc[7],
                            const unsigned ref_ref_poc[7][7],
-                           const WarpedMotionParams gmv[7],
+                           const Dav1dWarpedMotionParams gmv[7],
                            const int allow_hp,
                            const int force_int_mv,
                            const int allow_ref_frame_mvs,
@@ -2003,7 +2003,7 @@
                            const unsigned cur_poc,
                            const unsigned ref_poc[7],
                            const unsigned ref_ref_poc[7][7],
-                           const WarpedMotionParams gmv[7],
+                           const Dav1dWarpedMotionParams gmv[7],
                            const int allow_hp,
                            const int force_int_mv,
                            const int allow_ref_frame_mvs,
--- a/src/ref_mvs.h
+++ b/src/ref_mvs.h
@@ -45,7 +45,7 @@
                            unsigned cur_poc,
                            const unsigned ref_poc[7],
                            const unsigned ref_ref_poc[7][7],
-                           const WarpedMotionParams gmv[7],
+                           const Dav1dWarpedMotionParams gmv[7],
                            int allow_hp, int force_int_mv,
                            int allow_ref_frame_mvs, int order_hint);
 
@@ -156,7 +156,7 @@
     } while (--bh4);
 }
 
-static inline void fix_mv_precision(const Av1FrameHeader *const hdr,
+static inline void fix_mv_precision(const Dav1dFrameHeader *const hdr,
                                     mv *const mv)
 {
     if (hdr->force_integer_mv) {
--- a/src/tables.c
+++ b/src/tables.c
@@ -418,35 +418,35 @@
     [WHT_WHT]           = TX_CLASS_2D,
 };
 
-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,
-        [FILTER_8TAP_SMOOTH]  = FILTER_2D_8TAP_REGULAR_SMOOTH,
-    }, [FILTER_8TAP_SHARP] = {
-        [FILTER_8TAP_REGULAR] = FILTER_2D_8TAP_SHARP_REGULAR,
-        [FILTER_8TAP_SHARP]   = FILTER_2D_8TAP_SHARP,
-        [FILTER_8TAP_SMOOTH]  = FILTER_2D_8TAP_SHARP_SMOOTH,
-    }, [FILTER_8TAP_SMOOTH] = {
-        [FILTER_8TAP_REGULAR] = FILTER_2D_8TAP_SMOOTH_REGULAR,
-        [FILTER_8TAP_SHARP]   = FILTER_2D_8TAP_SMOOTH_SHARP,
-        [FILTER_8TAP_SMOOTH]  = FILTER_2D_8TAP_SMOOTH,
-    }, [FILTER_BILINEAR] = {
-        [FILTER_BILINEAR]     = FILTER_2D_BILINEAR,
+const uint8_t /* enum Filter2d */ dav1d_filter_2d[DAV1D_N_FILTERS][DAV1D_N_FILTERS] = {
+    [DAV1D_FILTER_8TAP_REGULAR] = {
+        [DAV1D_FILTER_8TAP_REGULAR] = FILTER_2D_8TAP_REGULAR,
+        [DAV1D_FILTER_8TAP_SHARP]   = FILTER_2D_8TAP_REGULAR_SHARP,
+        [DAV1D_FILTER_8TAP_SMOOTH]  = FILTER_2D_8TAP_REGULAR_SMOOTH,
+    }, [DAV1D_FILTER_8TAP_SHARP] = {
+        [DAV1D_FILTER_8TAP_REGULAR] = FILTER_2D_8TAP_SHARP_REGULAR,
+        [DAV1D_FILTER_8TAP_SHARP]   = FILTER_2D_8TAP_SHARP,
+        [DAV1D_FILTER_8TAP_SMOOTH]  = FILTER_2D_8TAP_SHARP_SMOOTH,
+    }, [DAV1D_FILTER_8TAP_SMOOTH] = {
+        [DAV1D_FILTER_8TAP_REGULAR] = FILTER_2D_8TAP_SMOOTH_REGULAR,
+        [DAV1D_FILTER_8TAP_SHARP]   = FILTER_2D_8TAP_SMOOTH_SHARP,
+        [DAV1D_FILTER_8TAP_SMOOTH]  = FILTER_2D_8TAP_SMOOTH,
+    }, [DAV1D_FILTER_BILINEAR] = {
+        [DAV1D_FILTER_BILINEAR]     = FILTER_2D_BILINEAR,
     }
 };
 
-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 },
-    [FILTER_2D_8TAP_SHARP_REGULAR]  = { FILTER_8TAP_REGULAR, FILTER_8TAP_SHARP   },
-    [FILTER_2D_8TAP_SHARP_SMOOTH]   = { FILTER_8TAP_SMOOTH,  FILTER_8TAP_SHARP   },
-    [FILTER_2D_8TAP_SHARP]          = { FILTER_8TAP_SHARP,   FILTER_8TAP_SHARP   },
-    [FILTER_2D_8TAP_SMOOTH_REGULAR] = { FILTER_8TAP_REGULAR, FILTER_8TAP_SMOOTH  },
-    [FILTER_2D_8TAP_SMOOTH]         = { FILTER_8TAP_SMOOTH,  FILTER_8TAP_SMOOTH  },
-    [FILTER_2D_8TAP_SMOOTH_SHARP]   = { FILTER_8TAP_SHARP,   FILTER_8TAP_SMOOTH  },
-    [FILTER_2D_BILINEAR]            = { FILTER_BILINEAR,     FILTER_BILINEAR     },
+const uint8_t /* enum Dav1dFilterMode */ dav1d_filter_dir[N_2D_FILTERS][2] = {
+    [FILTER_2D_8TAP_REGULAR]        = { DAV1D_FILTER_8TAP_REGULAR, DAV1D_FILTER_8TAP_REGULAR },
+    [FILTER_2D_8TAP_REGULAR_SMOOTH] = { DAV1D_FILTER_8TAP_SMOOTH,  DAV1D_FILTER_8TAP_REGULAR },
+    [FILTER_2D_8TAP_REGULAR_SHARP]  = { DAV1D_FILTER_8TAP_SHARP,   DAV1D_FILTER_8TAP_REGULAR },
+    [FILTER_2D_8TAP_SHARP_REGULAR]  = { DAV1D_FILTER_8TAP_REGULAR, DAV1D_FILTER_8TAP_SHARP   },
+    [FILTER_2D_8TAP_SHARP_SMOOTH]   = { DAV1D_FILTER_8TAP_SMOOTH,  DAV1D_FILTER_8TAP_SHARP   },
+    [FILTER_2D_8TAP_SHARP]          = { DAV1D_FILTER_8TAP_SHARP,   DAV1D_FILTER_8TAP_SHARP   },
+    [FILTER_2D_8TAP_SMOOTH_REGULAR] = { DAV1D_FILTER_8TAP_REGULAR, DAV1D_FILTER_8TAP_SMOOTH  },
+    [FILTER_2D_8TAP_SMOOTH]         = { DAV1D_FILTER_8TAP_SMOOTH,  DAV1D_FILTER_8TAP_SMOOTH  },
+    [FILTER_2D_8TAP_SMOOTH_SHARP]   = { DAV1D_FILTER_8TAP_SHARP,   DAV1D_FILTER_8TAP_SMOOTH  },
+    [FILTER_2D_BILINEAR]            = { DAV1D_FILTER_BILINEAR,     DAV1D_FILTER_BILINEAR     },
 };
 
 const uint8_t dav1d_filter_mode_to_y_mode[5] = {
@@ -481,8 +481,8 @@
     [BS_8x8]   = 0,
 };
 
-const WarpedMotionParams dav1d_default_wm_params = {
-    .type = WM_TYPE_IDENTITY,
+const Dav1dWarpedMotionParams dav1d_default_wm_params = {
+    .type = DAV1D_WM_TYPE_IDENTITY,
     .matrix = {
         0, 0, 1 << 16,
         0, 0, 1 << 16,
@@ -524,7 +524,7 @@
 };
 
 const int8_t ALIGN(dav1d_mc_subpel_filters[5][15][8], 8) = {
-    [FILTER_8TAP_REGULAR] = {
+    [DAV1D_FILTER_8TAP_REGULAR] = {
         {   0,   1,  -3,  63,   4,  -1,   0,   0 },
         {   0,   1,  -5,  61,   9,  -2,   0,   0 },
         {   0,   1,  -6,  58,  14,  -4,   1,   0 },
@@ -540,7 +540,7 @@
         {   0,   1,  -4,  14,  58,  -6,   1,   0 },
         {   0,   0,  -2,   9,  61,  -5,   1,   0 },
         {   0,   0,  -1,   4,  63,  -3,   1,   0 }
-    }, [FILTER_8TAP_SMOOTH] = {
+    }, [DAV1D_FILTER_8TAP_SMOOTH] = {
         {   0,   1,  14,  31,  17,   1,   0,   0 },
         {   0,   0,  13,  31,  18,   2,   0,   0 },
         {   0,   0,  11,  31,  20,   2,   0,   0 },
@@ -556,7 +556,7 @@
         {   0,   0,   2,  20,  31,  11,   0,   0 },
         {   0,   0,   2,  18,  31,  13,   0,   0 },
         {   0,   0,   1,  17,  31,  14,   1,   0 }
-    }, [FILTER_8TAP_SHARP] = {
+    }, [DAV1D_FILTER_8TAP_SHARP] = {
         {  -1,   1,  -3,  63,   4,  -1,   1,   0 },
         {  -1,   3,  -6,  62,   8,  -3,   2,  -1 },
         {  -1,   4,  -9,  60,  13,  -5,   3,  -1 },
@@ -573,7 +573,7 @@
         {  -1,   2,  -3,   8,  62,  -6,   3,  -1 },
         {   0,   1,  -1,   4,  63,  -3,   1,  -1 }
     /* width <= 4 */
-    }, [3 + FILTER_8TAP_REGULAR] = {
+    }, [3 + DAV1D_FILTER_8TAP_REGULAR] = {
         {   0,   0,  -2,  63,   4,  -1,   0,   0 },
         {   0,   0,  -4,  61,   9,  -2,   0,   0 },
         {   0,   0,  -5,  58,  14,  -3,   0,   0 },
@@ -589,7 +589,7 @@
         {   0,   0,  -3,  14,  58,  -5,   0,   0 },
         {   0,   0,  -2,   9,  61,  -4,   0,   0 },
         {   0,   0,  -1,   4,  63,  -2,   0,   0 }
-    }, [3 + FILTER_8TAP_SMOOTH] = {
+    }, [3 + DAV1D_FILTER_8TAP_SMOOTH] = {
         {   0,   0,  15,  31,  17,   1,   0,   0 },
         {   0,   0,  13,  31,  18,   2,   0,   0 },
         {   0,   0,  11,  31,  20,   2,   0,   0 },
--- a/src/tables.h
+++ b/src/tables.h
@@ -63,8 +63,8 @@
 extern const uint8_t /* enum TxClass */
                      dav1d_tx_type_class[N_TX_TYPES_PLUS_LL];
 extern const uint8_t /* enum Filter2d */
-                     dav1d_filter_2d[N_FILTERS /* h */][N_FILTERS /* v */];
-extern const uint8_t /* enum FilterMode */ dav1d_filter_dir[N_2D_FILTERS][2];
+                     dav1d_filter_2d[DAV1D_N_FILTERS /* h */][DAV1D_N_FILTERS /* v */];
+extern const uint8_t /* enum Dav1dFilterMode */ 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];
 
@@ -104,7 +104,7 @@
     (1 << BS_8x16) |
     (1 << BS_8x8);
 
-extern const WarpedMotionParams dav1d_default_wm_params;
+extern const Dav1dWarpedMotionParams dav1d_default_wm_params;
 
 extern const int16_t dav1d_sgr_params[16][4];
 extern const int dav1d_sgr_x_by_xplus1[256];
--- a/src/warpmv.c
+++ b/src/warpmv.c
@@ -78,7 +78,7 @@
     return div_lut[f];
 }
 
-int dav1d_get_shear_params(WarpedMotionParams *const wm) {
+int dav1d_get_shear_params(Dav1dWarpedMotionParams *const wm) {
     const int32_t *const mat = wm->matrix;
 
     if (mat[2] <= 0) return 1;
@@ -129,7 +129,7 @@
 
 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 mv mv, Dav1dWarpedMotionParams *const wm,
                           const int bx4, const int by4)
 {
     int32_t *const mat = wm->matrix;
--- a/src/warpmv.h
+++ b/src/warpmv.h
@@ -30,8 +30,8 @@
 
 #include "src/levels.h"
 
-int dav1d_get_shear_params(WarpedMotionParams *wm);
+int dav1d_get_shear_params(Dav1dWarpedMotionParams *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);
+                          mv mv, Dav1dWarpedMotionParams *wm, int by, int bx);
 
 #endif /* __DAV1D_SRC_WARPMV_H__ */