[x264-devel] enable pthreads for Andorid

Alex Cohn alexcohn at netvision.net.il
Thu Mar 21 11:14:57 CET 2013


./configure --enable-pic --enable-static
--cross-prefix=/etc/android-ndk-r8d/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86/bin/arm-linux-androideabi-
--sysroot=/etc/android-ndk-r8d/platforms/android-14/arch-arm
--host=arm-linux

Unfortunately, for Android this results in

thread:    no

That's because Android does not present a separate libpthread.a. The
fix is to create a fake empty library:

/etc/android-ndk-r8d/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86/bin/arm-linux-androideabi-ar
q ./libpthread.a
./configure --enable-pic --enable-static
--cross-prefix=/etc/android-ndk-r8d/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86/bin/arm-linux-androideabi-
--sysroot=/etc/android-ndk-r8d/platforms/android-14/arch-arm
--host=arm-linux --extra-ldflags="-L."

After this, configuration gives us

thread:     posix

This is not enough, though. make will fail, because Android does not
define cpu_set_t and the affinity API to derive number of cores at
runtime. I am using the following patch:

git diff common/cpu.c
diff --git a/common/cpu.c b/common/cpu.c
index 42a1b0e..bbbfcf4 100644
--- a/common/cpu.c
+++ b/common/cpu.c
@@-416,6 +416,9 @@ int x264_cpu_num_processors( void )
 #if !HAVE_THREAD
     return 1;

+#elif ANDROID
+     return android_getCpuCount();
+
 #elif SYS_WINDOWS
    return x264_pthread_num_processors_np( void )

To enable this, use

./configure --enable-pic --enable-static
--cross-prefix=/etc/android-ndk-r8d/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86/bin/arm-linux-androideabi-
--sysroot=/etc/android-ndk-r8d/platforms/android-14/arch-arm
--host=arm-linux --extra-ldflags="-L." --extra-cflags="-DANDROID"

android_getCpuCount() is supplied by Android NDK, see
http://www.kandroid.org/ndk/docs/CPU-FEATURES.html.

Best regards,

Alex Cohn


More information about the x264-devel mailing list