shithub: openh264

Download patch

ref: 01a2f582c35f89eb7a6127460af74c678a187da2
parent: e61bd1b5048b183963ca5cb38c9ce035deb5a559
parent: 560c14b67c577e528440d38ae04cf5b1187c9fa4
author: Ethan Hugg <[email protected]>
date: Tue Mar 4 04:50:07 EST 2014

Merge pull request #401 from mstorsjo/android-arm-assembly

Enable the arm assembly in android builds

--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,7 @@
 ARCH=$(shell uname -m)
 LIBPREFIX=lib
 LIBSUFFIX=a
+CCAS=$(CC)
 CXX_O=-o $@
 CXX_LINK_O=-o $@
 AR_OPTS=cr $@
@@ -44,6 +45,7 @@
 ifneq ($(V),Yes)
     QUIET_CXX = @printf "CXX\t$@\n";
     QUIET_CC  = @printf "CC\t$@\n";
+    QUIET_CCAS = @printf "CCAS\t$@\n";
     QUIET_ASM = @printf "ASM\t$@\n";
     QUIET_AR  = @printf "AR\t$@\n";
     QUIET     = @
@@ -110,8 +112,10 @@
 include codec/processing/targets.mk
 
 ifneq (android, $(OS))
+ifneq (ios, $(OS))
 include codec/console/dec/targets.mk
 include codec/console/enc/targets.mk
+endif
 endif
 
 libraries: $(LIBPREFIX)wels.$(LIBSUFFIX) $(LIBPREFIX)wels.$(SHAREDLIBSUFFIX)
--- a/build/mktargets.py
+++ b/build/mktargets.py
@@ -46,11 +46,20 @@
     f.write('\t$(QUIET_ASM)$(ASM) $(ASMFLAGS) $(ASM_INCLUDES) $(' + PREFIX + '_ASMFLAGS) $(' + PREFIX + '_ASM_INCLUDES) -o $@ $<\n')
     f.write("\n")
 
+def write_asm_s_rule_pattern(f):
+    src = "$(%s_SRCDIR)/%%.S"%(PREFIX)
+    dst = "$(%s_SRCDIR)/%%.o"%(PREFIX)
 
+    f.write("%s: %s\n"%(dst, src))
+    f.write('\t$(QUIET_CCAS)$(CCAS) $(CFLAGS) $(ASMFLAGS) $(INCLUDES) $(' + PREFIX + '_CFLAGS) $(' + PREFIX + '_INCLUDES) -c -o $@ $<\n')
+    f.write("\n")
+
+
 def find_sources():
     cpp_files = []
     asm_files = []
     c_files = []
+    s_files = []
     print EXCLUDE
     for dir in os.walk("."):
         for file in dir[2]:
@@ -61,7 +70,9 @@
                     asm_files.append(os.path.join(dir[0].strip('./'), file))
                 if os.path.splitext(file)[1] == '.c':
                     c_files.append(os.path.join(dir[0].strip('./'), file))
-    return [cpp_files, asm_files, c_files]
+                if os.path.splitext(file)[1] == '.S':
+                    s_files.append(os.path.join(dir[0].strip('./'), file))
+    return [cpp_files, asm_files, c_files, s_files]
 
 
 args = parser.parse_args()
@@ -91,7 +102,7 @@
 except:
     sys.exit(1)
 
-(cpp, asm, cfiles) = find_sources()
+(cpp, asm, cfiles, sfiles) = find_sources()
 
 
 
@@ -120,6 +131,15 @@
     f.write("%s_OBJS += $(%s_ASM_SRCS:.asm=.o)\n"%(PREFIX, PREFIX))
     f.write("endif\n\n")
 
+if len(sfiles) > 0:
+    f.write("ifeq ($(ASM_ARCH), arm)\n")
+    f.write("%s_ASM_S_SRCS=\\\n"%(PREFIX))
+    for c in sfiles:
+        f.write("\t$(%s_SRCDIR)/%s\\\n"%(PREFIX, c))
+    f.write("\n")
+    f.write("%s_OBJS += $(%s_ASM_S_SRCS:.S=.o)\n"%(PREFIX, PREFIX))
+    f.write("endif\n\n")
+
 f.write("OBJS += $(%s_OBJS)\n"%PREFIX)
 
 write_cpp_rule_pattern(f)
