From 8b134231f9dd04ae0a5d725e0a72d1a7b2804533 Mon Sep 17 00:00:00 2001 From: The Cheaterman Date: Mon, 15 Mar 2021 20:39:37 +0100 Subject: [PATCH] Add libvpx recipe, reference it in ffpyplayer_codecs and ffmpeg Add recipe test as well... Only checks that configure is called but it's something I guess. --- pythonforandroid/recipes/ffmpeg/__init__.py | 7 ++ .../recipes/ffpyplayer_codecs/__init__.py | 2 +- pythonforandroid/recipes/libvpx/__init__.py | 67 +++++++++++++++++++ .../0001-android-force-neon-runtime.patch | 25 +++++++ tests/recipes/test_libvpx.py | 10 +++ 5 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 pythonforandroid/recipes/libvpx/__init__.py create mode 100644 pythonforandroid/recipes/libvpx/patches/0001-android-force-neon-runtime.patch create mode 100644 tests/recipes/test_libvpx.py diff --git a/pythonforandroid/recipes/ffmpeg/__init__.py b/pythonforandroid/recipes/ffmpeg/__init__.py index 5baa20389a..6f64d26562 100644 --- a/pythonforandroid/recipes/ffmpeg/__init__.py +++ b/pythonforandroid/recipes/ffmpeg/__init__.py @@ -61,6 +61,13 @@ def build_arch(self, arch): ldflags += ['-lshine', '-L' + build_dir + '/lib/'] ldflags += ['-lm'] + # libvpx + flags += ['--enable-libvpx'] + build_dir = Recipe.get_recipe( + 'libvpx', self.ctx).get_build_dir(arch.arch) + cflags += ['-I' + build_dir + '/include/'] + ldflags += ['-lvpx', '-L' + build_dir + '/lib/'] + # Enable all codecs: flags += [ '--enable-parsers', diff --git a/pythonforandroid/recipes/ffpyplayer_codecs/__init__.py b/pythonforandroid/recipes/ffpyplayer_codecs/__init__.py index 558c0c223d..eedb1269e5 100644 --- a/pythonforandroid/recipes/ffpyplayer_codecs/__init__.py +++ b/pythonforandroid/recipes/ffpyplayer_codecs/__init__.py @@ -2,7 +2,7 @@ class FFPyPlayerCodecsRecipe(Recipe): - depends = ['libx264', 'libshine'] + depends = ['libx264', 'libshine', 'libvpx'] def build_arch(self, arch): pass diff --git a/pythonforandroid/recipes/libvpx/__init__.py b/pythonforandroid/recipes/libvpx/__init__.py new file mode 100644 index 0000000000..9c2957a2da --- /dev/null +++ b/pythonforandroid/recipes/libvpx/__init__.py @@ -0,0 +1,67 @@ +from pythonforandroid.recipe import Recipe +from pythonforandroid.toolchain import current_directory, shprint +from os.path import join, realpath +from multiprocessing import cpu_count +import sh + + +TARGETS = { + 'armeabi-v7a': 'armv7-android-gcc', + 'arm64-v8a': 'arm64-android-gcc', +} + + +class VPXRecipe(Recipe): + version = '1.9.0' + url = 'https://github.com/webmproject/libvpx/archive/v{version}.tar.gz' + + patches = [ + # See https://git.io/Jq50q + join('patches', '0001-android-force-neon-runtime.patch'), + ] + + def get_recipe_env(self, arch=None): + env = super().get_recipe_env(arch) + cxx_include_dir = join( + self.ctx.ndk_dir, + 'toolchains', + 'llvm', + 'prebuilt', + 'linux-x86_64', + 'sysroot', + 'usr', + 'include', + 'c++', + 'v1', + ) + env['CXXFLAGS'] += f' -I{cxx_include_dir}' + if 'arm64' not in arch.arch: + env['AS'] = arch.command_prefix + '-as' + return env + + def build_arch(self, arch): + with current_directory(self.get_build_dir(arch.arch)): + env = self.get_recipe_env(arch) + flags = [ + '--target=' + TARGETS[arch.arch], + '--enable-pic', + '--enable-vp8', + '--enable-vp9', + '--enable-static', + '--enable-small', + '--disable-shared', + '--disable-examples', + '--disable-unit-tests', + '--disable-tools', + '--disable-docs', + '--disable-install-docs', + '--disable-realtime-only', + f'--prefix={realpath(".")}', + ] + configure = sh.Command('./configure') + shprint(configure, *flags, _env=env) + shprint(sh.make, '-j', str(cpu_count()), _env=env) + shprint(sh.make, 'install', _env=env) + + +recipe = VPXRecipe() diff --git a/pythonforandroid/recipes/libvpx/patches/0001-android-force-neon-runtime.patch b/pythonforandroid/recipes/libvpx/patches/0001-android-force-neon-runtime.patch new file mode 100644 index 0000000000..220800d77d --- /dev/null +++ b/pythonforandroid/recipes/libvpx/patches/0001-android-force-neon-runtime.patch @@ -0,0 +1,25 @@ +diff -u -r ../libvpx-1.6.1/vpx_ports/arm_cpudetect.c ./vpx_ports/arm_cpudetect.c +--- ../libvpx-1.6.1/vpx_ports/arm_cpudetect.c 2017-01-12 21:27:27.000000000 +0100 ++++ ./vpx_ports/arm_cpudetect.c 2017-01-29 23:55:05.399283897 +0100 +@@ -92,20 +92,17 @@ + } + + #elif defined(__ANDROID__) /* end _MSC_VER */ +-#include + + int arm_cpu_caps(void) { + int flags; + int mask; +- uint64_t features; + if (!arm_cpu_env_flags(&flags)) { + return flags; + } + mask = arm_cpu_env_mask(); +- features = android_getCpuFeatures(); + + #if HAVE_NEON || HAVE_NEON_ASM +- if (features & ANDROID_CPU_ARM_FEATURE_NEON) flags |= HAS_NEON; ++ flags |= HAS_NEON; + #endif /* HAVE_NEON || HAVE_NEON_ASM */ + return flags & mask; + } diff --git a/tests/recipes/test_libvpx.py b/tests/recipes/test_libvpx.py new file mode 100644 index 0000000000..ae6783f0e9 --- /dev/null +++ b/tests/recipes/test_libvpx.py @@ -0,0 +1,10 @@ +import unittest +from tests.recipes.recipe_lib_test import BaseTestForMakeRecipe + + +class TestLibVPXRecipe(BaseTestForMakeRecipe, unittest.TestCase): + """ + An unittest for recipe :mod:`~pythonforandroid.recipes.libvpx` + """ + recipe_name = "libvpx" + sh_command_calls = ["./configure"]