[MPlayer-dev-eng] [PATCH] Fix dependencies on libavutil/mem_internal.h

Reimar Döffinger Reimar.Doeffinger at gmx.de
Sun Feb 7 13:04:08 EET 2021


Especially relevant once DECLARE_ALIGNED will be removed
from mem.h.
While keeping our own copy is a bit ugly and wasteful, it
seems like the best option overall, even if I'd prefer
that mem_internal functionality was instead available
to users of FFmpeg.
---
 libmpcodecs/vf_filmdint.c |  1 +
 libmpcodecs/vf_fspp.c     |  2 +-
 libmpcodecs/vf_gradfun.c  |  2 +-
 libmpcodecs/vf_ow.c       |  2 +-
 libmpcodecs/vf_pp7.c      |  1 +
 libmpcodecs/vf_spp.c      |  2 +-
 libmpcodecs/vf_uspp.c     |  2 +-
 m_config.h                |  2 +-
 mpmem.h                   | 89 +++++++++++++++++++++++++++++++++++++++
 sub/osd.c                 |  2 +-
 10 files changed, 98 insertions(+), 7 deletions(-)
 create mode 100644 mpmem.h

diff --git a/libmpcodecs/vf_filmdint.c b/libmpcodecs/vf_filmdint.c
index 3adb76f9f..aaeeaf168 100644
--- a/libmpcodecs/vf_filmdint.c
+++ b/libmpcodecs/vf_filmdint.c
@@ -24,6 +24,7 @@
 #include "mp_msg.h"
 #include "cpudetect.h"
 #include "osdep/timer.h"
+#include "mpmem.h"

 #include "img_format.h"
 #include "mp_image.h"
diff --git a/libmpcodecs/vf_fspp.c b/libmpcodecs/vf_fspp.c
index 9bb967710..f9c4c693d 100644
--- a/libmpcodecs/vf_fspp.c
+++ b/libmpcodecs/vf_fspp.c
@@ -50,7 +50,7 @@

 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
-#include "libavutil/mem.h"
+#include "mpmem.h"
 #include "mpx86asm.h"
 #include "libavcodec/avcodec.h"

diff --git a/libmpcodecs/vf_gradfun.c b/libmpcodecs/vf_gradfun.c
index 5e451cf12..472080bb2 100644
--- a/libmpcodecs/vf_gradfun.c
+++ b/libmpcodecs/vf_gradfun.c
@@ -40,7 +40,7 @@
 #include "libvo/fastmemcpy.h"
 #include "libavutil/avutil.h"
 #include "libavutil/common.h"
