第一步,制作独立交叉编译链,我使用ndkr9制作的, 使用API 9平台,gcc4.6
进入ndk目录,执行
Shell
$ ./build/tools/make-standalone-toolchain.sh --platform=android-9 --install-dir=/home/aliang/arm-linux-androideabi
1
$./build/tools/make-standalone-toolchain.sh--platform=android-9--install-dir=/home/aliang/arm-linux-androideabi
第二部,修改x264的configure
libpthread=""
if [ "$thread" = "auto" ]; then
thread="no"
case $SYS in
BEOS)
thread="beos"
define HAVE_BEOSTHREAD
;;
WINDOWS)
if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
thread="posix"
libpthread="-lpthread"
elif cc_check pthread.h -lpthreadGC2 "pthread_create(0,0,0,0);" ; then
thread="posix"
libpthread="-lpthreadGC2"
elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
thread="posix"
libpthread="-lpthreadGC2 -lwsock32"
define PTW32_STATIC_LIB
elif cc_check pthread.h "-lpthreadGC2 -lws2_32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
thread="posix"
libpthread="-lpthreadGC2 -lws2_32"
define PTW32_STATIC_LIB
else
# default to native threading if pthread-win32 is unavailable
thread="win32"
fi
;;
QNX)
cc_check pthread.h -lc && thread="posix" && libpthread="-lc"
;;
*)
cc_check pthread.h -lc && thread="posix" && libpthread="-lc"
;;
esac
fi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
libpthread=""
if["$thread"="auto"];then
thread="no"
case$SYSin
BEOS)
thread="beos"
defineHAVE_BEOSTHREAD
;;
WINDOWS)
ifcc_checkpthread.h-lpthread"pthread_create(0,0,0,0);";then
thread="posix"
libpthread="-lpthread"
elifcc_checkpthread.h-lpthreadGC2"pthread_create(0,0,0,0);";then
thread="posix"
libpthread="-lpthreadGC2"
elifcc_checkpthread.h"-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB""pthread_create(0,0,0,0);";then
thread="posix"
libpthread="-lpthreadGC2 -lwsock32"
definePTW32_STATIC_LIB
elifcc_checkpthread.h"-lpthreadGC2 -lws2_32 -DPTW32_STATIC_LIB""pthread_create(0,0,0,0);";then
thread="posix"
libpthread="-lpthreadGC2 -lws2_32"
definePTW32_STATIC_LIB
else
# default to native threading if pthread-win32 is unavailable
thread="win32"
fi
;;
QNX)
cc_checkpthread.h-lc&&thread="posix"&&libpthread="-lc"
;;
*)
cc_checkpthread.h-lc&&thread="posix"&&libpthread="-lc"
;;
esac
fi
改为红色行的内容,因为android的ndk虽然有pthread.h,但是没有libpthread.a,集成到libc.a里了
第三步,定位到制作的独立编译链的头文件目录 /home/aliang/arm-linux-androideabi/sysroot/usr/include/
使用这个sched.h替换原有的sched.h文件
ok
./configure –host=arm-linux-androideabi –cross-prefix=arm-linux-androideabi-
可以看到,已经支持多线程了
platform: ARM
system: LINUX
cli: yes
libx264: internal
shared: no
static: no
asm: yes
interlaced: yes
avs: avxsynth
lavf: no
ffms: no
gpac: no
gpl: yes
thread: posix
opencl: yes
filters: crop select_every
debug: no
gprof: no
strip: no
PIC: no
visualize: no
bit depth: 8
chroma format: all
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
platform:ARM
system:LINUX
cli:yes
libx264:internal
shared:no
static:no
asm:yes
interlaced:yes
avs:avxsynth
lavf:no
ffms:no
gpac:no
gpl:yes
thread:posix
opencl:yes
filters:cropselect_every
debug:no
gprof:no
strip:no
PIC:no
visualize:no
bitdepth:8
chromaformat:all
效果如何,我测试下看看
*************呃 不用试了,NDK头文件里虽然申明了方法,c库里却没有实现****************
好吧 解决方法当然是有的,修改x264/common/cpu.c
通过读取/sys/devices/system/cpu/present文件判断cpu核心数
0 单核
0-1 双核
0-3 四核
sched.h还是用以前的吧
C
int getNrOfCPUs()
{
FILE* fp;
int res, i = -1, j = -1;
/* open file */
fp = fopen("/sys/devices/system/cpu/present", "r");
if (fp == 0)
{
return -1; /* failure */
}
/* read and interpret line */
res = fscanf(fp, "%d-%d", &i, &j);
/* close file */
fclose(fp);
/* interpret result */
if (res == 1 && i == 0) /* single-core? */
{
return 1;
}
if (res == 2 && i == 0) /* 2+ cores */
{
return j+1;
}
return 1; /* failure */
}
int x264_cpu_num_processors( void )
{
return getNrOfCPUs();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
intgetNrOfCPUs()
{
FILE*fp;
intres,i=-1,j=-1;
/* open file */
fp=fopen("/sys/devices/system/cpu/present","r");
if(fp==0)
{
return-1;/* failure */
}
/* read and interpret line */
res=fscanf(fp,"%d-%d",&i,&j);
/* close file */
fclose(fp);
/* interpret result */
if(res==1&&i==0)/* single-core? */
{
return1;
}
if(res==2&&i==0)/* 2+ cores */
{
returnj+1;
}
return1;/* failure */
}
intx264_cpu_num_processors(void)
{
returngetNrOfCPUs();
}