Skip to content

Commit

Permalink
Merge pull request #2440 from Cheaterman/add_libvpx_recipe
Browse files Browse the repository at this point in the history
Add libvpx recipe, reference it in ffpyplayer_codecs and ffmpeg
  • Loading branch information
AndreMiras authored Apr 25, 2021
2 parents 8336cea + 8b13423 commit 53a2223
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pythonforandroid/recipes/ffmpeg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion pythonforandroid/recipes/ffpyplayer_codecs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class FFPyPlayerCodecsRecipe(Recipe):
depends = ['libx264', 'libshine']
depends = ['libx264', 'libshine', 'libvpx']

def build_arch(self, arch):
pass
Expand Down
67 changes: 67 additions & 0 deletions pythonforandroid/recipes/libvpx/__init__.py
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -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 <cpu-features.h>

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;
}
10 changes: 10 additions & 0 deletions tests/recipes/test_libvpx.py
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 53a2223

Please sign in to comment.