基于x265_2.5(2.5版本),Android-18
0.提取Android交叉编译工具链
运行如下命令:
/home/xxxx/project/test/ndk/android-ndk-r9d/build/tools/make-standalone-toolchain.sh --platform=android-17 --install-dir=/home/xxxx/project/test/ndk/android-ndk-r9d/tmp/android-17-toolchain
make-standalone-toolchain.sh --platform=android-18 --install-dir=/home/yuhao/android-18-toolchain
1.交叉编译
下载libx265源码
下载地址:https://bitbucket.org/multicoreware/x265/downloads/
1.修改文件libx265/x265_2.5/build/arm-linux/crosscompile.cmake
源文件
5 set(CROSS_COMPILE_ARM 1)
6 set(CMAKE_SYSTEM_NAME Linux)
7 set(CMAKE_SYSTEM_PROCESSOR armv6l)
8
9 # specify the cross compiler
10 set(CMAKE_C_COMPILER arm-linux-androideabi-gcc)
11 set(CMAKE_CXX_COMPILER arm-linux-androideabi-g++)
12
13 # specify the target environment
14 SET(CMAKE_FIND_ROOT_PATH /home/yuhao/android-16-toolchain)
15
修改为
5 set(CROSS_COMPILE_ARM 1)
6 set(CMAKE_SYSTEM_NAME Linux)
7 set(CMAKE_SYSTEM_PROCESSOR armv6l)
8
9 # specify the cross compiler
10 set(CMAKE_C_COMPILER arm-linux-androideabi-gcc)
11 set(CMAKE_CXX_COMPILER arm-linux-androideabi-g++)
12
13 # specify the target environment
14 SET(CMAKE_FIND_ROOT_PATH /home/yuhao/android-18-toolchain)
15
16 set(CMAKE_SYSROOT /home/yuhao/android-18-toolchain/sysroot)
1.2修改libx265/x265_2.5/source/CMakeLists.txt
619 if(X265_LATEST_TAG)
620 # convert lists of link libraries into -lstdc++ -lm etc..
621 fore::ach(LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS})
622 if(IS_ABSOLUTE ${LIB} AND EXISTS ${LIB})
623 list(APPEND PLIBLIST "${LIB}")
624 else()
625 list(APPEND PLIBLIST "-l${LIB}")
626 endif()
627 endforeach()
628 if(PLIBLIST)
629 # blacklist of libraries that should not be in Libs.private
630 list(REMOVE_ITEM PLIBLIST "-lc" "-lpthread") //修改点
631 string(REPLACE ";" " " PRIVATE_LIBS "${PLIBLIST}")
632 else()
633 set(PRIVATE_LIBS "")
634 endif(PLIBLIST)
修改为
619 if(X265_LATEST_TAG)
620 # convert lists of link libraries into -lstdc++ -lm etc..
621 foreach(LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS})
622 if(IS_ABSOLUTE ${LIB} AND EXISTS ${LIB})
623 list(APPEND PLIBLIST "${LIB}")
624 else()
625 list(APPEND PLIBLIST "-l${LIB}")
626 endif()
627 endforeach()
628 if(PLIBLIST)
629 # blacklist of libraries that should not be in Libs.private
630 list(REMOVE_ITEM PLIBLIST "-lc") //修改点
631 string(REPLACE ";" " " PRIVATE_LIBS "${PLIBLIST}")
632 else()
633 set(PRIVATE_LIBS "")
634 endif(PLIBLIST)
当前文件libx265/x265_2.5/source/CMakeLists.txt
81 if(UNIX)
82 list(APPEND PLATFORM_LIBS pthread) //修改点
83 find_library(LIBRT rt)
84 if(LIBRT)
85 list(APPEND PLATFORM_LIBS rt)
86 endif()
修改为
81 if(UNIX)
82 # list(APPEND PLATFORM_LIBS pthread) //修改点
83 find_library(LIBRT rt)
84 if(LIBRT)
85 list(APPEND PLATFORM_LIBS rt)
86 endif()
2.安装编译所需要的软件
执行如下命令
sudo apt-get install cmake-curses-gui
3.配置编译信息
执行配置命令
cmake -DCMAKE_TOOLCHAIN_FILE=crosscompile.cmake -G "Unix Makefiles" ../../source && ccmake ../../source
执行如上命令会出现下图信息
CHECKED_BUILD OFF
CMAKE_BUILD_TYPE Release
CMAKE_INSTALL_PREFIX /home/yuhao/ytxPlayer/android/contrib/jni/jniLibs/x265
DETAILED_CU_STATS OFF
ENABLE_AGGRESSIVE_CHECKS OFF
ENABLE_ASSEMBLY OFF //关闭汇编
ENABLE_CLI ON
ENABLE_HDR10_PLUS OFF
ENABLE_LIBNUMA ON
ENABLE_PIC ON //打开PIC 位置无关
ENABLE_PPA OFF
ENABLE_SHARED ON
ENABLE_TESTS OFF
ENABLE_VTUNE OFF
FSANITIZE
HIGH_BIT_DEPTH OFF
LIBDL /home/yuhao/android-18-toolchain/sysroot/usr/lib/libdl.so
LIB_INSTALL_DIR lib
NO_ATOMICS OFF
NUMA_ROOT_DIR /usr
STATIC_LINK_CRT OFF
WARNINGS_AS_ERRORS OFF
YASM_EXECUTABLE /home/yuhao/android-18-toolchain/bin/yasm
输入c
然后输入g
修改文件CMakeFiles/x265-shared.dir/link.txt
arm-linux-androideabi-g++ -fPIC -O3 -DNDEBUG -Wl,-Bsymbolic,-znoexecstack -shared -Wl,-soname,libx265.so.130 -o libx265.so.130
修改为
arm-linux-androideabi-g++ -fPIC -O3 -DNDEBUG -Wl,-Bsymbolic,-znoexecstack -shared -o libx265.so
修改文件CMakeFiles/cli.dir/link.txt
-o x265 -rdynamic libx265.so.130
修改为
-o x265 -rdynamic libx265.so
修改文件./CMakeFiles/x265-shared.dir/build.make
187 libx265.so: encoder/CMakeFiles/encoder.dir/__/x265-extras.cpp.o
188 libx265.so: common/CMakeFiles/common.dir/arm/asm-primitives.cpp.o //修改点
189 libx265.so: common/CMakeFiles/common.dir/primitives.cpp.o
190 libx265.so: common/CMakeFiles/common.dir/pixel.cpp.o
191 libx265.so: common/CMakeFiles/common.dir/dct.cpp.o
192 libx265.so: common/CMakeFiles/common.dir/ipfilter.cpp.o
193 libx265.so: common/CMakeFiles/common.dir/intrapred.cpp.o
194 libx265.so: common/CMakeFiles/common.dir/loopfilter.cpp.o
195 libx265.so: common/CMakeFiles/common.dir/constants.cpp.o
196 libx265.so.130: common/CMakeFiles/common.dir/cpu.cpp.o
197 libx265.so.130: common/CMakeFiles/common.dir/version.cpp.o
198 libx265.so.130: common/CMakeFiles/common.dir/threading.cpp.o
199 libx265.so.130: common/CMakeFiles/common.dir/threadpool.cpp.o
200 libx265.so.130: common/CMakeFiles/common.dir/wavefront.cpp.o
201 libx265.so.130: common/CMakeFiles/common.dir/md5.cpp.o
202 libx265.so.130: common/CMakeFiles/common.dir/bitstream.cpp.o
203 libx265.so.130: common/CMakeFiles/common.dir/yuv.cpp.o
204 libx265.so.130: common/CMakeFiles/common.dir/shortyuv.cpp.o
205 libx265.so.130: common/CMakeFiles/common.dir/picyuv.cpp.o
206 libx265.so.130: common/CMakeFiles/common.dir/common.cpp.o
207 libx265.so.130: common/CMakeFiles/common.dir/param.cpp.o
208 libx265.so.130: common/CMakeFiles/common.dir/frame.cpp.o
209 libx265.so.130: common/CMakeFiles/common.dir/framedata.cpp.o
210 libx265.so.130: common/CMakeFiles/common.dir/cudata.cpp.o
211 libx265.so.130: common/CMakeFiles/common.dir/slice.cpp.o
212 libx265.so.130: common/CMakeFiles/common.dir/lowres.cpp.o
213 libx265.so.130: common/CMakeFiles/common.dir/piclist.cpp.o
214 libx265.so.130: common/CMakeFiles/common.dir/predict.cpp.o
215 libx265.so.130: common/CMakeFiles/common.dir/scalinglist.cpp.o
216 libx265.so.130: common/CMakeFiles/common.dir/quant.cpp.o
217 libx265.so.130: common/CMakeFiles/common.dir/deblock.cpp.o
218 libx265.so.130: CMakeFiles/x265-shared.dir/build.make
219 libx265.so.130: x265.def
220 libx265.so.130: CMakeFiles/x265-shared.dir/link.txt
221 @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/home/yuhao/ytxPlayer/android/contrib/libx265/tmp/x265_2.5/build/arm-lin
ux/CMakeFiles --progress-num=$(CMAKE_PROGRESS_10) "Linking CXX shared library libx265.so"
222 $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/x265-shared.dir/link.txt --verbose=$(VERBOSE)
223 $(CMAKE_COMMAND) -E cmake_symlink_library libx265.so.130 libx265.so.130 libx265.so
224
225 libx265.so: libx265.so.130
226 @$(CMAKE_COMMAND) -E touch_nocreate libx265.so
改为
187 libx265.so: encoder/CMakeFiles/encoder.dir/__/x265-extras.cpp.o
188 #libx265.so: common/CMakeFiles/common.dir/arm/asm-primitives.cpp.o //修改点
189 libx265.so: common/CMakeFiles/common.dir/primitives.cpp.o
190 libx265.so: common/CMakeFiles/common.dir/pixel.cpp.o
191 libx265.so: common/CMakeFiles/common.dir/dct.cpp.o
192 libx265.so: common/CMakeFiles/common.dir/ipfilter.cpp.o //将libx265.so.130改为libx265.so
193 libx265.so: common/CMakeFiles/common.dir/intrapred.cpp.o
194 libx265.so: common/CMakeFiles/common.dir/loopfilter.cpp.o
195 libx265.so: common/CMakeFiles/common.dir/constants.cpp.o
196 libx265.so: common/CMakeFiles/common.dir/cpu.cpp.o
197 libx265.so: common/CMakeFiles/common.dir/version.cpp.o
198 libx265.so: common/CMakeFiles/common.dir/threading.cpp.o
199 libx265.so: common/CMakeFiles/common.dir/threadpool.cpp.o
200 libx265.so: common/CMakeFiles/common.dir/wavefront.cpp.o
201 libx265.so: common/CMakeFiles/common.dir/md5.cpp.o
202 libx265.so: common/CMakeFiles/common.dir/bitstream.cpp.o
203 libx265.so: common/CMakeFiles/common.dir/yuv.cpp.o
204 libx265.so: common/CMakeFiles/common.dir/shortyuv.cpp.o
205 libx265.so: common/CMakeFiles/common.dir/picyuv.cpp.o
206 libx265.so: common/CMakeFiles/common.dir/common.cpp.o
207 libx265.so: common/CMakeFiles/common.dir/param.cpp.o
208 libx265.so: common/CMakeFiles/common.dir/frame.cpp.o
209 libx265.so: common/CMakeFiles/common.dir/framedata.cpp.o
210 libx265.so: common/CMakeFiles/common.dir/cudata.cpp.o
211 libx265.so: common/CMakeFiles/common.dir/slice.cpp.o
212 libx265.so: common/CMakeFiles/common.dir/lowres.cpp.o
213 libx265.so: common/CMakeFiles/common.dir/piclist.cpp.o
214 libx265.so: common/CMakeFiles/common.dir/predict.cpp.o
215 libx265.so: common/CMakeFiles/common.dir/scalinglist.cpp.o
216 libx265.so: common/CMakeFiles/common.dir/quant.cpp.o
217 libx265.so: common/CMakeFiles/common.dir/deblock.cpp.o
218 libx265.so: CMakeFiles/x265-shared.dir/build.make
219 libx265.so: x265.def
220 libx265.so: CMakeFiles/x265-shared.dir/link.txt
221 @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/home/yuhao/ytxPlayer/android/contrib/libx265/x265_2.5/build/arm-linux/C
MakeFiles --progress-num=$(CMAKE_PROGRESS_10) "Linking CXX shared library libx265.so"
222 $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/x265-shared.dir/link.txt --verbose=$(VERBOSE)
223 $(CMAKE_COMMAND) -E cmake_symlink_library libx265.so libx265.so libx265.so.130 //修改点
224
225 libx265.so.130: libx265.so
226 @$(CMAKE_COMMAND) -E touch_nocreate libx265.so.130 //修改点
将libx265.so.130
改为libx265.so
修改文件source/common/cpu.cpp
331 uint32_t cpu_detect(void)
332 {
333 int flags = 0;
334
335 #if HAVE_ARMV6
336 flags |= X265_CPU_ARMV6;
337
338 // don't do this hack if compiled with -mfpu=neon
339 #if !HAVE_NEON
340 static void (* oldsig)(int);
341 oldsig = signal(SIGILL, sigill_handler);
342 if (sigsetjmp(jmpbuf, 1))
343 {
344 signal(SIGILL, oldsig);
345 return flags;
346 }
347
348 canjump = 1;
349 PFX(cpu_neon_test)();
350 canjump = 0;
351 signal(SIGILL, oldsig);
352 #endif // if !HAVE_NEON
353
354 flags |= X265_CPU_NEON;
355
356 // fast neon -> arm (Cortex-A9) detection relies on user access to the
357 // cycle counter; this assumes ARMv7 performance counters.
358 // NEON requires at least ARMv7, ARMv8 may require changes here, but
359 // hopefully this hacky detection method will have been replaced by then.
360 // Note that there is potential for a race condition if another program or
361 // x264 instance disables or reinits the counters while x264 is using them,
362 // which may result in incorrect detection and the counters stuck enabled.
363 // right now Apple does not seem to support performance counters for this test
364 #ifndef __MACH__
365 flags |= PFX(cpu_fast_neon_mrc_test)() ? X265_CPU_FAST_NEON_MRC : 0;
366 #endif
367 // TODO: write dual issue test? currently it's A8 (dual issue) vs. A9 (fast mrc)
368 #endif // if HAVE_ARMV6
369
370 return flags;
371 }
修改为
uint32_t cpu_detect(void)
{
int flags = 0;
return flags;
}
执行make
命令