summaryrefslogtreecommitdiffstats
path: root/third_party/dav1d/include
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/dav1d/include
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/dav1d/include')
-rw-r--r--third_party/dav1d/include/common/attributes.h203
-rw-r--r--third_party/dav1d/include/common/bitdepth.h93
-rw-r--r--third_party/dav1d/include/common/dump.h92
-rw-r--r--third_party/dav1d/include/common/frame.h45
-rw-r--r--third_party/dav1d/include/common/intops.h84
-rw-r--r--third_party/dav1d/include/common/validate.h61
-rw-r--r--third_party/dav1d/include/compat/gcc/stdatomic.h51
-rw-r--r--third_party/dav1d/include/compat/getopt.h95
-rw-r--r--third_party/dav1d/include/compat/msvc/stdatomic.h82
-rw-r--r--third_party/dav1d/include/dav1d/common.h94
-rw-r--r--third_party/dav1d/include/dav1d/data.h117
-rw-r--r--third_party/dav1d/include/dav1d/dav1d.h329
-rw-r--r--third_party/dav1d/include/dav1d/headers.h444
-rw-r--r--third_party/dav1d/include/dav1d/meson.build45
-rw-r--r--third_party/dav1d/include/dav1d/picture.h157
-rw-r--r--third_party/dav1d/include/dav1d/version.h.in50
-rw-r--r--third_party/dav1d/include/meson.build34
-rw-r--r--third_party/dav1d/include/vcs_version.h.in2
18 files changed, 2078 insertions, 0 deletions
diff --git a/third_party/dav1d/include/common/attributes.h b/third_party/dav1d/include/common/attributes.h
new file mode 100644
index 0000000000..cd058abf9b
--- /dev/null
+++ b/third_party/dav1d/include/common/attributes.h
@@ -0,0 +1,203 @@
+/*
+ * 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_COMMON_ATTRIBUTES_H
+#define DAV1D_COMMON_ATTRIBUTES_H
+
+#include "config.h"
+
+#include <stddef.h>
+#include <assert.h>
+
+#ifndef __has_attribute
+#define __has_attribute(x) 0
+#endif
+
+#ifndef __has_feature
+#define __has_feature(x) 0
+#endif
+
+#ifdef __GNUC__
+#define ATTR_ALIAS __attribute__((may_alias))
+#if defined(__MINGW32__) && !defined(__clang__)
+#define ATTR_FORMAT_PRINTF(fmt, attr) __attribute__((__format__(__gnu_printf__, fmt, attr)))
+#else
+#define ATTR_FORMAT_PRINTF(fmt, attr) __attribute__((__format__(__printf__, fmt, attr)))
+#endif
+#define COLD __attribute__((cold))
+#else
+#define ATTR_ALIAS
+#define ATTR_FORMAT_PRINTF(fmt, attr)
+#define COLD
+#endif
+
+#if ARCH_X86_64
+/* x86-64 needs 32- and 64-byte alignment for AVX2 and AVX-512. */
+#define ALIGN_64_VAL 64
+#define ALIGN_32_VAL 32
+#define ALIGN_16_VAL 16
+#elif ARCH_AARCH64 || ARCH_ARM || ARCH_LOONGARCH || ARCH_PPC64LE || ARCH_X86_32
+/* ARM doesn't benefit from anything more than 16-byte alignment. */
+#define ALIGN_64_VAL 16
+#define ALIGN_32_VAL 16
+#define ALIGN_16_VAL 16
+#else
+/* No need for extra alignment on platforms without assembly. */
+#define ALIGN_64_VAL 8
+#define ALIGN_32_VAL 8
+#define ALIGN_16_VAL 8
+#endif
+
+/*
+ * API for variables, struct members (ALIGN()) like:
+ * uint8_t var[1][2][3][4]
+ * becomes:
+ * ALIGN(uint8_t var[1][2][3][4], alignment).
+ */
+#ifdef _MSC_VER
+#define ALIGN(ll, a) \
+ __declspec(align(a)) ll
+#else
+#define ALIGN(line, align) \
+ line __attribute__((aligned(align)))
+#endif
+
+/*
+ * API for stack alignment (ALIGN_STK_$align()) of variables like:
+ * uint8_t var[1][2][3][4]
+ * becomes:
+ * ALIGN_STK_$align(uint8_t, var, 1, [2][3][4])
+ */
+#define ALIGN_STK_64(type, var, sz1d, sznd) \
+ ALIGN(type var[sz1d]sznd, ALIGN_64_VAL)
+#define ALIGN_STK_32(type, var, sz1d, sznd) \
+ ALIGN(type var[sz1d]sznd, ALIGN_32_VAL)
+#define ALIGN_STK_16(type, var, sz1d, sznd) \
+ ALIGN(type var[sz1d]sznd, ALIGN_16_VAL)
+
+/*
+ * Forbid inlining of a function:
+ * static NOINLINE void func() {}
+ */
+#ifdef _MSC_VER
+#define NOINLINE __declspec(noinline)
+#elif __has_attribute(noclone)
+#define NOINLINE __attribute__((noinline, noclone))
+#else
+#define NOINLINE __attribute__((noinline))
+#endif
+
+#ifdef _MSC_VER
+#define ALWAYS_INLINE __forceinline
+#else
+#define ALWAYS_INLINE __attribute__((always_inline)) inline
+#endif
+
+#if (defined(__ELF__) || defined(__MACH__) || (defined(_WIN32) && defined(__clang__))) && __has_attribute(visibility)
+#define EXTERN extern __attribute__((visibility("hidden")))
+#else
+#define EXTERN extern
+#endif
+
+#ifdef __clang__
+#define NO_SANITIZE(x) __attribute__((no_sanitize(x)))
+#else
+#define NO_SANITIZE(x)
+#endif
+
+#if defined(NDEBUG) && (defined(__GNUC__) || defined(__clang__))
+#undef assert
+#define assert(x) do { if (!(x)) __builtin_unreachable(); } while (0)
+#elif defined(NDEBUG) && defined(_MSC_VER)
+#undef assert
+#define assert __assume
+#endif
+
+#if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__)
+# define dav1d_uninit(x) x=x
+#else
+# define dav1d_uninit(x) x
+#endif
+
+#if defined(_MSC_VER) && !defined(__clang__)
+#include <intrin.h>
+
+static inline int ctz(const unsigned int mask) {
+ unsigned long idx;
+ _BitScanForward(&idx, mask);
+ return idx;
+}
+
+static inline int clz(const unsigned int mask) {
+ unsigned long leading_zero = 0;
+ _BitScanReverse(&leading_zero, mask);
+ return (31 - leading_zero);
+}
+
+#ifdef _WIN64
+static inline int clzll(const unsigned long long mask) {
+ unsigned long leading_zero = 0;
+ _BitScanReverse64(&leading_zero, mask);
+ return (63 - leading_zero);
+}
+#else /* _WIN64 */
+static inline int clzll(const unsigned long long mask) {
+ if (mask >> 32)
+ return clz((unsigned)(mask >> 32));
+ else
+ return clz((unsigned)mask) + 32;
+}
+#endif /* _WIN64 */
+#else /* !_MSC_VER */
+static inline int ctz(const unsigned int mask) {
+ return __builtin_ctz(mask);
+}
+
+static inline int clz(const unsigned int mask) {
+ return __builtin_clz(mask);
+}
+
+static inline int clzll(const unsigned long long mask) {
+ return __builtin_clzll(mask);
+}
+#endif /* !_MSC_VER */
+
+#ifndef static_assert
+#define CHECK_OFFSET(type, field, name) \
+ struct check_##type##_##field { int x[(name == offsetof(type, field)) ? 1 : -1]; }
+#else
+#define CHECK_OFFSET(type, field, name) \
+ static_assert(name == offsetof(type, field), #field)
+#endif
+
+#ifdef _MSC_VER
+#define PACKED(...) __pragma(pack(push, 1)) __VA_ARGS__ __pragma(pack(pop))
+#else
+#define PACKED(...) __VA_ARGS__ __attribute__((__packed__))
+#endif
+
+#endif /* DAV1D_COMMON_ATTRIBUTES_H */
diff --git a/third_party/dav1d/include/common/bitdepth.h b/third_party/dav1d/include/common/bitdepth.h
new file mode 100644
index 0000000000..8a8f5740b8
--- /dev/null
+++ b/third_party/dav1d/include/common/bitdepth.h
@@ -0,0 +1,93 @@
+/*
+ * 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_COMMON_BITDEPTH_H
+#define DAV1D_COMMON_BITDEPTH_H
+
+#include <stdint.h>
+#include <string.h>
+
+#include "common/attributes.h"
+
+#if !defined(BITDEPTH)
+typedef uint8_t pixel; /* can't be void due to pointer-to-array usage */
+typedef void coef;
+#define HIGHBD_DECL_SUFFIX /* nothing */
+#define HIGHBD_CALL_SUFFIX /* nothing */
+#define HIGHBD_TAIL_SUFFIX /* nothing */
+#elif BITDEPTH == 8
+typedef uint8_t pixel;
+typedef int16_t coef;
+#define PIXEL_TYPE uint8_t
+#define COEF_TYPE int16_t
+#define pixel_copy memcpy
+#define pixel_set memset
+#define iclip_pixel iclip_u8
+#define PIX_HEX_FMT "%02x"
+#define bitfn(x) x##_8bpc
+#define BF(x, suffix) x##_8bpc_##suffix
+#define PXSTRIDE(x) (x)
+#define highbd_only(x)
+#define HIGHBD_DECL_SUFFIX /* nothing */
+#define HIGHBD_CALL_SUFFIX /* nothing */
+#define HIGHBD_TAIL_SUFFIX /* nothing */
+#define bitdepth_from_max(x) 8
+#define BITDEPTH_MAX 0xff
+#elif BITDEPTH == 16
+typedef uint16_t pixel;
+typedef int32_t coef;
+#define PIXEL_TYPE uint16_t
+#define COEF_TYPE int32_t
+#define pixel_copy(a, b, c) memcpy(a, b, (c) << 1)
+static inline void pixel_set(pixel *const dst, const int val, const int num) {
+ for (int n = 0; n < num; n++)
+ dst[n] = val;
+}
+#define PIX_HEX_FMT "%03x"
+#define iclip_pixel(x) iclip(x, 0, bitdepth_max)
+#define HIGHBD_DECL_SUFFIX , const int bitdepth_max
+#define HIGHBD_CALL_SUFFIX , f->bitdepth_max
+#define HIGHBD_TAIL_SUFFIX , bitdepth_max
+#define bitdepth_from_max(bitdepth_max) (32 - clz(bitdepth_max))
+#define BITDEPTH_MAX bitdepth_max
+#define bitfn(x) x##_16bpc
+#define BF(x, suffix) x##_16bpc_##suffix
+static inline ptrdiff_t PXSTRIDE(const ptrdiff_t x) {
+ assert(!(x & 1));
+ return x >> 1;
+}
+#define highbd_only(x) x
+#else
+#error invalid value for bitdepth
+#endif
+#define bytefn(x) bitfn(x)
+
+#define bitfn_decls(name, ...) \
+name##_8bpc(__VA_ARGS__); \
+name##_16bpc(__VA_ARGS__)
+
+#endif /* DAV1D_COMMON_BITDEPTH_H */
diff --git a/third_party/dav1d/include/common/dump.h b/third_party/dav1d/include/common/dump.h
new file mode 100644
index 0000000000..9ffab6a45e
--- /dev/null
+++ b/third_party/dav1d/include/common/dump.h
@@ -0,0 +1,92 @@
+/*
+ * 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_COMMON_DUMP_H
+#define DAV1D_COMMON_DUMP_H
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+
+#include "common/bitdepth.h"
+
+static inline void append_plane_to_file(const pixel *buf, ptrdiff_t stride,
+ int w, int h, const char *const file)
+{
+ FILE *const f = fopen(file, "ab");
+ while (h--) {
+ fwrite(buf, w * sizeof(pixel), 1, f);
+ buf += PXSTRIDE(stride);
+ }
+ fclose(f);
+}
+
+static inline void hex_fdump(FILE *out, const pixel *buf, ptrdiff_t stride,
+ int w, int h, const char *what)
+{
+ fprintf(out, "%s\n", what);
+ while (h--) {
+ int x;
+ for (x = 0; x < w; x++)
+ fprintf(out, " " PIX_HEX_FMT, buf[x]);
+ buf += PXSTRIDE(stride);
+ fprintf(out, "\n");
+ }
+}
+
+static inline void hex_dump(const pixel *buf, ptrdiff_t stride,
+ int w, int h, const char *what)
+{
+ hex_fdump(stdout, buf, stride, w, h, what);
+}
+
+static inline void coef_dump(const coef *buf, const int w, const int h,
+ const int len, const char *what)
+{
+ int y;
+ printf("%s\n", what);
+ for (y = 0; y < h; y++) {
+ int x;
+ for (x = 0; x < w; x++)
+ printf(" %*d", len, buf[x]);
+ buf += w;
+ printf("\n");
+ }
+}
+
+static inline void ac_dump(const int16_t *buf, int w, int h, const char *what)
+{
+ printf("%s\n", what);
+ while (h--) {
+ for (int x = 0; x < w; x++)
+ printf(" %03d", buf[x]);
+ buf += w;
+ printf("\n");
+ }
+}
+
+#endif /* DAV1D_COMMON_DUMP_H */
diff --git a/third_party/dav1d/include/common/frame.h b/third_party/dav1d/include/common/frame.h
new file mode 100644
index 0000000000..767f7fd06a
--- /dev/null
+++ b/third_party/dav1d/include/common/frame.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright © 2021, VideoLAN and dav1d authors
+ * 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_COMMON_FRAME_H
+#define DAV1D_COMMON_FRAME_H
+
+/*
+ * Checks whether Dav1dFrameType == INTER || == SWITCH
+ * Both are defined as odd numbers {1, 3} and therefore have the LSB set.
+ * See also: AV1 spec 6.8.2
+ */
+#define IS_INTER_OR_SWITCH(frame_header) \
+ ((frame_header)->frame_type & 1)
+
+/*
+ * Checks whether Dav1dFrameType == KEY || == INTRA
+ * See also: AV1 spec 6.8.2
+ */
+#define IS_KEY_OR_INTRA(frame_header) \
+ (!IS_INTER_OR_SWITCH(frame_header))
+
+#endif /* DAV1D_COMMON_FRAME_H */
diff --git a/third_party/dav1d/include/common/intops.h b/third_party/dav1d/include/common/intops.h
new file mode 100644
index 0000000000..2d21998b71
--- /dev/null
+++ b/third_party/dav1d/include/common/intops.h
@@ -0,0 +1,84 @@
+/*
+ * 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_COMMON_INTOPS_H
+#define DAV1D_COMMON_INTOPS_H
+
+#include <stdint.h>
+
+#include "common/attributes.h"
+
+static inline int imax(const int a, const int b) {
+ return a > b ? a : b;
+}
+
+static inline int imin(const int a, const int b) {
+ return a < b ? a : b;
+}
+
+static inline unsigned umax(const unsigned a, const unsigned b) {
+ return a > b ? a : b;
+}
+
+static inline unsigned umin(const unsigned a, const unsigned b) {
+ return a < b ? a : b;
+}
+
+static inline int iclip(const int v, const int min, const int max) {
+ return v < min ? min : v > max ? max : v;
+}
+
+static inline int iclip_u8(const int v) {
+ return iclip(v, 0, 255);
+}
+
+static inline int apply_sign(const int v, const int s) {
+ return s < 0 ? -v : v;
+}
+
+static inline int apply_sign64(const int v, const int64_t s) {
+ return s < 0 ? -v : v;
+}
+
+static inline int ulog2(const unsigned v) {
+ return 31 - clz(v);
+}
+
+static inline int u64log2(const uint64_t v) {
+ return 63 - clzll(v);
+}
+
+static inline unsigned inv_recenter(const unsigned r, const unsigned v) {
+ if (v > (r << 1))
+ return v;
+ else if ((v & 1) == 0)
+ return (v >> 1) + r;
+ else
+ return r - ((v + 1) >> 1);
+}
+
+#endif /* DAV1D_COMMON_INTOPS_H */
diff --git a/third_party/dav1d/include/common/validate.h b/third_party/dav1d/include/common/validate.h
new file mode 100644
index 0000000000..3aaed5bb92
--- /dev/null
+++ b/third_party/dav1d/include/common/validate.h
@@ -0,0 +1,61 @@
+/*
+ * 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_COMMON_VALIDATE_H
+#define DAV1D_COMMON_VALIDATE_H
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#if defined(NDEBUG)
+#define debug_print(...) do {} while (0)
+#define debug_abort() do {} while (0)
+#else
+#define debug_print(...) fprintf(stderr, __VA_ARGS__)
+#define debug_abort abort
+#endif
+
+#define validate_input_or_ret_with_msg(x, r, ...) \
+ if (!(x)) { \
+ debug_print("Input validation check \'%s\' failed in %s!\n", \
+ #x, __func__); \
+ debug_print(__VA_ARGS__); \
+ debug_abort(); \
+ return r; \
+ }
+
+#define validate_input_or_ret(x, r) \
+ if (!(x)) { \
+ debug_print("Input validation check \'%s\' failed in %s!\n", \
+ #x, __func__); \
+ debug_abort(); \
+ return r; \
+ }
+
+#define validate_input(x) validate_input_or_ret(x, )
+
+#endif /* DAV1D_COMMON_VALIDATE_H */
diff --git a/third_party/dav1d/include/compat/gcc/stdatomic.h b/third_party/dav1d/include/compat/gcc/stdatomic.h
new file mode 100644
index 0000000000..29f906321f
--- /dev/null
+++ b/third_party/dav1d/include/compat/gcc/stdatomic.h
@@ -0,0 +1,51 @@
+/*
+* Copyright © 2018, VideoLAN and dav1d authors
+* 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 GCCVER_STDATOMIC_H_
+#define GCCVER_STDATOMIC_H_
+
+#if !defined(__cplusplus)
+
+typedef int atomic_int;
+typedef unsigned int atomic_uint;
+
+#define memory_order_relaxed __ATOMIC_RELAXED
+#define memory_order_acquire __ATOMIC_ACQUIRE
+
+#define atomic_init(p_a, v) do { *(p_a) = (v); } while(0)
+#define atomic_store(p_a, v) __atomic_store_n(p_a, v, __ATOMIC_SEQ_CST)
+#define atomic_load(p_a) __atomic_load_n(p_a, __ATOMIC_SEQ_CST)
+#define atomic_load_explicit(p_a, mo) __atomic_load_n(p_a, mo)
+#define atomic_fetch_add(p_a, inc) __atomic_fetch_add(p_a, inc, __ATOMIC_SEQ_CST)
+#define atomic_fetch_add_explicit(p_a, inc, mo) __atomic_fetch_add(p_a, inc, mo)
+#define atomic_fetch_sub(p_a, dec) __atomic_fetch_sub(p_a, dec, __ATOMIC_SEQ_CST)
+#define atomic_exchange(p_a, v) __atomic_exchange_n(p_a, v, __ATOMIC_SEQ_CST)
+#define atomic_fetch_or(p_a, v) __atomic_fetch_or(p_a, v, __ATOMIC_SEQ_CST)
+#define atomic_compare_exchange_strong(p_a, expected, desired) __atomic_compare_exchange_n(p_a, expected, desired, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
+
+#endif /* !defined(__cplusplus) */
+
+#endif /* GCCVER_STDATOMIC_H_ */
diff --git a/third_party/dav1d/include/compat/getopt.h b/third_party/dav1d/include/compat/getopt.h
new file mode 100644
index 0000000000..930e002a13
--- /dev/null
+++ b/third_party/dav1d/include/compat/getopt.h
@@ -0,0 +1,95 @@
+#ifndef __GETOPT_H__
+/**
+ * DISCLAIMER
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ *
+ * The mingw-w64 runtime package and its code is distributed in the hope that it
+ * will be useful but WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESSED OR
+ * IMPLIED ARE HEREBY DISCLAIMED. This includes but is not limited to
+ * warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#define __GETOPT_H__
+
+/* All the headers include this file. */
+#include <crtdefs.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int optind; /* index of first non-option in argv */
+extern int optopt; /* single option character, as parsed */
+extern int opterr; /* flag to enable built-in diagnostics... */
+ /* (user may set to zero, to suppress) */
+
+extern char *optarg; /* pointer to argument of current option */
+
+extern int getopt(int nargc, char * const *nargv, const char *options);
+
+#ifdef _BSD_SOURCE
+/*
+ * BSD adds the non-standard `optreset' feature, for reinitialisation
+ * of `getopt' parsing. We support this feature, for applications which
+ * proclaim their BSD heritage, before including this header; however,
+ * to maintain portability, developers are advised to avoid it.
+ */
+# define optreset __mingw_optreset
+extern int optreset;
+#endif
+#ifdef __cplusplus
+}
+#endif
+/*
+ * POSIX requires the `getopt' API to be specified in `unistd.h';
+ * thus, `unistd.h' includes this header. However, we do not want
+ * to expose the `getopt_long' or `getopt_long_only' APIs, when
+ * included in this manner. Thus, close the standard __GETOPT_H__
+ * declarations block, and open an additional __GETOPT_LONG_H__
+ * specific block, only when *not* __UNISTD_H_SOURCED__, in which
+ * to declare the extended API.
+ */
+#if !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__)
+#define __GETOPT_LONG_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct option /* specification for a long form option... */
+{
+ const char *name; /* option name, without leading hyphens */
+ int has_arg; /* does it take an argument? */
+ int *flag; /* where to save its status, or NULL */
+ int val; /* its associated status value */
+};
+
+enum /* permitted values for its `has_arg' field... */
+{
+ no_argument = 0, /* option never takes an argument */
+ required_argument, /* option always requires an argument */
+ optional_argument /* option may take an argument */
+};
+
+extern int getopt_long(int nargc, char * const *nargv, const char *options,
+ const struct option *long_options, int *idx);
+extern int getopt_long_only(int nargc, char * const *nargv, const char *options,
+ const struct option *long_options, int *idx);
+/*
+ * Previous MinGW implementation had...
+ */
+#ifndef HAVE_DECL_GETOPT
+/*
+ * ...for the long form API only; keep this for compatibility.
+ */
+# define HAVE_DECL_GETOPT 1
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__) */
+
+#endif /* !defined(__GETOPT_H__) */
diff --git a/third_party/dav1d/include/compat/msvc/stdatomic.h b/third_party/dav1d/include/compat/msvc/stdatomic.h
new file mode 100644
index 0000000000..618f0ee87d
--- /dev/null
+++ b/third_party/dav1d/include/compat/msvc/stdatomic.h
@@ -0,0 +1,82 @@
+/*
+* Copyright © 2018, VideoLAN and dav1d authors
+* 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 MSCVER_STDATOMIC_H_
+#define MSCVER_STDATOMIC_H_
+
+#if !defined(__cplusplus) && defined(_MSC_VER)
+
+#pragma warning(push)
+#pragma warning(disable:4067) /* newline for __has_include_next */
+
+#if defined(__clang__) && __has_include_next(<stdatomic.h>)
+ /* use the clang stdatomic.h with clang-cl*/
+# include_next <stdatomic.h>
+#else /* ! stdatomic.h */
+
+#include <windows.h>
+
+#include "common/attributes.h"
+
+typedef volatile LONG atomic_int;
+typedef volatile ULONG atomic_uint;
+
+typedef enum {
+ memory_order_relaxed,
+ memory_order_acquire
+} msvc_atomic_memory_order;
+
+#define atomic_init(p_a, v) do { *(p_a) = (v); } while(0)
+#define atomic_store(p_a, v) InterlockedExchange((LONG*)p_a, v)
+#define atomic_load(p_a) InterlockedCompareExchange((LONG*)p_a, 0, 0)
+#define atomic_exchange(p_a, v) InterlockedExchange(p_a, v)
+#define atomic_load_explicit(p_a, mo) atomic_load(p_a)
+
+static inline int atomic_compare_exchange_strong_int(LONG *obj, LONG *expected,
+ LONG desired)
+{
+ LONG orig = *expected;
+ *expected = InterlockedCompareExchange(obj, desired, orig);
+ return *expected == orig;
+}
+#define atomic_compare_exchange_strong(p_a, expected, desired) atomic_compare_exchange_strong_int((LONG *)p_a, (LONG *)expected, (LONG)desired)
+
+/*
+ * TODO use a special call to increment/decrement
+ * using InterlockedIncrement/InterlockedDecrement
+ */
+#define atomic_fetch_add(p_a, inc) InterlockedExchangeAdd(p_a, inc)
+#define atomic_fetch_sub(p_a, dec) InterlockedExchangeAdd(p_a, -(dec))
+#define atomic_fetch_or(p_a, v) InterlockedOr(p_a, v)
+#define atomic_fetch_add_explicit(p_a, inc, mo) atomic_fetch_add(p_a, inc)
+
+#endif /* ! stdatomic.h */
+
+#pragma warning(pop)
+
+#endif /* !defined(__cplusplus) && defined(_MSC_VER) */
+
+#endif /* MSCVER_STDATOMIC_H_ */
diff --git a/third_party/dav1d/include/dav1d/common.h b/third_party/dav1d/include/dav1d/common.h
new file mode 100644
index 0000000000..290e6ace32
--- /dev/null
+++ b/third_party/dav1d/include/dav1d/common.h
@@ -0,0 +1,94 @@
+/*
+ * 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_COMMON_H
+#define DAV1D_COMMON_H
+
+#include <errno.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef DAV1D_API
+ #if defined _WIN32
+ #if defined DAV1D_BUILDING_DLL
+ #define DAV1D_API __declspec(dllexport)
+ #else
+ #define DAV1D_API
+ #endif
+ #else
+ #if __GNUC__ >= 4
+ #define DAV1D_API __attribute__ ((visibility ("default")))
+ #else
+ #define DAV1D_API
+ #endif
+ #endif
+#endif
+
+#if EPERM > 0
+#define DAV1D_ERR(e) (-(e)) ///< Negate POSIX error code.
+#else
+#define DAV1D_ERR(e) (e)
+#endif
+
+/**
+ * A reference-counted object wrapper for a user-configurable pointer.
+ */
+typedef struct Dav1dUserData {
+ const uint8_t *data; ///< data pointer
+ struct Dav1dRef *ref; ///< allocation origin
+} Dav1dUserData;
+
+/**
+ * Input packet metadata which are copied from the input data used to
+ * decode each image into the matching structure of the output image
+ * returned back to the user. Since these are metadata fields, they
+ * can be used for other purposes than the documented ones, they will
+ * still be passed from input data to output picture without being
+ * used internally.
+ */
+typedef struct Dav1dDataProps {
+ int64_t timestamp; ///< container timestamp of input data, INT64_MIN if unknown (default)
+ int64_t duration; ///< container duration of input data, 0 if unknown (default)
+ int64_t offset; ///< stream offset of input data, -1 if unknown (default)
+ size_t size; ///< packet size, default Dav1dData.sz
+ struct Dav1dUserData user_data; ///< user-configurable data, default NULL members
+} Dav1dDataProps;
+
+/**
+ * Release reference to a Dav1dDataProps.
+ */
+DAV1D_API void dav1d_data_props_unref(Dav1dDataProps *props);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* DAV1D_COMMON_H */
diff --git a/third_party/dav1d/include/dav1d/data.h b/third_party/dav1d/include/dav1d/data.h
new file mode 100644
index 0000000000..e551ad6506
--- /dev/null
+++ b/third_party/dav1d/include/dav1d/data.h
@@ -0,0 +1,117 @@
+/*
+ * 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_DATA_H
+#define DAV1D_DATA_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "common.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct Dav1dData {
+ const uint8_t *data; ///< data pointer
+ size_t sz; ///< data size
+ struct Dav1dRef *ref; ///< allocation origin
+ Dav1dDataProps m; ///< user provided metadata passed to the output picture
+} Dav1dData;
+
+/**
+ * Allocate data.
+ *
+ * @param data Input context.
+ * @param sz Size of the data that should be allocated.
+ *
+ * @return Pointer to the allocated buffer on success. NULL on error.
+ */
+DAV1D_API uint8_t * dav1d_data_create(Dav1dData *data, size_t sz);
+
+/**
+ * Wrap an existing data array.
+ *
+ * @param data Input context.
+ * @param buf The data to be wrapped.
+ * @param sz Size of the data.
+ * @param free_callback Function to be called when we release our last
+ * reference to this data. In this callback, $buf will be
+ * the $buf argument to this function, and $cookie will
+ * be the $cookie input argument to this function.
+ * @param cookie Opaque parameter passed to free_callback().
+ *
+ * @return 0 on success. A negative DAV1D_ERR value on error.
+ */
+DAV1D_API int dav1d_data_wrap(Dav1dData *data, const uint8_t *buf, size_t sz,
+ void (*free_callback)(const uint8_t *buf, void *cookie),
+ void *cookie);
+
+/**
+ * Wrap a user-provided data pointer into a reference counted object.
+ *
+ * data->m.user_data field will initialized to wrap the provided $user_data
+ * pointer.
+ *
+ * $free_callback will be called on the same thread that released the last
+ * reference. If frame threading is used, make sure $free_callback is
+ * thread-safe.
+ *
+ * @param data Input context.
+ * @param user_data The user data to be wrapped.
+ * @param free_callback Function to be called when we release our last
+ * reference to this data. In this callback, $user_data
+ * will be the $user_data argument to this function, and
+ * $cookie will be the $cookie input argument to this
+ * function.
+ * @param cookie Opaque parameter passed to $free_callback.
+ *
+ * @return 0 on success. A negative DAV1D_ERR value on error.
+ */
+DAV1D_API int dav1d_data_wrap_user_data(Dav1dData *data,
+ const uint8_t *user_data,
+ void (*free_callback)(const uint8_t *user_data,
+ void *cookie),
+ void *cookie);
+
+/**
+ * Free the data reference.
+ *
+ * The reference count for data->m.user_data will be decremented (if it has been
+ * initialized with dav1d_data_wrap_user_data). The $data object will be memset
+ * to 0.
+ *
+ * @param data Input context.
+ */
+DAV1D_API void dav1d_data_unref(Dav1dData *data);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* DAV1D_DATA_H */
diff --git a/third_party/dav1d/include/dav1d/dav1d.h b/third_party/dav1d/include/dav1d/dav1d.h
new file mode 100644
index 0000000000..e8f0705779
--- /dev/null
+++ b/third_party/dav1d/include/dav1d/dav1d.h
@@ -0,0 +1,329 @@
+/*
+ * Copyright © 2018-2021, 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_H
+#define DAV1D_H
+
+#include <errno.h>
+#include <stdarg.h>
+
+#include "common.h"
+#include "picture.h"
+#include "data.h"
+#include "version.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct Dav1dContext Dav1dContext;
+typedef struct Dav1dRef Dav1dRef;
+
+#define DAV1D_MAX_THREADS 256
+#define DAV1D_MAX_FRAME_DELAY 256
+
+typedef struct Dav1dLogger {
+ void *cookie; ///< Custom data to pass to the callback.
+ /**
+ * Logger callback. May be NULL to disable logging.
+ *
+ * @param cookie Custom pointer passed to all calls.
+ * @param format The vprintf compatible format string.
+ * @param ap List of arguments referenced by the format string.
+ */
+ void (*callback)(void *cookie, const char *format, va_list ap);
+} Dav1dLogger;
+
+enum Dav1dInloopFilterType {
+ DAV1D_INLOOPFILTER_NONE = 0,
+ DAV1D_INLOOPFILTER_DEBLOCK = 1 << 0,
+ DAV1D_INLOOPFILTER_CDEF = 1 << 1,
+ DAV1D_INLOOPFILTER_RESTORATION = 1 << 2,
+ DAV1D_INLOOPFILTER_ALL = DAV1D_INLOOPFILTER_DEBLOCK |
+ DAV1D_INLOOPFILTER_CDEF |
+ DAV1D_INLOOPFILTER_RESTORATION,
+};
+
+enum Dav1dDecodeFrameType {
+ DAV1D_DECODEFRAMETYPE_ALL = 0, ///< decode and return all frames
+ DAV1D_DECODEFRAMETYPE_REFERENCE = 1,///< decode and return frames referenced by other frames only
+ DAV1D_DECODEFRAMETYPE_INTRA = 2, ///< decode and return intra frames only (includes keyframes)
+ DAV1D_DECODEFRAMETYPE_KEY = 3, ///< decode and return keyframes only
+};
+
+typedef struct Dav1dSettings {
+ int n_threads; ///< number of threads (0 = number of logical cores in host system, default 0)
+ int max_frame_delay; ///< Set to 1 for low-latency decoding (0 = ceil(sqrt(n_threads)), default 0)
+ int apply_grain; ///< whether to apply film grain on output frames (default 1)
+ int operating_point; ///< select an operating point for scalable AV1 bitstreams (0 - 31, default 0)
+ int all_layers; ///< output all spatial layers of a scalable AV1 biststream (default 1)
+ unsigned frame_size_limit; ///< maximum frame size, in pixels (0 = unlimited, default 0)
+ Dav1dPicAllocator allocator; ///< Picture allocator callback.
+ Dav1dLogger logger; ///< Logger callback.
+ int strict_std_compliance; ///< whether to abort decoding on standard compliance violations
+ ///< that don't affect actual bitstream decoding (e.g. inconsistent
+ ///< or invalid metadata, default 0)
+ int output_invisible_frames; ///< output invisibly coded frames (in coding order) in addition
+ ///< to all visible frames. Because of show-existing-frame, this
+ ///< means some frames may appear twice (once when coded,
+ ///< once when shown, default 0)
+ enum Dav1dInloopFilterType inloop_filters; ///< postfilters to enable during decoding (default
+ ///< DAV1D_INLOOPFILTER_ALL)
+ enum Dav1dDecodeFrameType decode_frame_type; ///< frame types to decode (default
+ ///< DAV1D_DECODEFRAMETYPE_ALL)
+ uint8_t reserved[16]; ///< reserved for future use
+} Dav1dSettings;
+
+/**
+ * Get library version.
+ */
+DAV1D_API const char *dav1d_version(void);
+
+/**
+ * Get library API version.
+ *
+ * @return A value in the format 0x00XXYYZZ, where XX is the major version,
+ * YY the minor version, and ZZ the patch version.
+ * @see DAV1D_API_MAJOR, DAV1D_API_MINOR, DAV1D_API_PATCH
+ */
+DAV1D_API unsigned dav1d_version_api(void);
+
+/**
+ * Initialize settings to default values.
+ *
+ * @param s Input settings context.
+ */
+DAV1D_API void dav1d_default_settings(Dav1dSettings *s);
+
+/**
+ * Allocate and open a decoder instance.
+ *
+ * @param c_out The decoder instance to open. *c_out will be set to the
+ * allocated context.
+ * @param s Input settings context.
+ *
+ * @note The context must be freed using dav1d_close() when decoding is
+ * finished.
+ *
+ * @return 0 on success, or < 0 (a negative DAV1D_ERR code) on error.
+ */
+DAV1D_API int dav1d_open(Dav1dContext **c_out, const Dav1dSettings *s);
+
+/**
+ * Parse a Sequence Header OBU from bitstream data.
+ *
+ * @param out Output Sequence Header.
+ * @param buf The data to be parser.
+ * @param sz Size of the data.
+ *
+ * @return
+ * 0: Success, and out is filled with the parsed Sequence Header
+ * OBU parameters.
+ * DAV1D_ERR(ENOENT): No Sequence Header OBUs were found in the buffer.
+ * Other negative DAV1D_ERR codes: Invalid data in the buffer, invalid passed-in
+ * arguments, and other errors during parsing.
+ *
+ * @note It is safe to feed this function data containing other OBUs than a
+ * Sequence Header, as they will simply be ignored. If there is more than
+ * one Sequence Header OBU present, only the last will be returned.
+ */
+DAV1D_API int dav1d_parse_sequence_header(Dav1dSequenceHeader *out,
+ const uint8_t *buf, const size_t sz);
+
+/**
+ * Feed bitstream data to the decoder, in the form of one or multiple AV1
+ * Open Bitstream Units (OBUs).
+ *
+ * @param c Input decoder instance.
+ * @param in Input bitstream data. On success, ownership of the reference is
+ * passed to the library.
+ *
+ * @return
+ * 0: Success, and the data was consumed.
+ * DAV1D_ERR(EAGAIN): The data can't be consumed. dav1d_get_picture() should
+ * be called to get one or more frames before the function
+ * can consume new data.
+ * Other negative DAV1D_ERR codes: Error during decoding or because of invalid
+ * passed-in arguments. The reference remains
+ * owned by the caller.
+ */
+DAV1D_API int dav1d_send_data(Dav1dContext *c, Dav1dData *in);
+
+/**
+ * Return a decoded picture.
+ *
+ * @param c Input decoder instance.
+ * @param out Output frame. The caller assumes ownership of the returned
+ * reference.
+ *
+ * @return
+ * 0: Success, and a frame is returned.
+ * DAV1D_ERR(EAGAIN): Not enough data to output a frame. dav1d_send_data()
+ * should be called with new input.
+ * Other negative DAV1D_ERR codes: Error during decoding or because of invalid
+ * passed-in arguments.
+ *
+ * @note To drain buffered frames from the decoder (i.e. on end of stream),
+ * call this function until it returns DAV1D_ERR(EAGAIN).
+ *
+ * @code{.c}
+ * Dav1dData data = { 0 };
+ * Dav1dPicture p = { 0 };
+ * int res;
+ *
+ * read_data(&data);
+ * do {
+ * res = dav1d_send_data(c, &data);
+ * // Keep going even if the function can't consume the current data
+ * packet. It eventually will after one or more frames have been
+ * returned in this loop.
+ * if (res < 0 && res != DAV1D_ERR(EAGAIN))
+ * free_and_abort();
+ * res = dav1d_get_picture(c, &p);
+ * if (res < 0) {
+ * if (res != DAV1D_ERR(EAGAIN))
+ * free_and_abort();
+ * } else
+ * output_and_unref_picture(&p);
+ * // Stay in the loop as long as there's data to consume.
+ * } while (data.sz || read_data(&data) == SUCCESS);
+ *
+ * // Handle EOS by draining all buffered frames.
+ * do {
+ * res = dav1d_get_picture(c, &p);
+ * if (res < 0) {
+ * if (res != DAV1D_ERR(EAGAIN))
+ * free_and_abort();
+ * } else
+ * output_and_unref_picture(&p);
+ * } while (res == 0);
+ * @endcode
+ */
+DAV1D_API int dav1d_get_picture(Dav1dContext *c, Dav1dPicture *out);
+
+/**
+ * Apply film grain to a previously decoded picture. If the picture contains no
+ * film grain metadata, then this function merely returns a new reference.
+ *
+ * @param c Input decoder instance.
+ * @param out Output frame. The caller assumes ownership of the returned
+ * reference.
+ * @param in Input frame. No ownership is transferred.
+ *
+ * @return
+ * 0: Success, and a frame is returned.
+ * Other negative DAV1D_ERR codes: Error due to lack of memory or because of
+ * invalid passed-in arguments.
+ *
+ * @note If `Dav1dSettings.apply_grain` is true, film grain was already applied
+ * by `dav1d_get_picture`, and so calling this function leads to double
+ * application of film grain. Users should only call this when needed.
+ */
+DAV1D_API int dav1d_apply_grain(Dav1dContext *c, Dav1dPicture *out,
+ const Dav1dPicture *in);
+
+/**
+ * Close a decoder instance and free all associated memory.
+ *
+ * @param c_out The decoder instance to close. *c_out will be set to NULL.
+ */
+DAV1D_API void dav1d_close(Dav1dContext **c_out);
+
+/**
+ * Flush all delayed frames in decoder and clear internal decoder state,
+ * to be used when seeking.
+ *
+ * @param c Input decoder instance.
+ *
+ * @note Decoding will start only after a valid sequence header OBU is
+ * delivered to dav1d_send_data().
+ *
+ */
+DAV1D_API void dav1d_flush(Dav1dContext *c);
+
+enum Dav1dEventFlags {
+ /**
+ * The last returned picture contains a reference to a new Sequence Header,
+ * either because it's the start of a new coded sequence, or the decoder was
+ * flushed before it was generated.
+ */
+ DAV1D_EVENT_FLAG_NEW_SEQUENCE = 1 << 0,
+ /**
+ * The last returned picture contains a reference to a Sequence Header with
+ * new operating parameters information for the current coded sequence.
+ */
+ DAV1D_EVENT_FLAG_NEW_OP_PARAMS_INFO = 1 << 1,
+};
+
+/**
+ * Fetch a combination of DAV1D_EVENT_FLAG_* event flags generated by the decoding
+ * process.
+ *
+ * @param c Input decoder instance.
+ * @param flags Where to write the flags.
+ *
+ * @return 0 on success, or < 0 (a negative DAV1D_ERR code) on error.
+ *
+ * @note Calling this function will clear all the event flags currently stored in
+ * the decoder.
+ *
+ */
+DAV1D_API int dav1d_get_event_flags(Dav1dContext *c, enum Dav1dEventFlags *flags);
+
+/**
+ * Retrieve the user-provided metadata associated with the input data packet
+ * for the last decoding error reported to the user, i.e. a negative return
+ * value (not EAGAIN) from dav1d_send_data() or dav1d_get_picture().
+ *
+ * @param c Input decoder instance.
+ * @param out Output Dav1dDataProps. On success, the caller assumes ownership of
+ * the returned reference.
+ *
+ * @return 0 on success, or < 0 (a negative DAV1D_ERR code) on error.
+ */
+DAV1D_API int dav1d_get_decode_error_data_props(Dav1dContext *c, Dav1dDataProps *out);
+
+/**
+ * Get the decoder delay, which is the number of internally buffered frames, not
+ * including reference frames.
+ * This value is guaranteed to be >= 1 and <= max_frame_delay.
+ *
+ * @param s Input settings context.
+ *
+ * @return Decoder frame delay on success, or < 0 (a negative DAV1D_ERR code) on
+ * error.
+ *
+ * @note The returned delay is valid only for a Dav1dContext initialized with the
+ * provided Dav1dSettings.
+ */
+DAV1D_API int dav1d_get_frame_delay(const Dav1dSettings *s);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* DAV1D_H */
diff --git a/third_party/dav1d/include/dav1d/headers.h b/third_party/dav1d/include/dav1d/headers.h
new file mode 100644
index 0000000000..b9037f23de
--- /dev/null
+++ b/third_party/dav1d/include/dav1d/headers.h
@@ -0,0 +1,444 @@
+/*
+ * Copyright © 2018-2020, 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
+
+#include <stdint.h>
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Constants from Section 3. "Symbols and abbreviated terms"
+#define DAV1D_MAX_CDEF_STRENGTHS 8
+#define DAV1D_MAX_OPERATING_POINTS 32
+#define DAV1D_MAX_TILE_COLS 64
+#define DAV1D_MAX_TILE_ROWS 64
+#define DAV1D_MAX_SEGMENTS 8
+#define DAV1D_NUM_REF_FRAMES 8
+#define DAV1D_PRIMARY_REF_NONE 7
+#define DAV1D_REFS_PER_FRAME 7
+#define DAV1D_TOTAL_REFS_PER_FRAME (DAV1D_REFS_PER_FRAME + 1)
+
+enum Dav1dObuType {
+ DAV1D_OBU_SEQ_HDR = 1,
+ DAV1D_OBU_TD = 2,
+ DAV1D_OBU_FRAME_HDR = 3,
+ DAV1D_OBU_TILE_GRP = 4,
+ DAV1D_OBU_METADATA = 5,
+ DAV1D_OBU_FRAME = 6,
+ DAV1D_OBU_REDUNDANT_FRAME_HDR = 7,
+ DAV1D_OBU_PADDING = 15,
+};
+
+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;
+ } p;
+ int16_t abcd[4];
+ } u;
+} 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,
+ DAV1D_COLOR_PRI_RESERVED = 255,
+};
+
+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)
+ DAV1D_TRC_RESERVED = 255,
+};
+
+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,
+ DAV1D_MC_RESERVED = 255,
+};
+
+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 Dav1dContentLightLevel {
+ uint16_t max_content_light_level;
+ uint16_t max_frame_average_light_level;
+} Dav1dContentLightLevel;
+
+typedef struct Dav1dMasteringDisplay {
+ ///< 0.16 fixed point
+ uint16_t primaries[3][2];
+ ///< 0.16 fixed point
+ uint16_t white_point[2];
+ ///< 24.8 fixed point
+ uint32_t max_luminance;
+ ///< 18.14 fixed point
+ uint32_t min_luminance;
+} Dav1dMasteringDisplay;
+
+typedef struct Dav1dITUTT35 {
+ uint8_t country_code;
+ uint8_t country_code_extension_byte;
+ size_t payload_size;
+ uint8_t *payload;
+} Dav1dITUTT35;
+
+typedef struct Dav1dSequenceHeader {
+ /**
+ * Stream profile, 0 for 8-10 bits/component 4:2:0 or monochrome;
+ * 1 for 8-10 bits/component 4:4:4; 2 for 4:2:2 at any bits/component,
+ * or 12 bits/component at any chroma subsampling.
+ */
+ uint8_t profile;
+ /**
+ * Maximum dimensions for this stream. In non-scalable streams, these
+ * are often the actual dimensions of the stream, although that is not
+ * a normative requirement.
+ */
+ int max_width, max_height;
+ enum Dav1dPixelLayout layout; ///< format of the picture
+ enum Dav1dColorPrimaries pri; ///< color primaries (av1)
+ enum Dav1dTransferCharacteristics trc; ///< transfer characteristics (av1)
+ enum Dav1dMatrixCoefficients mtrx; ///< matrix coefficients (av1)
+ enum Dav1dChromaSamplePosition chr; ///< chroma sample position (av1)
+ /**
+ * 0, 1 and 2 mean 8, 10 or 12 bits/component, respectively. This is not
+ * exactly the same as 'hbd' from the spec; the spec's hbd distinguishes
+ * between 8 (0) and 10-12 (1) bits/component, and another element
+ * (twelve_bit) to distinguish between 10 and 12 bits/component. To get
+ * the spec's hbd, use !!our_hbd, and to get twelve_bit, use hbd == 2.
+ */
+ uint8_t hbd;
+ /**
+ * Pixel data uses JPEG pixel range ([0,255] for 8bits) instead of
+ * MPEG pixel range ([16,235] for 8bits luma, [16,240] for 8bits chroma).
+ */
+ uint8_t color_range;
+
+ uint8_t num_operating_points;
+ struct Dav1dSequenceHeaderOperatingPoint {
+ uint8_t major_level, minor_level;
+ uint8_t initial_display_delay;
+ uint16_t idc;
+ uint8_t tier;
+ uint8_t decoder_model_param_present;
+ uint8_t display_model_param_present;
+ } operating_points[DAV1D_MAX_OPERATING_POINTS];
+
+ uint8_t still_picture;
+ uint8_t reduced_still_picture_header;
+ uint8_t timing_info_present;
+ uint32_t num_units_in_tick;
+ uint32_t time_scale;
+ uint8_t equal_picture_interval;
+ uint32_t num_ticks_per_picture;
+ uint8_t decoder_model_info_present;
+ uint8_t encoder_decoder_buffer_delay_length;
+ uint32_t num_units_in_decoding_tick;
+ uint8_t buffer_removal_delay_length;
+ uint8_t frame_presentation_delay_length;
+ uint8_t display_model_info_present;
+ uint8_t width_n_bits, height_n_bits;
+ uint8_t frame_id_numbers_present;
+ uint8_t delta_frame_id_n_bits;
+ uint8_t frame_id_n_bits;
+ uint8_t sb128;
+ uint8_t filter_intra;
+ uint8_t intra_edge_filter;
+ uint8_t inter_intra;
+ uint8_t masked_compound;
+ uint8_t warped_motion;
+ uint8_t dual_filter;
+ uint8_t order_hint;
+ uint8_t jnt_comp;
+ uint8_t ref_frame_mvs;
+ enum Dav1dAdaptiveBoolean screen_content_tools;
+ enum Dav1dAdaptiveBoolean force_integer_mv;
+ uint8_t order_hint_n_bits;
+ uint8_t super_res;
+ uint8_t cdef;
+ uint8_t restoration;
+ uint8_t ss_hor, ss_ver, monochrome;
+ uint8_t color_description_present;
+ uint8_t separate_uv_delta_q;
+ uint8_t film_grain_present;
+
+ // Dav1dSequenceHeaders of the same sequence are required to be
+ // bit-identical until this offset. See 7.5 "Ordering of OBUs":
+ // Within a particular coded video sequence, the contents of
+ // sequence_header_obu must be bit-identical each time the
+ // sequence header appears except for the contents of
+ // operating_parameters_info.
+ struct Dav1dSequenceHeaderOperatingParameterInfo {
+ uint32_t decoder_buffer_delay;
+ uint32_t encoder_buffer_delay;
+ uint8_t low_delay_mode;
+ } operating_parameter_info[DAV1D_MAX_OPERATING_POINTS];
+} Dav1dSequenceHeader;
+
+typedef struct Dav1dSegmentationData {
+ int16_t delta_q;
+ int8_t delta_lf_y_v, delta_lf_y_h, delta_lf_u, delta_lf_v;
+ int8_t ref;
+ uint8_t skip;
+ uint8_t globalmv;
+} Dav1dSegmentationData;
+
+typedef struct Dav1dSegmentationDataSet {
+ Dav1dSegmentationData d[DAV1D_MAX_SEGMENTS];
+ uint8_t preskip;
+ int8_t last_active_segid;
+} Dav1dSegmentationDataSet;
+
+typedef struct Dav1dLoopfilterModeRefDeltas {
+ int8_t mode_delta[2 /* is_zeromv */];
+ int8_t ref_delta[DAV1D_TOTAL_REFS_PER_FRAME];
+} Dav1dLoopfilterModeRefDeltas;
+
+typedef struct Dav1dFilmGrainData {
+ unsigned 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 + 3 /* padding for alignment purposes */];
+ uint64_t 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 {
+ struct {
+ Dav1dFilmGrainData data;
+ uint8_t present, update;
+ } film_grain; ///< film grain parameters
+ enum Dav1dFrameType frame_type; ///< type of the picture
+ int width[2 /* { coded_width, superresolution_upscaled_width } */], height;
+ uint8_t frame_offset; ///< frame number
+ uint8_t temporal_id; ///< temporal id of the frame for SVC
+ uint8_t spatial_id; ///< spatial id of the frame for SVC
+
+ uint8_t show_existing_frame;
+ uint8_t existing_frame_idx;
+ uint32_t frame_id;
+ uint32_t frame_presentation_delay;
+ uint8_t show_frame;
+ uint8_t showable_frame;
+ uint8_t error_resilient_mode;
+ uint8_t disable_cdf_update;
+ uint8_t allow_screen_content_tools;
+ uint8_t force_integer_mv;
+ uint8_t frame_size_override;
+ uint8_t primary_ref_frame;
+ uint8_t buffer_removal_time_present;
+ struct Dav1dFrameHeaderOperatingPoint {
+ uint32_t buffer_removal_time;
+ } operating_points[DAV1D_MAX_OPERATING_POINTS];
+ uint8_t refresh_frame_flags;
+ int render_width, render_height;
+ struct {
+ uint8_t width_scale_denominator;
+ uint8_t enabled;
+ } super_res;
+ uint8_t have_render_size;
+ uint8_t allow_intrabc;
+ uint8_t frame_ref_short_signaling;
+ int8_t refidx[DAV1D_REFS_PER_FRAME];
+ uint8_t hp;
+ enum Dav1dFilterMode subpel_filter_mode;
+ uint8_t switchable_motion_mode;
+ uint8_t use_ref_frame_mvs;
+ uint8_t refresh_context;
+ struct {
+ uint8_t uniform;
+ uint8_t n_bytes;
+ uint8_t min_log2_cols, max_log2_cols, log2_cols, cols;
+ uint8_t 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];
+ uint16_t update;
+ } tiling;
+ struct {
+ uint8_t yac;
+ int8_t ydc_delta;
+ int8_t udc_delta, uac_delta, vdc_delta, vac_delta;
+ uint8_t qm, qm_y, qm_u, qm_v;
+ } quant;
+ struct {
+ uint8_t enabled, update_map, temporal, update_data;
+ Dav1dSegmentationDataSet seg_data;
+ uint8_t lossless[DAV1D_MAX_SEGMENTS], qidx[DAV1D_MAX_SEGMENTS];
+ } segmentation;
+ struct {
+ struct {
+ uint8_t present;
+ uint8_t res_log2;
+ } q;
+ struct {
+ uint8_t present;
+ uint8_t res_log2;
+ uint8_t multi;
+ } lf;
+ } delta;
+ uint8_t all_lossless;
+ struct {
+ uint8_t level_y[2 /* dir */];
+ uint8_t level_u, level_v;
+ uint8_t mode_ref_delta_enabled;
+ uint8_t mode_ref_delta_update;
+ Dav1dLoopfilterModeRefDeltas mode_ref_deltas;
+ uint8_t sharpness;
+ } loopfilter;
+ struct {
+ uint8_t damping;
+ uint8_t n_bits;
+ uint8_t y_strength[DAV1D_MAX_CDEF_STRENGTHS];
+ uint8_t uv_strength[DAV1D_MAX_CDEF_STRENGTHS];
+ } cdef;
+ struct {
+ enum Dav1dRestorationType type[3 /* plane */];
+ uint8_t unit_size[2 /* y, uv */];
+ } restoration;
+ enum Dav1dTxfmMode txfm_mode;
+ uint8_t switchable_comp_refs;
+ uint8_t skip_mode_allowed, skip_mode_enabled;
+ int8_t skip_mode_refs[2];
+ uint8_t warp_motion;
+ uint8_t reduced_txtp_set;
+ Dav1dWarpedMotionParams gmv[DAV1D_REFS_PER_FRAME];
+} Dav1dFrameHeader;
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* DAV1D_HEADERS_H */
diff --git a/third_party/dav1d/include/dav1d/meson.build b/third_party/dav1d/include/dav1d/meson.build
new file mode 100644
index 0000000000..68faaf9a36
--- /dev/null
+++ b/third_party/dav1d/include/dav1d/meson.build
@@ -0,0 +1,45 @@
+# Copyright © 2019, VideoLAN and dav1d authors
+# 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.
+
+# installed version.h header generation
+version_h_data = configuration_data()
+version_h_data.set('DAV1D_API_VERSION_MAJOR', dav1d_api_version_major)
+version_h_data.set('DAV1D_API_VERSION_MINOR', dav1d_api_version_minor)
+version_h_data.set('DAV1D_API_VERSION_PATCH', dav1d_api_version_revision)
+version_h_target = configure_file(input: 'version.h.in',
+ output: 'version.h',
+ configuration: version_h_data)
+
+dav1d_api_headers = [
+ 'common.h',
+ 'data.h',
+ 'dav1d.h',
+ 'headers.h',
+ 'picture.h',
+]
+
+# install headers
+install_headers(dav1d_api_headers,
+ version_h_target,
+ subdir : 'dav1d')
diff --git a/third_party/dav1d/include/dav1d/picture.h b/third_party/dav1d/include/dav1d/picture.h
new file mode 100644
index 0000000000..cc291a4abb
--- /dev/null
+++ b/third_party/dav1d/include/dav1d/picture.h
@@ -0,0 +1,157 @@
+/*
+ * Copyright © 2018-2020, 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_PICTURE_H
+#define DAV1D_PICTURE_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "common.h"
+#include "headers.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Number of bytes to align AND pad picture memory buffers by, so that SIMD
+ * implementations can over-read by a few bytes, and use aligned read/write
+ * instructions. */
+#define DAV1D_PICTURE_ALIGNMENT 64
+
+typedef struct Dav1dPictureParameters {
+ int w; ///< width (in pixels)
+ int h; ///< height (in pixels)
+ enum Dav1dPixelLayout layout; ///< format of the picture
+ int bpc; ///< bits per pixel component (8 or 10)
+} Dav1dPictureParameters;
+
+typedef struct Dav1dPicture {
+ Dav1dSequenceHeader *seq_hdr;
+ Dav1dFrameHeader *frame_hdr;
+
+ /**
+ * Pointers to planar image data (Y is [0], U is [1], V is [2]). The data
+ * should be bytes (for 8 bpc) or words (for 10 bpc). In case of words
+ * containing 10 bpc image data, the pixels should be located in the LSB
+ * bits, so that values range between [0, 1023]; the upper bits should be
+ * zero'ed out.
+ */
+ void *data[3];
+
+ /**
+ * Number of bytes between 2 lines in data[] for luma [0] or chroma [1].
+ */
+ ptrdiff_t stride[2];
+
+ Dav1dPictureParameters p;
+ Dav1dDataProps m;
+
+ /**
+ * High Dynamic Range Content Light Level metadata applying to this picture,
+ * as defined in section 5.8.3 and 6.7.3
+ */
+ Dav1dContentLightLevel *content_light;
+ /**
+ * High Dynamic Range Mastering Display Color Volume metadata applying to
+ * this picture, as defined in section 5.8.4 and 6.7.4
+ */
+ Dav1dMasteringDisplay *mastering_display;
+ /**
+ * Array of ITU-T T.35 metadata as defined in section 5.8.2 and 6.7.2
+ */
+ Dav1dITUTT35 *itut_t35;
+
+ /**
+ * Number of ITU-T T35 metadata entries in the array
+ */
+ size_t n_itut_t35;
+
+ uintptr_t reserved[4]; ///< reserved for future use
+
+ struct Dav1dRef *frame_hdr_ref; ///< Dav1dFrameHeader allocation origin
+ struct Dav1dRef *seq_hdr_ref; ///< Dav1dSequenceHeader allocation origin
+ struct Dav1dRef *content_light_ref; ///< Dav1dContentLightLevel allocation origin
+ struct Dav1dRef *mastering_display_ref; ///< Dav1dMasteringDisplay allocation origin
+ struct Dav1dRef *itut_t35_ref; ///< Dav1dITUTT35 allocation origin
+ uintptr_t reserved_ref[4]; ///< reserved for future use
+ struct Dav1dRef *ref; ///< Frame data allocation origin
+
+ void *allocator_data; ///< pointer managed by the allocator
+} Dav1dPicture;
+
+typedef struct Dav1dPicAllocator {
+ void *cookie; ///< custom data to pass to the allocator callbacks.
+ /**
+ * Allocate the picture buffer based on the Dav1dPictureParameters.
+ *
+ * The data[0], data[1] and data[2] must be DAV1D_PICTURE_ALIGNMENT byte
+ * aligned and with a pixel width/height multiple of 128 pixels. Any
+ * allocated memory area should also be padded by DAV1D_PICTURE_ALIGNMENT
+ * bytes.
+ * data[1] and data[2] must share the same stride[1].
+ *
+ * This function will be called on the main thread (the thread which calls
+ * dav1d_get_picture()).
+ *
+ * @param pic The picture to allocate the buffer for. The callback needs to
+ * fill the picture data[0], data[1], data[2], stride[0] and
+ * stride[1].
+ * The allocator can fill the pic allocator_data pointer with
+ * a custom pointer that will be passed to
+ * release_picture_callback().
+ * @param cookie Custom pointer passed to all calls.
+ *
+ * @note No fields other than data, stride and allocator_data must be filled
+ * by this callback.
+ * @return 0 on success. A negative DAV1D_ERR value on error.
+ */
+ int (*alloc_picture_callback)(Dav1dPicture *pic, void *cookie);
+ /**
+ * Release the picture buffer.
+ *
+ * If frame threading is used, this function may be called by the main
+ * thread (the thread which calls dav1d_get_picture()) or any of the frame
+ * threads and thus must be thread-safe. If frame threading is not used,
+ * this function will only be called on the main thread.
+ *
+ * @param pic The picture that was filled by alloc_picture_callback().
+ * @param cookie Custom pointer passed to all calls.
+ */
+ void (*release_picture_callback)(Dav1dPicture *pic, void *cookie);
+} Dav1dPicAllocator;
+
+/**
+ * Release reference to a picture.
+ */
+DAV1D_API void dav1d_picture_unref(Dav1dPicture *p);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* DAV1D_PICTURE_H */
diff --git a/third_party/dav1d/include/dav1d/version.h.in b/third_party/dav1d/include/dav1d/version.h.in
new file mode 100644
index 0000000000..4fa420ded3
--- /dev/null
+++ b/third_party/dav1d/include/dav1d/version.h.in
@@ -0,0 +1,50 @@
+/*
+ * Copyright © 2019, VideoLAN and dav1d authors
+ * 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_VERSION_H
+#define DAV1D_VERSION_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define DAV1D_API_VERSION_MAJOR @DAV1D_API_VERSION_MAJOR@
+#define DAV1D_API_VERSION_MINOR @DAV1D_API_VERSION_MINOR@
+#define DAV1D_API_VERSION_PATCH @DAV1D_API_VERSION_PATCH@
+
+/**
+ * Extract version components from the value returned by
+ * dav1d_version_int()
+ */
+#define DAV1D_API_MAJOR(v) (((v) >> 16) & 0xFF)
+#define DAV1D_API_MINOR(v) (((v) >> 8) & 0xFF)
+#define DAV1D_API_PATCH(v) (((v) >> 0) & 0xFF)
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* DAV1D_VERSION_H */
diff --git a/third_party/dav1d/include/meson.build b/third_party/dav1d/include/meson.build
new file mode 100644
index 0000000000..e5971840c2
--- /dev/null
+++ b/third_party/dav1d/include/meson.build
@@ -0,0 +1,34 @@
+# Copyright © 2018, VideoLAN and dav1d authors
+# 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.
+
+# Revision file (vcs_version.h) generation
+dav1d_git_dir = join_paths(dav1d_src_root, '.git')
+rev_target = vcs_tag(command: [
+ 'git', '--git-dir', dav1d_git_dir, 'describe', '--long', '--always'
+ ],
+ input: 'vcs_version.h.in',
+ output: 'vcs_version.h'
+)
+
+subdir('dav1d')
diff --git a/third_party/dav1d/include/vcs_version.h.in b/third_party/dav1d/include/vcs_version.h.in
new file mode 100644
index 0000000000..71ed2f6982
--- /dev/null
+++ b/third_party/dav1d/include/vcs_version.h.in
@@ -0,0 +1,2 @@
+/* auto-generated, do not edit */
+#define DAV1D_VERSION "@VCS_TAG@"