[FFmpeg-devel] [PATCH 09/19] swscale/internal: use static_assert for enforcing offsets
Niklas Haas
ffmpeg at haasn.xyz
Fri Oct 11 01:26:56 EEST 2024
From: Niklas Haas <git at haasn.dev>
Instead of sprinkling av_assert0 into random init functions.
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git at haasn.dev>
---
libswscale/swscale_internal.h | 9 +++++++++
libswscale/utils.c | 3 ++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index 1817815b01..9b346c4fd9 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -22,6 +22,7 @@
#define SWSCALE_SWSCALE_INTERNAL_H
#include <stdatomic.h>
+#include <assert.h>
#include "config.h"
#include "swscale.h"
@@ -704,6 +705,14 @@ struct SwsInternal {
};
//FIXME check init (where 0)
+static_assert(offsetof(SwsInternal, redDither) + DITHER32_INT == offsetof(SwsInternal, dither32),
+ "dither32 must be at the same offset as redDither + DITHER32_INT");
+
+/* x86 yuv2gbrp uses the SwsInternal for yuv coefficients
+ if struct offsets change the asm needs to be updated too */
+static_assert(offsetof(SwsInternal, yuv2rgb_y_offset) == 40292,
+ "yuv2rgb_y_offset must be updated in x86 asm");
+
SwsFunc ff_yuv2rgb_get_func_ptr(SwsInternal *c);
int ff_yuv2rgb_c_init_tables(SwsInternal *c, const int inv_table[4],
int fullRange, int brightness,
diff --git a/libswscale/utils.c b/libswscale/utils.c
index 01fe474020..f5833548a7 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -1227,7 +1227,8 @@ SwsContext *sws_alloc_context(void)
{
SwsInternal *c = av_mallocz(sizeof(SwsInternal));
- av_assert0(offsetof(SwsInternal, redDither) + DITHER32_INT == offsetof(SwsInternal, dither32));
+ static_assert(offsetof(SwsInternal, redDither) + DITHER32_INT == offsetof(SwsInternal, dither32),
+ "dither32 must be at the same offset as redDither + DITHER32_INT");
if (c) {
c->av_class = &ff_sws_context_class;
--
2.46.1
More information about the ffmpeg-devel
mailing list