@@ -129,6 +149,9 @@
 
 if len(asm) > 0:
     write_asm_rule_pattern(f)
+
+if len(sfiles) > 0:
+    write_asm_s_rule_pattern(f)
 
 if args.library is not None:
     f.write("$(LIBPREFIX)%s.$(LIBSUFFIX): $(%s_OBJS)\n"%(args.library, PREFIX))
--- a/build/platform-android.mk
+++ b/build/platform-android.mk
@@ -8,13 +8,14 @@
     GCCPATHPREFIX = arm-linux-androideabi
     GCCPREFIX = arm-linux-androideabi
     CFLAGS += -march=armv7-a -mfloat-abi=softfp
-  ifeq (Yes, $(HAVE_NEON))
-    CFLAGS += -mfpu=neon
-  else
     CFLAGS += -mfpu=vfpv3-d16
-  endif
     LDFLAGS += -march=armv7-a -Wl,--fix-cortex-a8
     APP_ABI = armeabi-v7a
+  ifeq (Yes, $(USE_ASM))
+    ASM_ARCH = arm
+    CFLAGS += -DHAVE_NEON
+    ASMFLAGS += -march=armv7-a -mfpu=neon
+  endif
 else
     GCCPATHPREFIX = x86
     GCCPREFIX = i686-linux-android
@@ -37,7 +38,7 @@
 CXX = $(NDKROOT)/toolchains/$(GCCPATHPREFIX)-$(GCCVERSION)/prebuilt/$(HOSTOS)-$(HOSTARCH)/bin/$(GCCPREFIX)-g++
 CC = $(NDKROOT)/toolchains/$(GCCPATHPREFIX)-$(GCCVERSION)/prebuilt/$(HOSTOS)-$(HOSTARCH)/bin/$(GCCPREFIX)-gcc
 AR = $(NDKROOT)/toolchains/$(GCCPATHPREFIX)-$(GCCVERSION)/prebuilt/$(HOSTOS)-$(HOSTARCH)/bin/$(GCCPREFIX)-ar
-CFLAGS += -DLINUX -fpic --sysroot=$(SYSROOT)
+CFLAGS += -DLINUX -DANDROID_NDK -fpic --sysroot=$(SYSROOT)
 CXXFLAGS += -fno-rtti -fno-exceptions
 LDFLAGS += --sysroot=$(SYSROOT)
 SHLDFLAGS = -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,-soname,libwels.so
@@ -58,3 +59,9 @@
 
 encdemo: libraries
 	cd ./codec/build/android/enc && $(NDKROOT)/ndk-build -B APP_ABI=$(APP_ABI) && android update project -t $(TARGET) -p . && ant debug
+
+COMMON_INCLUDES += -I$(NDKROOT)/sources/android/cpufeatures
+COMMON_OBJS += $(COMMON_SRCDIR)/cpu-features.o
+
+codec/common/cpu-features.o: $(NDKROOT)/sources/android/cpufeatures/cpu-features.c
+	$(QUIET_CC)$(CC) $(CFLAGS) $(INCLUDES) $(COMMON_CFLAGS) $(COMMON_INCLUDES) -c $(CXX_O) $<
--- a/build/platform-arch.mk
+++ b/build/platform-arch.mk
@@ -1,3 +1,9 @@
 ifneq ($(filter %86 x86_64, $(ARCH)),)
 include build/platform-x86-common.mk
 endif
+ifneq ($(filter-out arm64, $(filter arm%, $(ARCH))),)
+ifeq ($(USE_ASM), Yes)
+ASM_ARCH = arm
+CFLAGS += -DHAVE_NEON
+endif
+endif
--- a/build/platform-ios.mk
+++ b/build/platform-ios.mk
@@ -10,6 +10,6 @@
 SDK_MIN = 5.1
 
 SDKROOT = /Applications/Xcode.app/Contents/Developer/Platforms/$(SDKTYPE).platform/Developer/SDKs/$(SDKTYPE)$(SDK).sdk
