不同平台下移植x264

  一.   编译环境

    mips移植x264相关记录,mips交叉编译工具采用buildroot-gcc342版本,x264 版本x264-snapshot-20140831-2245。

    android 平台下移植, 采用android-ndk-r9d

  二. 移植到android 或者x86平台时候,配置脚本如下

     android ndk 编译脚本如下

mkdir platform/
mkdir platform/android/

export ARM_ROOT=/home/soft/linux_eclipse_tar/android-ndk-r9d
export ARM_INC=$ARM_ROOT/platforms/android-9/arch-arm/usr/include/
export ARM_LIB=$ARM_ROOT/platforms/android-9/arch-arm/usr/lib/
export ARM_TOOL=$ARM_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86
export ARM_LIBO=$ARM_TOOL/lib/gcc/arm-linux-androideabi/4.8
export PATH=$ARM_TOOL/bin:$PATH
export ARM_PRE=arm-linux-androideabi
export PLATFORM=$ARM_ROOT/platforms/android-9/arch-arm/

CPU=android
PREFIX=$(pwd)/platform/$CPU
./configure --prefix=$PREFIX \
--enable-static \
--enable-shared \
--disable-asm \
--host=arm-linux \
--cross-prefix=arm-linux-androideabi- \
--sysroot=$PLATFORM

make clean
make -j2
make install

 x86 平台编译脚本

mkdir x86

CPU=x86
PREFIX=$(pwd)/platform/$CPU
function build_one
{
./configure \
 --prefix=$PREFIX\
 --enable-shared\
 --enable-static\
 --disable-asm
}
build_one
make clean
make -j2
make install

mips 编译脚本

mkdir mips

export ARM_ROOT=/opt/buildroot-gcc342
export ARM_INC=$ARM_ROOT/include/
export ARM_LIB=$ARM_ROOT/lib
export ARM_PRE=$ARM_ROOT/bin/mipsel-linux
CPU=mips
PREFIX=$(pwd)/android/$CPU
HOST=mipsel-linux
function build_one
{
./configure \
 --disable-gpac\
 --prefix=$PREFIX\
 --enable-static\
 --enable-shared\
 --disable-asm\
 --host=$HOST\
 --cross-prefix=${ARM_PRE}-\
 --extra-cflags="-I$ARM_INC -fPIC -DANDROID -ffunction-sections -funwind-tables  -fno-short-enums  -msoft-float  -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -DANDROID  -Wa,--noexecstack -MMD -MP "\
 --extra-ldflags="-L$ARM_LIB -lmath"
}
build_one
make clean
make -j2
make install


三. android 和x86 平台移植编译都没问题

mips 下编译出现如下错误

错误 1:

common/cpu.c: In function `x264_cpu_num_processors':
common/cpu.c:447: error: `cpu_set_t' undeclared (first use in this function)
common/cpu.c:447: error: (Each undeclared identifier is reported only once
common/cpu.c:447: error: for each function iint x264_cpu_num_processors( void )
t appears in.)
common/cpu.c:447: error: parse error before "p_aff"
common/cpu.c:448: error: `p_aff' undeclared (first use in this function)
common/cpu.c:449: warning: implicit declaration of function `sched_getaffinity'
make: *** [common/cpu.o] Error 1
make: *** Waiting for unfinished jobs....
/opt/buildroot-gcc342/bin/mipsel-linux-gcc -Wshadow -O3 -ffast-math  -Wall -I. -I. -std=gnu99 -fPIC -fomit-frame-pointer   -c -o common/cpu.o common/cpu.c

这个函数主要是检测当前cpu个数,需要屏蔽如下代码

int x264_cpu_num_processors( void )

{
#if !HAVE_THREAD
    return 1;

#elif SYS_WINDOWS
    return x264_pthread_num_processors_np();

#elif SYS_CYGWIN || SYS_SunOS
    return sysconf( _SC_NPROCESSORS_ONLN );

#elif SYS_LINUX
#ifdef __ANDROID__
    // Android NDK does not expose sched_getaffinity
    return sysconf( _SC_NPROCESSORS_CONF );
#else
    //cpu_set_t p_aff;
    //memset( &p_aff, 0, sizeof(p_aff) );
    //if( sched_getaffinity( 0, sizeof(p_aff), &p_aff ) )
        return 1;
#if HAVE_CPU_COUNT
    return CPU_COUNT(&p_aff);
#else
    //int np = 0;
    //for( unsigned int bit = 0; bit < 8 * sizeof(p_aff); bit++ )
    //    np += (((uint8_t *)&p_aff)[bit / 8] >> (bit % 8)) & 1;
//    return np;
        return 1;

}


错误 2:

