Skip to content

Commit 53a2223

Browse files
authored
Merge pull request kivy#2440 from Cheaterman/add_libvpx_recipe
Add libvpx recipe, reference it in ffpyplayer_codecs and ffmpeg
2 parents 8336cea + 8b13423 commit 53a2223

File tree

5 files changed

+110
-1
lines changed

5 files changed

+110
-1
lines changed

pythonforandroid/recipes/ffmpeg/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ def build_arch(self, arch):
6161
ldflags += ['-lshine', '-L' + build_dir + '/lib/']
6262
ldflags += ['-lm']
6363

64+
# libvpx
65+
flags += ['--enable-libvpx']
66+
build_dir = Recipe.get_recipe(
67+
'libvpx', self.ctx).get_build_dir(arch.arch)
68+
cflags += ['-I' + build_dir + '/include/']
69+
ldflags += ['-lvpx', '-L' + build_dir + '/lib/']
70+
6471
# Enable all codecs:
6572
flags += [
6673
'--enable-parsers',

pythonforandroid/recipes/ffpyplayer_codecs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
class FFPyPlayerCodecsRecipe(Recipe):
5-
depends = ['libx264', 'libshine']
5+
depends = ['libx264', 'libshine', 'libvpx']
66

77
def build_arch(self, arch):
88
pass
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from pythonforandroid.recipe import Recipe
2+
from pythonforandroid.toolchain import current_directory, shprint
3+
from os.path import join, realpath
4+
from multiprocessing import cpu_count
5+
import sh
6+
7+
8+
TARGETS = {
9+
'armeabi-v7a': 'armv7-android-gcc',
10+
'arm64-v8a': 'arm64-android-gcc',
11+
}
12+
13+
14+
class VPXRecipe(Recipe):
15+
version = '1.9.0'
16+
url = 'https://github.com/webmproject/libvpx/archive/v{version}.tar.gz'
17+
18+
patches = [
19+
# See https://git.io/Jq50q
20+
join('patches', '0001-android-force-neon-runtime.patch'),
21+
]
22+
23+
def get_recipe_env(self, arch=None):
24+
env = super().get_recipe_env(arch)
25+
cxx_include_dir = join(
26+
self.ctx.ndk_dir,
27+
'toolchains',
28+
'llvm',
29+
'prebuilt',
30+
'linux-x86_64',
31+
'sysroot',
32+
'usr',
33+
'include',
34+
'c++',
35+
'v1',
36+
)
37+
env['CXXFLAGS'] += f' -I{cxx_include_dir}'
38+
if 'arm64' not in arch.arch:
39+
env['AS'] = arch.command_prefix + '-as'
40+
return env
41+
42+
def build_arch(self, arch):
43+
with current_directory(self.get_build_dir(arch.arch)):
44+
env = self.get_recipe_env(arch)
45+
flags = [
46+
'--target=' + TARGETS[arch.arch],
47+
'--enable-pic',
48+
'--enable-vp8',
49+
'--enable-vp9',
50+
'--enable-static',
51+
'--enable-small',
52+
'--disable-shared',
53+
'--disable-examples',
54+
'--disable-unit-tests',
55+
'--disable-tools',
56+
'--disable-docs',
57+
'--disable-install-docs',
58+
'--disable-realtime-only',
59+
f'--prefix={realpath(".")}',
60+
]
61+
configure = sh.Command('./configure')
62+
shprint(configure, *flags, _env=env)
63+
shprint(sh.make, '-j', str(cpu_count()), _env=env)
64+
shprint(sh.make, 'install', _env=env)
65+
66+
67+
recipe = VPXRecipe()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
diff -u -r ../libvpx-1.6.1/vpx_ports/arm_cpudetect.c ./vpx_ports/arm_cpudetect.c
2+
--- ../libvpx-1.6.1/vpx_ports/arm_cpudetect.c 2017-01-12 21:27:27.000000000 +0100
3+
+++ ./vpx_ports/arm_cpudetect.c 2017-01-29 23:55:05.399283897 +0100
4+
@@ -92,20 +92,17 @@
5+
}
6+
7+
#elif defined(__ANDROID__) /* end _MSC_VER */
8+
-#include <cpu-features.h>
9+
10+
int arm_cpu_caps(void) {
11+
int flags;
12+
int mask;
13+
- uint64_t features;
14+
if (!arm_cpu_env_flags(&flags)) {
15+
return flags;
16+
}
17+
mask = arm_cpu_env_mask();
18+
- features = android_getCpuFeatures();
19+
20+
#if HAVE_NEON || HAVE_NEON_ASM
21+
- if (features & ANDROID_CPU_ARM_FEATURE_NEON) flags |= HAS_NEON;
22+
+ flags |= HAS_NEON;
23+
#endif /* HAVE_NEON || HAVE_NEON_ASM */
24+
return flags & mask;
25+
}

tests/recipes/test_libvpx.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import unittest
2+
from tests.recipes.recipe_lib_test import BaseTestForMakeRecipe
3+
4+
5+
class TestLibVPXRecipe(BaseTestForMakeRecipe, unittest.TestCase):
6+
"""
7+
An unittest for recipe :mod:`~pythonforandroid.recipes.libvpx`
8+
"""
9+
recipe_name = "libvpx"
10+
sh_command_calls = ["./configure"]

0 commit comments

Comments
 (0)