-CFLAGS += -arch $(ARCH) -isysroot $(SDKROOT) -miphoneos-version-min=$(SDK_MIN)
+CFLAGS += -arch $(ARCH) -isysroot $(SDKROOT) -miphoneos-version-min=$(SDK_MIN) -DAPPLE_IOS
 LDFLAGS += -arch $(ARCH) -isysroot $(SDKROOT) -miphoneos-version-min=$(SDK_MIN)
 
--- a/build/platform-linux.mk
+++ b/build/platform-linux.mk
@@ -10,4 +10,7 @@
 ASMFLAGS += -f elf32
 endif
 endif
+ifeq ($(ASM_ARCH), arm)
+ASMFLAGS += -march=armv7-a -mfpu=neon
+endif
 
--- a/codec/common/targets.mk
+++ b/codec/common/targets.mk
@@ -22,6 +22,14 @@
 COMMON_OBJS += $(COMMON_ASM_SRCS:.asm=.o)
 endif
 
+ifeq ($(ASM_ARCH), arm)
+COMMON_ASM_S_SRCS=\
+	$(COMMON_SRCDIR)/arm_arch_common_macro.S\
+	$(COMMON_SRCDIR)/deblocking_neon.S\
+
+COMMON_OBJS += $(COMMON_ASM_S_SRCS:.S=.o)
+endif
+
 OBJS += $(COMMON_OBJS)
 $(COMMON_SRCDIR)/%.o: $(COMMON_SRCDIR)/%.cpp
 	$(QUIET_CXX)$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(COMMON_CFLAGS) $(COMMON_INCLUDES) -c $(CXX_O) $<
@@ -28,6 +36,9 @@
 
 $(COMMON_SRCDIR)/%.o: $(COMMON_SRCDIR)/%.asm
 	$(QUIET_ASM)$(ASM) $(ASMFLAGS) $(ASM_INCLUDES) $(COMMON_ASMFLAGS) $(COMMON_ASM_INCLUDES) -o $@ $<
+
+$(COMMON_SRCDIR)/%.o: $(COMMON_SRCDIR)/%.S
+	$(QUIET_CCAS)$(CCAS) $(CFLAGS) $(ASMFLAGS) $(INCLUDES) $(COMMON_CFLAGS) $(COMMON_INCLUDES) -c -o $@ $<
 
 $(LIBPREFIX)common.$(LIBSUFFIX): $(COMMON_OBJS)
 	$(QUIET)rm -f $@
--- a/codec/decoder/targets.mk
+++ b/codec/decoder/targets.mk
@@ -34,6 +34,15 @@
 DECODER_OBJS += $(DECODER_ASM_SRCS:.asm=.o)
 endif
 
+ifeq ($(ASM_ARCH), arm)
+DECODER_ASM_S_SRCS=\
+	$(DECODER_SRCDIR)/core/arm/block_add_neon.S\
+	$(DECODER_SRCDIR)/core/arm/intra_pred_neon.S\
+	$(DECODER_SRCDIR)/core/arm/mc_neon.S\
+
+DECODER_OBJS += $(DECODER_ASM_S_SRCS:.S=.o)
+endif
+
 OBJS += $(DECODER_OBJS)
 $(DECODER_SRCDIR)/%.o: $(DECODER_SRCDIR)/%.cpp
 	$(QUIET_CXX)$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(DECODER_CFLAGS) $(DECODER_INCLUDES) -c $(CXX_O) $<
@@ -40,6 +49,9 @@
 
 $(DECODER_SRCDIR)/%.o: $(DECODER_SRCDIR)/%.asm
 	$(QUIET_ASM)$(ASM) $(ASMFLAGS) $(ASM_INCLUDES) $(DECODER_ASMFLAGS) $(DECODER_ASM_INCLUDES) -o $@ $<
+
+$(DECODER_SRCDIR)/%.o: $(DECODER_SRCDIR)/%.S
+	$(QUIET_CCAS)$(CCAS) $(CFLAGS) $(ASMFLAGS) $(INCLUDES) $(DECODER_CFLAGS) $(DECODER_INCLUDES) -c -o $@ $<
 
 $(LIBPREFIX)decoder.$(LIBSUFFIX): $(DECODER_OBJS)
 	$(QUIET)rm -f $@