-#include "libavutil/mem.h"
+#include "mpmem.h"
 #include "mpx86asm.h"

 struct vf_priv_s {
diff --git a/libmpcodecs/vf_ow.c b/libmpcodecs/vf_ow.c
index af4bdbc2c..23295b770 100644
--- a/libmpcodecs/vf_ow.c
+++ b/libmpcodecs/vf_ow.c
@@ -32,7 +32,7 @@
 #include <inttypes.h>
 #include <math.h>

-#include "libavutil/mem_internal.h"
+#include "mpmem.h"
 #include "mp_msg.h"
 #include "img_format.h"
 #include "mp_image.h"
diff --git a/libmpcodecs/vf_pp7.c b/libmpcodecs/vf_pp7.c
index 6d6963db6..3a0422a0e 100644
--- a/libmpcodecs/vf_pp7.c
+++ b/libmpcodecs/vf_pp7.c
@@ -35,6 +35,7 @@
 #endif

 #include "libavutil/mem.h"
+#include "mpmem.h"

 #include "img_format.h"
 #include "mp_image.h"
diff --git a/libmpcodecs/vf_spp.c b/libmpcodecs/vf_spp.c
index 84b467286..59c71bb94 100644
--- a/libmpcodecs/vf_spp.c
+++ b/libmpcodecs/vf_spp.c
@@ -34,12 +34,12 @@

 #include "config.h"

+#include "mpmem.h"
 #include "mp_msg.h"
 #include "cpudetect.h"

 #include "libavutil/common.h"
 #include "libavutil/internal.h"
-#include "libavutil/mem_internal.h"
 #include "libavutil/intreadwrite.h"
 #include "libavcodec/avcodec.h"
 #include "libavcodec/pixblockdsp.h"
diff --git a/libmpcodecs/vf_uspp.c b/libmpcodecs/vf_uspp.c
index 851f16a31..786a46596 100644
--- a/libmpcodecs/vf_uspp.c
+++ b/libmpcodecs/vf_uspp.c
@@ -30,7 +30,7 @@
 #include "mp_msg.h"
 #include "cpudetect.h"

-#include "libavutil/mem.h"
+#include "mpmem.h"
 #include "libavcodec/avcodec.h"

 #include "img_format.h"
diff --git a/m_config.h b/m_config.h
index 293717be5..553d2396d 100644
--- a/m_config.h
+++ b/m_config.h
@@ -19,7 +19,7 @@
 #ifndef MPLAYER_M_CONFIG_H
 #define MPLAYER_M_CONFIG_H

-#include "libavutil/mem_internal.h"
+#include "mpmem.h"

 /// \defgroup Config Config manager
 ///
diff --git a/mpmem.h b/mpmem.h
new file mode 100644
index 000000000..4f61c4d74
--- /dev/null
+++ b/mpmem.h
@@ -0,0 +1,89 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MPlayer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPLAYER_MPMEM_H
+#define MPLAYER_MPMEM_H
+
+// copy of libavutil/mem_internal.h code for the
+// benefit of compiling against shared FFmpeg libs
+
+#include "config.h"
+
+#ifndef DECLARE_ALIGNED
+#if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
+    #define DECLARE_ALIGNED(n,t,v)      t __attribute__ ((aligned (n))) v
+    #define DECLARE_ASM_ALIGNED(n,t,v)  t __attribute__ ((aligned (n))) v
+    #define DECLARE_ASM_CONST(n,t,v)    const t __attribute__ ((aligned (n))) v
+#elif defined(__DJGPP__)
+    #define DECLARE_ALIGNED(n,t,v)      t __attribute__ ((aligned (FFMIN(n, 16)))) v
+    #define DECLARE_ASM_ALIGNED(n,t,v)  t av_used __attribute__ ((aligned (FFMIN(n, 16)))) v
+    #define DECLARE_ASM_CONST(n,t,v)    static const t av_used __attribute__ ((aligned (FFMIN(n, 16)))) v
+#elif defined(__GNUC__) || defined(__clang__)
+    #define DECLARE_ALIGNED(n,t,v)      t __attribute__ ((aligned (n))) v
+    #define DECLARE_ASM_ALIGNED(n,t,v)  t av_used __attribute__ ((aligned (n))) v
+    #define DECLARE_ASM_CONST(n,t,v)    static const t av_used __attribute__ ((aligned (n))) v
+#elif defined(_MSC_VER)
+    #define DECLARE_ALIGNED(n,t,v)      __declspec(align(n)) t v
+    #define DECLARE_ASM_ALIGNED(n,t,v)  __declspec(align(n)) t v
+    #define DECLARE_ASM_CONST(n,t,v)    __declspec(align(n)) static const t v
+#else
+    #define DECLARE_ALIGNED(n,t,v)      t v
+    #define DECLARE_ASM_ALIGNED(n,t,v)  t v
+    #define DECLARE_ASM_CONST(n,t,v)    static const t v
+#endif
+#endif
+
+// Some broken preprocessors need a second expansion
+// to be forced to tokenize __VA_ARGS__
+#define E1(x) x
+
+#define LOCAL_ALIGNED_A(a, t, v, s, o, ...)             \
+    uint8_t la_##v[sizeof(t s o) + (a)];                \
+    t (*v) o = (void *)FFALIGN((uintptr_t)la_##v, a)
+
+#define LOCAL_ALIGNED_D(a, t, v, s, o, ...)             \
+    DECLARE_ALIGNED(a, t, la_##v) s o;                  \
+    t (*v) o = la_##v
+
+#define LOCAL_ALIGNED(a, t, v, ...) LOCAL_ALIGNED_##a(t, v, __VA_ARGS__)
+
+#if HAVE_LOCAL_ALIGNED
+#   define LOCAL_ALIGNED_4(t, v, ...) E1(LOCAL_ALIGNED_D(4, t, v, __VA_ARGS__,,))
+#else
+#   define LOCAL_ALIGNED_4(t, v, ...) E1(LOCAL_ALIGNED_A(4, t, v, __VA_ARGS__,,))
+#endif
+
+#if HAVE_LOCAL_ALIGNED
+#   define LOCAL_ALIGNED_8(t, v, ...) E1(LOCAL_ALIGNED_D(8, t, v, __VA_ARGS__,,))
+#else
+#   define LOCAL_ALIGNED_8(t, v, ...) E1(LOCAL_ALIGNED_A(8, t, v, __VA_ARGS__,,))
+#endif
+
+#if HAVE_LOCAL_ALIGNED
+#   define LOCAL_ALIGNED_16(t, v, ...) E1(LOCAL_ALIGNED_D(16, t, v, __VA_ARGS__,,))
+#else
+#   define LOCAL_ALIGNED_16(t, v, ...) E1(LOCAL_ALIGNED_A(16, t, v, __VA_ARGS__,,))
+#endif
+
+#if HAVE_LOCAL_ALIGNED
+#   define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_D(32, t, v, __VA_ARGS__,,))
+#else
+#   define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_A(32, t, v, __VA_ARGS__,,))
+#endif
+
+#endif /* MPLAYER_MPMEM_H */
diff --git a/sub/osd.c b/sub/osd.c
index 879060e8f..f20b06095 100644
--- a/sub/osd.c
+++ b/sub/osd.c
@@ -28,7 +28,7 @@
 #include "mp_msg.h"
 #include <inttypes.h>
 #include <stdlib.h>
-#include "libavutil/mem_internal.h"
+#include "mpmem.h"
 #include "libmpcodecs/img_format.h"
 #include "cpudetect.h"

--
2.30.0



More information about the MPlayer-dev-eng mailing list