Skip to content

Instantly share code, notes, and snippets.

@alexandruc
Last active August 31, 2016 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexandruc/d2bc868afde596fa6302 to your computer and use it in GitHub Desktop.
Save alexandruc/d2bc868afde596fa6302 to your computer and use it in GitHub Desktop.
Gstreamer patch for android mips build - for cerbero rev 4df49a735b00134516bafa44301bf424108166f5
diff --git a/cerbero/enums.py b/cerbero/enums.py
index 88edefe..f80373e 100644
--- a/cerbero/enums.py
+++ b/cerbero/enums.py
@@ -34,7 +34,7 @@ class Architecture:
UNIVERSAL = 'universal'
ARM = 'arm'
ARMv7 = 'armv7'
-
+ MIPS = 'mips'
class Distro:
''' Enumeration of supported distributions '''
diff --git a/config/android.config b/config/android.config
index b0e3950..7a02419 100644
--- a/config/android.config
+++ b/config/android.config
@@ -28,6 +28,19 @@ if target_arch == Architecture.ARM or target_arch == Architecture.ARMv7:
break
if toolchain_path:
break
+elif target_arch == Architecture.MIPS:
+ tools_prefix = 'mipsel-linux-android'
+ host = "mipsel-linux-android"
+ _arch = 'mips'
+
+ for tc_version in ['4.8', '4.7', '4.6']:
+ for tc_arch in ['linux-x86', 'linux-x86_64']:
+ tmp = '%s/toolchains/mipsel-linux-android-%s/prebuilt/%s/bin' % (toolchain_prefix, tc_version, tc_arch)
+ if os.path.exists(tmp):
+ toolchain_path = tmp
+ break
+ if toolchain_path:
+ break
elif target_arch == Architecture.X86:
tools_prefix = 'i686-linux-android'
host = "i686-linux-android"
@@ -84,6 +97,10 @@ if target_arch in [Architecture.ARM, Architecture.ARMv7]:
ldflags += "-march=armv7-a -Wl,--fix-cortex-a8 "
if target_arch == Architecture.X86:
cflags += ' -march=i686 -fomit-frame-pointer -fstrict-aliasing -funswitch-loops -finline-limit=300'
+if target_arch == Architecture.MIPS:
+ cflags += ' -march=mips32 -fomit-frame-pointer -fstrict-aliasing -funswitch-loops -finline-limit=300'
+ ldflags += ' -march=mips32 '
+
# Toolchain environment
@@ -96,10 +113,15 @@ def cmd(command):
return '%s-%s' % (tools_prefix, command)
os.environ['CC']= '%s%s' % (ccache, cmd('gcc'))
-os.environ['CC'] += ' -fuse-ld=gold'
+if target_arch != Architecture.MIPS:
+ os.environ['CC'] += ' -fuse-ld=gold'
os.environ['CXX']= '%s%s' % (ccache, cmd('g++'))
-os.environ['CXX'] += ' -fuse-ld=gold'
-os.environ['LD']= cmd('ld.gold')
+if target_arch != Architecture.MIPS:
+ os.environ['CXX'] += ' -fuse-ld=gold'
+if target_arch == Architecture.MIPS:
+ os.environ['LD']= cmd('ld')
+else:
+ os.environ['LD']= cmd('ld.gold')
os.environ['CPP']= cmd('cpp')
os.environ['RANLIB']= cmd('ranlib')
os.environ['AR']= cmd('ar')
diff --git a/config/cross-android-mips.cbc b/config/cross-android-mips.cbc
new file mode 100644
index 0000000..cf7d023
--- /dev/null
+++ b/config/cross-android-mips.cbc
@@ -0,0 +1,9 @@
+import os
+from cerbero.config import Platform, Architecture, Distro, DistroVersion
+
+target_platform = Platform.ANDROID
+target_distro = Distro.ANDROID
+target_distro_version = DistroVersion.ANDROID_GINGERBREAD
+target_arch = Architecture.MIPS
+
+#variants = ['nodebug']
diff --git a/recipes/gnustl.recipe b/recipes/gnustl.recipe
index 3e593a9..c6d1423 100644
--- a/recipes/gnustl.recipe
+++ b/recipes/gnustl.recipe
@@ -32,8 +32,10 @@ class Recipe(recipe.Recipe):
stl_libdir = os.path.join(stl_prefix, 'libs', 'x86')
elif self.config.target_arch == Architecture.ARMv7:
stl_libdir = os.path.join(stl_prefix, 'libs', 'armeabi-v7a')
- else:
+ elif self.config.target_arch == Architecture.ARM:
stl_libdir = os.path.join(stl_prefix, 'libs', 'armeabi')
+ else:
+ stl_libdir = os.path.join(stl_prefix, 'libs', 'mips')
libdir = os.path.join(self.config.prefix, 'lib')
if not os.path.exists(libdir):
os.makedirs(libdir)
diff --git a/recipes/libiconv.recipe b/recipes/libiconv.recipe
index d7d0024..d472822 100644
--- a/recipes/libiconv.recipe
+++ b/recipes/libiconv.recipe
@@ -19,4 +19,4 @@ class Recipe(recipe.Recipe):
def prepare(self):
if self.config.target_platform != Platform.LINUX:
- self.runtime_dep = True
+ self.runtime_dep = True
\ No newline at end of file
diff --git a/recipes/libmad.recipe b/recipes/libmad.recipe
index ac16edf..e019963 100644
--- a/recipes/libmad.recipe
+++ b/recipes/libmad.recipe
@@ -24,8 +24,11 @@ class Recipe(recipe.Recipe):
elif self.config.target_platform == Platform.DARWIN:
self.patches += ['libmad/0004-Remove-clang-unsupported-compiler-flags.patch']
elif self.config.target_platform == Platform.ANDROID:
- if Architecture.is_arm(self.config.target_arch):
+ #if Architecture.is_arm(self.config.target_arch):
+ if self.config.target_arch == Architecture.ARM or self.config.target_arch == Architecture.ARMv7 or self.config.target_arch == Architecture.MIPS:
# Disable thumb mode to get the optimizations compiled properly
self.new_env['CFLAGS'] = os.environ['CFLAGS'].replace('-mthumb', '')
if self.config.target_arch == Architecture.X86:
self.new_env['CFLAGS'] = os.environ['CFLAGS'] + ' -fno-stack-protector'
+ if self.config.target_arch == Architecture.MIPS:
+ self.patches += ['libmad/0005-imp_constraint.patch']
diff --git a/recipes/libmad/0005-imp_constraint.patch b/recipes/libmad/0005-imp_constraint.patch
new file mode 100644
index 0000000..903ae03
--- /dev/null
+++ b/recipes/libmad/0005-imp_constraint.patch
@@ -0,0 +1,34 @@
+diff -u -r a/apps/codecs/libmad/fixed.h b/apps/codecs/libmad/fixed.h
+--- a/fixed.h
++++ b/fixed.h
+@@ -292,6 +292,21 @@
+
+ # elif defined(FPM_MIPS)
+
++#if defined (__GNUC__) && defined (__GNUC_MINOR__)
++#define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
++#else
++#define __GNUC_PREREQ(maj, min) 0
++#endif
++
++#if __GNUC_PREREQ(4,4)
++typedef unsigned int u64_di_t __attribute__ ((mode (DI)));
++# define MAD_F_MLX(hi, lo, x, y) \
++do { \
++ u64_di_t __ll = (u64_di_t) (x) * (y); \
++ hi = __ll >> 32; \
++ lo = __ll; \
++}while(0)
++#else
+ /*
+ * This MIPS version is fast and accurate; the disposition of the least
+ * significant bit depends on OPT_ACCURACY via mad_f_scale64().
+@@ -321,6 +336,8 @@
+ : "%r" ((x) >> 12), "r" ((y) >> 16))
+ # define MAD_F_MLZ(hi, lo) ((mad_fixed_t) (lo))
+ # endif
++
++#endif /* __GNU_PREREQ(4,4) */
+
+ # if defined(OPT_SPEED)
+ # define mad_f_scale64(hi, lo) \
diff --git a/recipes/libvpx.recipe b/recipes/libvpx.recipe
index 1604d60..b8bef71 100644
--- a/recipes/libvpx.recipe
+++ b/recipes/libvpx.recipe
@@ -13,7 +13,7 @@ class Recipe(recipe.Recipe):
url = 'http://webm.googlecode.com/files/libvpx-v1.3.0.tar.bz2'
configure_tpl = "./configure --prefix=%(prefix)s "\
"--libdir=%(libdir)s %(options)s"
- configure_options = "--enable-pic --as=yasm --disable-unit-tests "
+ configure_options = "--enable-pic --as=yasm --disable-unit-tests --disable-examples --disable-docs"
add_host_build_target = False
supports_cache_variables = False
can_use_configure_cache = False
@@ -26,6 +26,8 @@ class Recipe(recipe.Recipe):
'libvpx/0006-Add-armv7s-ios-support.patch',
'libvpx/0007-configure-quote-local-variables-correctly.patch',
'libvpx/0008-Add-support-for-iOS-simulator-on-x86-64.patch',
+ 'libvpx/0009-configure-mips.patch',
+ 'libvpx/0010-androidmk-mips.patch',
]
files_libs = ['libvpx']
@@ -47,8 +49,10 @@ class Recipe(recipe.Recipe):
arch = 'arm'
elif self.config.target_arch == Architecture.ARMv7:
arch = 'armv7'
- elif self.config.target_arch == Architecture.ARMv7S:
- arch = 'armv7s'
+ #elif self.config.target_arch == Architecture.ARMv7S:
+ # arch = 'armv7s'
+ elif self.config.target_arch == Architecture.MIPS:
+ arch = 'mips'
self.new_env['LD'] = os.environ.get('CC', 'gcc')
if self.config.target_platform == Platform.DARWIN:
@@ -94,6 +98,8 @@ class Recipe(recipe.Recipe):
pass
elif self.config.target_arch == Architecture.X86:
pass
+ elif self.config.target_arch == Architecture.MIPS:
+ arch = 'mips32'
else:
raise FatalError("Unsupported Android architecture %s" % self.config.target_arch)
self.config_sh = 'LD=$CC ./configure'
diff --git a/recipes/libvpx/0009-configure-mips.patch b/recipes/libvpx/0009-configure-mips.patch
new file mode 100644
index 0000000..fa33b61
--- /dev/null
+++ b/recipes/libvpx/0009-configure-mips.patch
@@ -0,0 +1,11 @@
+--- a/configure
++++ b/configure
+@@ -102,6 +102,7 @@ all_platforms="${all_platforms} mips32-android-gcc"
+ all_platforms="${all_platforms} armv7-win32-vs11"
+ all_platforms="${all_platforms} armv7-win32-vs12"
+ all_platforms="${all_platforms} mips32-linux-gcc"
++all_platforms="${all_platforms} mips32-android-gcc"
+ all_platforms="${all_platforms} ppc32-darwin8-gcc"
+ all_platforms="${all_platforms} ppc32-darwin9-gcc"
+ all_platforms="${all_platforms} ppc32-linux-gcc"--
+
diff --git a/recipes/libvpx/0010-androidmk-mips.patch b/recipes/libvpx/0010-androidmk-mips.patch
new file mode 100644
index 0000000..5e9eb02
--- /dev/null
+++ b/recipes/libvpx/0010-androidmk-mips.patch
@@ -0,0 +1,106 @@
+diff --git a/build/make/Android.mk b/build/make/Android.mk
+index 48a0dd7..369c2a5 100644
+--- a/build/make/Android.mk
++++ b/build/make/Android.mk
+@@ -53,12 +53,20 @@
+ ASM_CNV_PATH_LOCAL := $(TARGET_ARCH_ABI)/ads2gas
+ ASM_CNV_PATH := $(LOCAL_PATH)/$(ASM_CNV_PATH_LOCAL)
+
+-# Makefiles created by the libvpx configure process
+-# This will need to be fixed to handle x86.
++# Use the makefiles generated by upstream configure to determine which files to
++# build. Also set any architecture-specific flags.
+ ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
+ include $(CONFIG_DIR)libs-armv7-android-gcc.mk
+-else
++ LOCAL_ARM_MODE := arm
++else ifeq ($(TARGET_ARCH_ABI),armeabi)
+ include $(CONFIG_DIR)libs-armv5te-android-gcc.mk
++ LOCAL_ARM_MODE := arm
++else ifeq ($(TARGET_ARCH_ABI),x86)
++ include $(CONFIG_DIR)libs-x86-android-gcc.mk
++else ifeq ($(TARGET_ARCH_ABI),mips)
++ include $(CONFIG_DIR)libs-mips-android-gcc.mk
++else
++ $(error Not a supported TARGET_ARCH_ABI: $(TARGET_ARCH_ABI))
+ endif
+
+ # Rule that is normally in Makefile created by libvpx
+@@ -72,9 +80,12 @@
+ # Include the list of files to be built
+ include $(LIBVPX_PATH)/libs.mk
+
+-# Want arm, not thumb, optimized
+-LOCAL_ARM_MODE := arm
++# Optimise the code. May want to revisit this setting in the future.
+ LOCAL_CFLAGS := -O3
++
++# For x86, include the source code in the search path so it will find files
++# like x86inc.asm and x86_abi_support.asm
++LOCAL_ASMFLAGS := -I$(LIBVPX_PATH)
+
+ # -----------------------------------------------------------------------------
+ # Template : asm_offsets_template
+@@ -109,7 +120,7 @@
+ @grep $(OFFSET_PATTERN) $$< | tr -d '\#' | $(CONFIG_DIR)$(ASM_CONVERSION) > $$@
+ endef
+
+-# Use ads2gas script to convert from RVCT format to GAS format. This passes
++# Use ads2gas script to convert from RVCT format to GAS format. This
+ # puts the processed file under $(ASM_CNV_PATH). Local clean rule
+ # to handle removing these
+ ifeq ($(CONFIG_VP8_ENCODER), yes)
+@@ -146,18 +157,26 @@
+
+ # Pull out assembly files, splitting NEON from the rest. This is
+ # done to specify that the NEON assembly files use NEON assembler flags.
+-CODEC_SRCS_ASM_ALL = $(filter %.asm.s, $(CODEC_SRCS_UNIQUE))
+-CODEC_SRCS_ASM = $(foreach v, \
+- $(CODEC_SRCS_ASM_ALL), \
+- $(if $(findstring neon,$(v)),,$(v)))
++# x86 assembly matches %.asm, arm matches %.asm.s
++
++# x86:
++
++CODEC_SRCS_ASM_X86 = $(filter %.asm, $(CODEC_SRCS_UNIQUE))
++LOCAL_SRC_FILES += $(foreach file, $(CODEC_SRCS_ASM_X86), libvpx/$(file))
++
++# arm:
++CODEC_SRCS_ASM_ARM_ALL = $(filter %.asm.s, $(CODEC_SRCS_UNIQUE))
++CODEC_SRCS_ASM_ARM = $(foreach v, \
++ $(CODEC_SRCS_ASM_ARM_ALL), \
++ $(if $(findstring neon,$(v)),,$(v)))
+ CODEC_SRCS_ASM_ADS2GAS = $(patsubst %.s, \
+ $(ASM_CNV_PATH_LOCAL)/libvpx/%.s, \
+- $(CODEC_SRCS_ASM))
++ $(CODEC_SRCS_ASM_ARM))
+ LOCAL_SRC_FILES += $(CODEC_SRCS_ASM_ADS2GAS)
+
+ ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
+ CODEC_SRCS_ASM_NEON = $(foreach v, \
+- $(CODEC_SRCS_ASM_ALL),\
++ $(CODEC_SRCS_ASM_ARM_ALL),\
+ $(if $(findstring neon,$(v)),$(v),))
+ CODEC_SRCS_ASM_NEON_ADS2GAS = $(patsubst %.s, \
+ $(ASM_CNV_PATH_LOCAL)/libvpx/%.s, \
+@@ -189,6 +208,10 @@
+ endif
+ $(foreach file, $(LOCAL_SRC_FILES), $(LOCAL_PATH)/$(file)): vpx_scale_rtcd.h
+
++ifeq ($(TARGET_ARCH_ABI),x86)
++$(foreach file, $(LOCAL_SRC_FILES), $(LOCAL_PATH)/$(file)): vpx_config.asm
++endif
++
+ .PHONY: clean
+ clean:
+ @echo "Clean: ads2gas files [$(TARGET_ARCH_ABI)]"
+diff --git a/test/android/README b/test/android/README
+index 6840d91..4a1adcf 100644
+--- a/test/android/README
++++ b/test/android/README
+@@ -3,7 +3,7 @@
+ ./libvpx/configure --target=armv7-android-gcc --enable-external-build \
+ --enable-postproc --disable-install-srcs --enable-multi-res-encoding \
+ --enable-temporal-denoising --disable-unit-tests --disable-install-docs \
+- --disable-examples --disable-runtime-cpu-detect --sdk=$NDK
++ --disable-examples --disable-runtime-cpu-detect --sdk-path=$NDK
@sdroege
Copy link

sdroege commented Feb 16, 2016

I can't comment on your blog it seems, so a comment here instead...

The official GStreamer website is http://gstreamer.freedesktop.org , gstreamer.com was just a project by some companies in the past that is no longer maintained and provides completely outdated versions of GStreamer (3+ years by now).

You can also get the latest version of cerbero at https://cgit.freedesktop.org/gstreamer/cerbero/ , which can be used to build newer versions of GStreamer but still has no MIPS support.

Would you mind providing your patch to the GStreamer project at https://bugzilla.gnome.org/show_bug.cgi?id=734188 ? Thanks :)

@alexandruc
Copy link
Author

Sorry for the loong delay for the response. I simply don't get notifications for comments for gists.
I see you have used a patch. I hope it's working. if you need any help, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment