diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/dav1d/include/common | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/dav1d/include/common')
-rw-r--r-- | third_party/dav1d/include/common/attributes.h | 199 | ||||
-rw-r--r-- | third_party/dav1d/include/common/bitdepth.h | 93 | ||||
-rw-r--r-- | third_party/dav1d/include/common/dump.h | 92 | ||||
-rw-r--r-- | third_party/dav1d/include/common/frame.h | 45 | ||||
-rw-r--r-- | third_party/dav1d/include/common/intops.h | 84 | ||||
-rw-r--r-- | third_party/dav1d/include/common/validate.h | 59 |
6 files changed, 572 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..2af42ef78b --- /dev/null +++ b/third_party/dav1d/include/common/attributes.h @@ -0,0 +1,199 @@ +/* + * 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)) +#define ATTR_FORMAT_PRINTF(fmt, attr) __attribute__((__format__(__printf__, fmt, attr))) +#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_X86_32 || ARCH_ARM || ARCH_AARCH64 || ARCH_PPC64LE +/* 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..88a822aab2 --- /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 void pixel; +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..3096f3db8e --- /dev/null +++ b/third_party/dav1d/include/common/validate.h @@ -0,0 +1,59 @@ +/* + * 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_abort() +#else +#define debug_abort abort +#endif + +#define validate_input_or_ret_with_msg(x, r, ...) \ + if (!(x)) { \ + fprintf(stderr, "Input validation check \'%s\' failed in %s!\n", \ + #x, __func__); \ + fprintf(stderr, __VA_ARGS__); \ + debug_abort(); \ + return r; \ + } + +#define validate_input_or_ret(x, r) \ + if (!(x)) { \ + fprintf(stderr, "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 */ |