[FFmpeg-devel] lavu/file: fix build on Android NDK with unified headers

Submitted by Rodger Combs on Sept. 26, 2017, 1:52 a.m.

Details

Message ID 20170926015217.42597-1-rodger.combs@gmail.com
State New
Headers show

Commit Message

Rodger Combs Sept. 26, 2017, 1:52 a.m.
---
 libavdevice/fbdev_enc.c  | 1 +
 libavformat/os_support.h | 6 ++++++
 libavutil/file.c         | 1 +
 3 files changed, 8 insertions(+)

Comments

Carl Eugen Hoyos Sept. 26, 2017, 11:27 a.m.
2017-09-26 3:52 GMT+02:00 Rodger Combs <rodger.combs@gmail.com>:

> +#  if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 21 && !defined(__LP64__)
> +#   ifdef mmap
> +#    undef mmap
> +#   endif
> +void* mmap(void*, size_t, int, int, int, __kernel_off_t);

How can this issue be reproduced?

Shouldn't this be checked in configure?

Carl Eugen
Rodger Combs Sept. 26, 2017, 4:22 p.m.
I used this rather absurd configure invocation:

BINDIR=$(realpath $(dirname $(ndk-which gcc)))
NDKDIR=$(dirname $(dirname $(dirname $(dirname $(dirname $BINDIR)))))
TARGET=16
ARCH=arm
TRIPLE=arm-linux-androideabi
SUFFIX=-4.9
PLATARCH=arm

../configure \
--enable-cross-compile \
--arch=$ARCH \
--cross_prefix="$NDKDIR/toolchains/$TRIPLE$SUFFIX/prebuilt/darwin-x86_64/bin/$TRIPLE-" \
--extra-cflags=-D__ANDROID_API__=$TARGET \
--extra-cflags="--sysroot=$NDKDIR/sysroot" \
--extra-cflags="-isystem $NDKDIR/sysroot/usr/include/$TRIPLE" \
--extra-cflags="-mfloat-abi=softfp" \
--extra-ldflags="--sysroot=$NDKDIR/platforms/android-$TARGET/arch-$PLATARCH" \
--extra-ldexeflags=-pie \
--enable-debug \
--target-os=android

The issue is that the unified headers don't declare mmap() on target API versions before 21 on 32-bit platforms when __USE_FILE_OFFSET64/_FILE_OFFSET_BITS=64 is set, because this sets off_t to be off64_t, and mmap64 isn't available until API 21. This doesn't matter for ffmpeg, since we never use the offset arg anyway, so we can just declare the function ourselves.

I'm not sure what one would do about this in configure.

> On Sep 26, 2017, at 06:27, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:
> 
> 2017-09-26 3:52 GMT+02:00 Rodger Combs <rodger.combs@gmail.com>:
> 
>> +#  if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 21 && !defined(__LP64__)
>> +#   ifdef mmap
>> +#    undef mmap
>> +#   endif
>> +void* mmap(void*, size_t, int, int, int, __kernel_off_t);
> 
> How can this issue be reproduced?
> 
> Shouldn't this be checked in configure?
> 
> Carl Eugen
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Patch hide | download patch | download mbox

diff --git a/libavdevice/fbdev_enc.c b/libavdevice/fbdev_enc.c
index b4e5f84975..a9be608383 100644
--- a/libavdevice/fbdev_enc.c
+++ b/libavdevice/fbdev_enc.c
@@ -28,6 +28,7 @@ 
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
 #include "libavformat/avformat.h"
+#include "libavformat/os_support.h"
 #include "fbdev_common.h"
 #include "avdevice.h"
 
diff --git a/libavformat/os_support.h b/libavformat/os_support.h
index 91220e9716..54324603c9 100644
--- a/libavformat/os_support.h
+++ b/libavformat/os_support.h
@@ -65,6 +65,12 @@ 
 #   undef lseek
 #  endif
 #  define lseek(f,p,w) lseek64((f), (p), (w))
+#  if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 21 && !defined(__LP64__)
+#   ifdef mmap
+#    undef mmap
+#   endif
+void* mmap(void*, size_t, int, int, int, __kernel_off_t);
+#  endif
 #endif
 
 static inline int is_dos_path(const char *path)
diff --git a/libavutil/file.c b/libavutil/file.c
index 7bdf6cde84..c4b22539d0 100644
--- a/libavutil/file.c
+++ b/libavutil/file.c
@@ -21,6 +21,7 @@ 
 #include "internal.h"
 #include "log.h"
 #include "mem.h"
+#include "libavformat/os_support.h"
 #include <fcntl.h>
 #include <sys/stat.h>
 #if HAVE_UNISTD_H