Skip to content

Commit 96ad9eb

Browse files
committed
Add libvpx recipe, reference it in ffpyplayer_codecs and ffmpeg
1 parent 4d84256 commit 96ad9eb

File tree

4 files changed

+101
-1
lines changed

4 files changed

+101
-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: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
from pathlib import Path
6+
import sh
7+
8+
9+
TARGETS = {
10+
'armeabi-v7a': 'armv7-android-gcc',
11+
'arm64-v8a': 'arm64-android-gcc',
12+
}
13+
14+
15+
class VPXRecipe(Recipe):
16+
version = '1.9.0'
17+
url = 'https://github.com/webmproject/libvpx/archive/v{version}.tar.gz'
18+
19+
patches = [
20+
# See https://git.io/Jq50q
21+
join('patches', '0001-android-force-neon-runtime.patch'),
22+
]
23+
24+
def get_recipe_env(self, arch=None):
25+
env = super().get_recipe_env(arch)
26+
cxx_include_dir = join(
27+
self.ctx.ndk_dir,
28+
'toolchains',
29+
'llvm',
30+
'prebuilt',
31+
'linux-x86_64',
32+
'sysroot',
33+
'usr',
34+
'include',
35+
'c++',
36+
'v1',
37+
)
38+
env['CXXFLAGS'] += f' -I{cxx_include_dir}'
39+
if 'arm64' not in arch.arch:
40+
env['AS'] = arch.command_prefix + '-as'
41+
return env
42+
43+
def build_arch(self, arch):
44+
with current_directory(self.get_build_dir(arch.arch)):
45+
env = self.get_recipe_env(arch)
46+
flags = [
47+
'--target=' + TARGETS[arch.arch],
48+
'--enable-pic',
49+
'--enable-vp8',
50+
'--enable-vp9',
51+
'--enable-static',
52+
'--enable-small',
53+
'--disable-shared',
54+
'--disable-examples',
55+
'--disable-unit-tests',
56+
'--disable-tools',
57+
'--disable-docs',
58+
'--disable-install-docs',
59+
'--disable-realtime-only',
60+
f'--prefix={realpath(".")}',
61+
]
62+
configure = sh.Command('./configure')
63+
shprint(configure, *flags, _env=env)
64+
shprint(sh.make, '-j', str(cpu_count()), _env=env)
65+
shprint(sh.make, 'install', _env=env)
66+
67+
68+
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+
}

0 commit comments

Comments
 (0)