input/timecode.o: In function `correct_fps':timecode.c:(.text.correct_fps+0x148): undefined reference to `round'
input/timecode.o: In function `try_mkv_timebase_den':timecode.c:(.text.try_mkv_timebase_den+0xa8): undefined reference to `round'
input/timecode.o: In function `open_file':timecode.c:(.text.open_file+0xa00): undefined reference to `round'
:timecode.c:(.text.open_file+0xafc): undefined reference to `round'
:timecode.c:(.text.open_file+0x11c4): undefined reference to `round'
libx264.a(set.o): In function `x264_sps_init':set.c:(.text.x264_sps_init+0x904): undefined reference to `log2f'
libx264.a(encoder.o): In function `x264_validate_parameters':encoder.c:(.text.x264_validate_parameters+0x95c): undefined reference to `log2f'
:encoder.c:(.text.x264_validate_parameters+0x9a8): undefined reference to `log2f'
libx264.a(analyse.o): In function `x264_analyse_prepare_costs':analyse.c:(.text.x264_analyse_prepare_costs+0x70): undefined reference to `log2f'
libx264.a(analyse.o): In function `x264_weights_analyse':analyse.c:(.text.x264_weights_analyse+0x550): undefined reference to `roundf'
:analyse.c:(.text.x264_weights_analyse+0x5d4): undefined reference to `roundf'
libx264.a(analyse.o): In function `x264_macroblock_tree_finish':analyse.c:(.text.x264_macroblock_tree_finish+0x238): undefined reference to `round'
libx264.a(ratecontrol.o): In function `x264_ratecontrol_summary':ratecontrol.c:(.text.x264_ratecontrol_summary+0x1dc): undefined reference to `log2f'
libx264.a(ratecontrol.o): In function `x264_ratecontrol_slice_type':ratecontrol.c:(.text.x264_ratecontrol_slice_type+0x1c4): undefined reference to `log2f'
:ratecontrol.c:(.text.x264_ratecontrol_slice_type+0x32c): undefined reference to `log2f'
libx264.a(ratecontrol.o): In function `rate_estimate_qscale':ratecontrol.c:(.text.rate_estimate_qscale+0xf84): undefined reference to `log2f'
:ratecontrol.c:(.text.rate_estimate_qscale+0x1dd8): undefined reference to `log2f'
libx264.a(ratecontrol.o):ratecontrol.c:(.text.x264_ratecontrol_start+0x934): more undefined references to `log2f' follow
libx264.a(ratecontrol.o): In function `x264_ratecontrol_new':ratecontrol.c:(.text.x264_ratecontrol_new+0x508): undefined reference to `log2'
:ratecontrol.c:(.text.x264_ratecontrol_new+0x56c): undefined reference to `log2'
:ratecontrol.c:(.text.x264_ratecontrol_new+0x5bc): undefined reference to `log2'
:ratecontrol.c:(.text.x264_ratecontrol_new+0x83c): undefined reference to `log2f'
:ratecontrol.c:(.text.x264_ratecontrol_new+0x8ac): undefined reference to `log2f'
:ratecontrol.c:(.text.x264_ratecontrol_new+0x3f14): undefined reference to `log2f'
:ratecontrol.c:(.text.x264_ratecontrol_new+0x4ecc): undefined reference to `log2f'


解决:

log2 未定义,修改生成的config.h

把#define HAVE_LOG2F 1  改成

#define HAVE_LOG2F 0

round 是系统数学库函数,在mips 编译工具里面 lib 里面执行 objdump -tT *.so | grep "round"   查找所有库函数没有发现这个函数标签号,需要到网上下载这个数学库函数


#if defined MIPS_ROUND
#include <sys/cdefs.h>
/* __FBSDID("$FreeBSD: src/lib/msun/src/s_round.c,v 1.4 2005/12/02 13:45:06 bde Exp $"); */

#include <math.h>
#include <fpmath.h>
int
__isfinite(double d)
{
        union IEEEd2bits u;

        u.d = d;
        return (u.bits.exp != 2047);
}

int
__isfinitef(float f)
{
        union IEEEf2bits u;

        u.f = f;
        return (u.bits.exp != 255);
}
int
__isfinitel(long double e)
{
        union IEEEl2bits u;

        u.e = e;
        return (u.bits.exp != 32767);
}

double
round(double x)
{
        double t;

        if (!isfinite(x))
                return (x);

        if (x >= 0.0) {
                t = floor(x);
                if (t - x <= -0.5)
                        t += 1.0;
                return (t);
        } else {
                t = floor(-x);
                if (t + x <= -0.5)
                        t += 1.0;
                return (-t);
        }
}
float
roundf(float x)
{
        float t;

        if (!isfinite(x))
                return (x);

        if (x >= 0.0) {
                t = floorf(x);
                if (t - x <= -0.5)
                        t += 1.0;
                return (t);
        } else {
                t = floorf(-x);
                if (t + x <= -0.5)
                        t += 1.0;
                return (-t);
        }
}

将以上代码编译生成动态库, 拷贝到 buildroot-gcc342/lib/
编译成功







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值