Android Faad静态库与aac解码

build_android.sh
#!/bin/bash

export NDK_HOME=/android-ndk-r10e
export SYSROOT=$NDK_HOME/platforms/android-9/arch-arm/
export TOOLCHAIN=$NDK_HOME/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64
export CPU=arm
export PREFIX=$(pwd)/android/$CPU

CFLAGS="-fpic -DANDROID -fpic -mthumb-interwork -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -Wno-psabi -march=armv5te -mtune=xscale -msoft-float -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -DANDROID -Wa,--noexecstack -MMD -MP "
CROSS_COMPILE=$TOOLCHAIN/bin/arm-linux-androideabi-
export CPPFLAGS="$CFLAGS"
export CFLAGS="$CFLAGS"
export CXXFLAGS="$CFLAGS"
export CXX="${CROSS_COMPILE}g++ --sysroot=${SYSROOT}"
export LDFLAGS="$LDFLAGS"
export CC="${CROSS_COMPILE}gcc --sysroot=${SYSROOT}"
export NM="${CROSS_COMPILE}nm"
export STRIP="${CROSS_COMPILE}strip"
export RANLIB="${CROSS_COMPILE}ranlib"
export AR="${CROSS_COMPILE}ar"
#export LIBS="-lm"

./configure --prefix=$PREFIX \
--without-mp4v2 \
--host=arm-linux

make clean
make
make install

解码
#include 
#include 
#include "playSdkMacro.h"
unsigned int adts_sample_rates[] = {96000,88200,64000,48000,44100,32000,24000,22050,16000,12000,11025,8000,7350,0,0,0};

int aac_Decode(char *src, char *dest, int srclen, int *dstlen)
{
    unsigned long samplerate;
    unsigned char channels;
    NeAACDecFrameInfo frameInfo;

    samplerate = adts_sample_rates[(src[2]&0x3c)>>2];
    channels =  ( (src[3]&0xc0)>>6 ) | ( (src[2]&0x1)<<2 );

    NeAACDecHandle m_aac_handle;
    NeAACDecConfigurationPtr config;

    m_aac_handle = NeAACDecOpen();//创建解码器
    if(m_aac_handle)
    {
        config = NeAACDecGetCurrentConfiguration(m_aac_handle);
        config->defObjectType = LC;
        config->defSampleRate = samplerate;
        config->outputFormat = FAAD_FMT_16BIT;
        config->dontUpSampleImplicitSBR = 1;
        config->downMatrix = 0;
        config->useOldADTSFormat = 0;
        NeAACDecSetConfiguration(m_aac_handle, config);//配置解码器
        NeAACDecInit(m_aac_handle, src, srclen,  &samplerate, &channels);//初始化faad解码句柄
        //NeAACDecDecode(m_aac_handle, &frameInfo, src, srclen);//解码
        NeAACDecDecode2(m_aac_handle, &frameInfo, src, srclen, (void **)&dest, dstlen);//解码
        AIPU_LOGI("> error:%d samples:%d samplerate:%d channels:%d\n",frameInfo.error, frameInfo.samples, frameInfo.samplerate, frameInfo.channels);
        AIPU_LOGI("< srclen:%d dstlen:%d\n",srclen, dstlen);
    }

    return 0;
}

你可能感兴趣的:(Android Faad静态库与aac解码)