[FFmpeg-cvslog] swscale/internal: use static_assert for enforcing offsets
Niklas Haas
git at videolan.org
Thu Nov 21 13:53:57 EET 2024
ffmpeg | branch: master | Niklas Haas <git at haasn.dev> | Thu Oct 10 11:57:44 2024 +0200| [10d1be262126f1699a89b54cf5f23a5370c57cb5] | committer: Niklas Haas
swscale/internal: use static_assert for enforcing offsets
Instead of sprinkling av_assert0 into random init functions.
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git at haasn.dev>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=10d1be262126f1699a89b54cf5f23a5370c57cb5
---
libswscale/swscale_internal.h | 11 +++++++++++
libswscale/utils.c | 2 --
libswscale/x86/swscale.c | 4 ----
3 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index 0035168997..0ab4e67270 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"
@@ -705,6 +706,16 @@ 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");
+
+#if ARCH_X86_64
+/* 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");
+#endif
+
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 5c21f9de4a..f71c63c17f 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -1228,8 +1228,6 @@ SwsContext *sws_alloc_context(void)
{
SwsInternal *c = av_mallocz(sizeof(SwsInternal));
- av_assert0(offsetof(SwsInternal, redDither) + DITHER32_INT == offsetof(SwsInternal, dither32));
-
if (c) {
c->av_class = &ff_sws_context_class;
av_opt_set_defaults(c);
diff --git a/libswscale/x86/swscale.c b/libswscale/x86/swscale.c
index ceafdf4aef..40bfe4a2f6 100644
--- a/libswscale/x86/swscale.c
+++ b/libswscale/x86/swscale.c
@@ -791,10 +791,6 @@ switch(c->dstBpc){ \
if(c->flags & SWS_FULL_CHR_H_INT) {
- /* yuv2gbrp uses the SwsInternal for yuv coefficients
- if struct offsets change the asm needs to be updated too */
- av_assert0(offsetof(SwsInternal, yuv2rgb_y_offset) == 40292);
-
#define YUV2ANYX_FUNC_CASE(fmt, name, opt) \
case fmt: \
c->yuv2anyX = ff_yuv2##name##_full_X_##opt; \
More information about the ffmpeg-cvslog
mailing list