Skip to content

Add libvpx recipe, reference it in ffpyplayer_codecs and ffmpeg #2440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]