編輯:關於 Android 程式設計
最近專案裡需要處理 AAC 音訊的解碼工作,我在網上查閱資料時,發現主流大致可以分成兩條路走。這裡把整個嘗試過程記錄下來,希望能幫到同樣在做 AAC 解碼的開發者。
第一種思路是使用 FFmpeg。當我執行 ./configure --list-decoders 時,確實能看到內建的 AAC 解碼器,在 x86 平台上編譯後也能正常啟用。然而當我改用 NDK 進行交叉編譯時,即便加上 --enable-decoder=aac 參數,AAC 解碼器仍然沒有被真正打開,於是這條路只能先擱置。
第二種思路則是直接採用 faad2 來解碼。我先在 x86 環境下除錯,寫一個能成功解碼 AAC 的 demo,驗證無誤後再进行交叉編譯,最終也順利產出了可用的庫。因此我選擇了第二種方案,並把步驟整理如下。
1. 下載 faad2 源碼
前往官網下載 faad,當時的最新版本為 2.7。
2. 建立專案目錄
新建一個名為 AACDecoder 的文件夾,並進入該目錄。
3. 解壓並重命名
將下載的 faad 源碼加壓後,重新命名為 jni。
4. 建立 Android.mk 與 Application.mk
首先在 jni 目錄下建立 Android.mk:
LOCAL_PATH := $(call my-dir) FAAD2_TOP := $(LOCAL_PATH) include $(CLEAR_VARS) include $(FAAD2_TOP)/libfaad/Android.mk
接著建立 Application.mk(若不建立也不影響編譯):
APP_ABI := armeabi
5. 建立 config.h
這個檔案通常由 configure 腳本生成,在 NDK 環境下需要手動建立,內容如下:
/* config.h. Generated from config.h.in by configure. */ /* Define to 1 if you have the <dlfcn.h> header file. */ #define HAVE_DLFCN_H 1 /* Define to 1 if you have the <errno.h> header file. */ #define HAVE_ERRNO_H 1 /* Define to 1 if you have the <float.h> header file. */ #define HAVE_FLOAT_H 1 /* Define to 1 if you have the <inttypes.h> header file. */ #define HAVE_INTTYPES_H 1 /* Define to 1 if you have the <limits.h> header file. */ #define HAVE_LIMITS_H 1 /* Define if you have C99's lrintf function. */ #define HAVE_LRINTF 1 /* Define to 1 if you have the <stdint.h> header file. */ #define HAVE_STDINT_H 1 /* Define to 1 if you have the <stdlib.h> header file. */ #define HAVE_STDLIB_H 1 /* Define to 1 if you have the <string.h> header file. */ #define HAVE_STRING_H 1 /* Define to 1 if you have the <strings.h> header file. */ #define HAVE_STRINGS_H 1 /* Define to 1 if you have the <sys/stat.h> header file. */ #define HAVE_SYS_STAT_H 1 /* Define to 1 if you have the <sys/types.h> header file. */ #define HAVE_SYS_TYPES_H 1 /* Define to 1 if you have the <unistd.h> header file. */ #define HAVE_UNISTD_H 1 /* Name of package */ #define PACKAGE "faad2" /* Version number of package */ #define VERSION "2.7.0" /* Define to 1 if you have the ANSI C header files. */ #define STDC_HEADERS 1
其餘如 DRM、DRM_PS、WORDS_BIGENDIAN 等選項在一般 Android 場景下保持 /* #undef */ 註釋狀態即可。
6. 在 libfaad 目錄下建立 Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
bits.c \
cfft.c \
decoder.c \
drc.c \
drm_dec.c \
error.c \
filtbank.c \
ic_predict.c \
is.c \
lt_predict.c \
mdct.c \
mp4.c \
ms.c \
output.c \
pns.c \
ps_dec.c \
ps_syntax.c \
pulse.c \
specrec.c \
syntax.c \
tns.c \
hcr.c \
huffman.c \
rvlc.c \
ssr.c \
ssr_fb.c \
ssr_ipqf.c \
common.c \
sbr_dct.c \
sbr_e_nf.c \
sbr_fbt.c \
sbr_hfadj.c \
sbr_hfgen.c \
sbr_huff.c \
sbr_qmf.c \
sbr_syntax.c \
sbr_tf_grid.c \
sbr_dec.c
LOCAL_MODULE:= libfaad
LOCAL_C_INCLUDES := \
$(LOCAL_PATH) \
$(FAAD2_TOP)/android \
$(FAAD2_TOP)/include \
$(LOCAL_PATH)/codebook
LOCAL_CFLAGS:=
-DHAVE_CONFIG_H
include $(BUILD_SHARED_LIBRARY)
7. 執行編譯
在 jni 目錄下執行 ndk-build。
8. 編譯結果
當所有原始檔逐一編譯完成後,最後會看到類似以下的輸出:
SharedLibrary : libfaad.so Install : libfaad.so => libs/armeabi/libfaad.so
看到 libfaad.so 成功安裝到 libs/armeabi/ 目錄,就代表交叉編譯圓滿完成,接著便可在 Android 專案中透過 JNI 呼叫它來進行 AAC 解碼了。
Android 仿微信朋友圈:多圖瀏覽效果完整實作
先來看看最終效果: 下面說明具體的實作方式。 實作思路 1. 準備資料來源,也就是每一則貼文(含姓名、標題與圖片陣列)。 2. 自訂 Adapter(ListView
從零搭建 C# Android 開發環境:JDK、SDK、VS2015 與 Xamarin 完整圖文
工欲善其事,必先利其器。不論你打算用 C# + VS2015 還是 Java + Eclipse 開發 Android,都得先把 JDK 與 Android SDK 裝好
Android 為 EditText 搜尋框的 ListView 實作即時篩選顯示
「根據 EditText 搜尋框即時過濾 ListView 資料」這個需求聽起來挺有意思,牽涉到的知識點也不少,於是動手寫了一遍,整理成文,希望能給需要的朋友一點參考。先
AppBarLayout + TabLayout + RecyclerView + ViewPager 實作可協同滑動的頭部
有人丟來一張效果圖,希望做出一個「Banner 捲出畫面後,標題欄吸頂」的頁面。仔細看起來不難,但要把 Material Design 那套協同滑動的規則串起來,還是得先