本文來源電子發燒友社區,作者:離北況歸, 帖子地址:https://bbs.elecfans.com/jishu_2308798_1_1.html
由于想要分享的內容較多,為避免讀者姥爺們失去看下去的耐心,分享將以連載的方式進行。
下期預告:speexdsp功能分析和功能測試
本期為移植speexdsp到OpenHarmony標準系統
的第④期,主要內容如下:
@toc
speexdsp移植后已提交至openhamrony sig倉庫:https://gitee.com/openharmony-sig/contest/tree/master/2022_OpenHarmony_thirdparty/speexdsp
五、在OpenHarmony編譯體系下增量編譯Speexdsp
建議先增量編譯生成三方庫的動態鏈接庫和可執行文件,驗證是否成功把三方庫加入OpenHarmonybian編譯體系。
- 成功編譯出so和可執行文件,即成功把三方庫加入到ohos編譯體系。之后還要驗證三方庫在ohos運行,功能是否正常。功能正常才能視為移植成功。
推薦增量編譯出三方庫的動態鏈接庫和測試用例,不推薦的做法是把三方庫加入openharmony編譯體系后全量編譯出燒錄ohos用的固件。
- 第一是因為全量編譯ohos對電腦的性能,特別是內存要求比較高(筆者的筆記本上的虛擬機內存給到了32G,對學生開發者來講,編譯ohos的硬件門檻還是有點高的。)增量編譯對內存要求不是特別高。(筆者的8G內存二合一筆記本都可以編譯出來,并且虛擬機內存只給到了4GB左右)
- 第二是因為全量編譯花費時間較多(筆者完整編譯出一個固件需要3個小時左右。)增量編譯需要的時間相對較少(筆者大概只需要花費9分鐘左右)
全量編譯和增量編譯概念
- 全量編譯是將所有文件重新編譯,重新生成解決方案就是全量編譯
- 增量編譯只對改動的文件進行編譯,執行生成解決方案就是增量編譯
在源碼目錄執行如下命令,進行增量編譯:
./build.sh --product-name rk3568 --ccache --build-target=speexdsp --target-cpu arm64
-
ohos3.2beta1
版本開始新增特性,支持64位系統的編譯,默認情況下編譯的都是32位系統,在編譯命令中添加--target-cpu arm64
即可構建64位系統,編譯so和可執行文件的執行語句更改為:
加快本地編譯的一些參數
編譯時,適當選擇添加以下的編譯參數可以加快編譯的過程。
- 添加--ccache參數:
- 添加--fast-rebuild參數
- 原理:編譯流程主要分為:preloader->loader->gn->ninja這四個過程,在本地沒有修改gn和產品配置相關文件的前提下,添加--fast-rebuild會讓你直接從ninja編譯開始。
- 使用:執行./build.sh --product-name 產品名 --fast-rebuild命令。
- 添加enable_notice_collection=false參數
- 原理:省略掉收集開源軟件模塊的license的過程。
- 使用:執行./build.sh --product-name 產品名 --gn-args --enable_notice_collection=false --ccache命令。
- 添加--build-target參數
- 該參數用于指定編譯模塊,如何找模塊的名字:
- 相關倉下BUILD.gn中關注group、ohos_shared_library、ohos_executable等關鍵字。
- ./build.sh --product-name 產品名 --build-target 模塊名 --build-only-gn生成build.ninja,然后去該文件中查找相關模塊名。
- 使用:執行./build.sh --product-name 產品名 --build-target ark_js_host_linux_tools_packages命令。
解決編譯報錯
(筆者理解移植過程肯定不會是一帆風順的)
執行編譯命令后,有部分報錯
1.部分頭文件缺失報錯‘speexdsp_config_types.h’ file not found
編譯找不到third_party/speexdsp/include/speex目錄下的speexdsp_config_types.h文件。
../../third_party/speexdsp/include/speex/speexdsp_types.h:122:10: fatal error:
'speexdsp_config_types.h' file not found
解決辦法:
- speexdsp_types.h 是由linux下編譯生成的,因此需要在Linux下編譯整個Speexdsp源碼,然后把在speexdsp原生庫目錄下build/include/speex目錄生成的speexdsp_types.h文件拷貝到要ohos源碼下的third_party/speexdsp/include/speex目錄下,
2.json文件語法發生錯誤。
解決方法:
查看out/rk3568目錄下build.log文件,檢查源碼/build/subsystem_config.json文件語法
筆者出現這個問題的原因是json文件語法發生錯誤,在subsystem_config.json文件第一行的{
沒有匹配}
,添加上去就沒問題。
編譯成功
解決完編譯報錯后,再次執行編譯命令。
./build.sh --product-name rk3568 --ccache --build-target=speexdsp --target-cpu arm64
編譯成功,終端打印信息如下:
(下面只選取關鍵的一小部分,實際打印出來的信息有兩千行左右。)
jiajiahao@ubuntu:~/Desktop/OpenHarmony/sources$ ./build.sh --product-name rk3568 --ccache --build-target=speexdsp --target-cpu arm64
++++++++++++++++++++++++++++++++++++++++
2022-09-07 22:03:47
--product-name rk3568 --ccache --build-target=speexdsp --target-cpu arm64
......
······
[OHOS INFO] [1595/1633] STAMP obj/third_party/speexdsp/speexdsp_share.inputdeps.stamp
[OHOS INFO] [1596/1633] CC obj/out/rk3568/obj/third_party/musl/intermidiates/linux/musl_src_ported/src/unistd/soft_musl_src/ttyname_r.o
[OHOS INFO] [1597/1633] CC obj/out/rk3568/obj/third_party/musl/intermidiates/linux/musl_src_ported/src/unistd/soft_musl_src/ualarm.o
[OHOS INFO] [1598/1633] CC obj/out/rk3568/obj/third_party/musl/intermidiates/linux/musl_src_ported/src/unistd/soft_musl_src/unlink.o
[OHOS INFO] [1599/1633] CC obj/out/rk3568/obj/third_party/musl/intermidiates/linux/musl_src_ported/src/unistd/soft_musl_src/unlinkat.o
[OHOS INFO] [1600/1633] CC obj/out/rk3568/obj/third_party/musl/intermidiates/linux/musl_src_ported/src/unistd/soft_musl_src/usleep.o
[OHOS INFO] [1601/1633] CC obj/out/rk3568/obj/third_party/musl/intermidiates/linux/musl_src_ported/src/unistd/soft_musl_src/write.o
[OHOS INFO] [1602/1633] CC obj/out/rk3568/obj/third_party/musl/intermidiates/linux/musl_src_ported/src/unistd/soft_musl_src/writev.o
[OHOS INFO] [1603/1633] CC obj/out/rk3568/obj/third_party/musl/intermidiates/linux/musl_src_ported/src/string/soft_musl_src_nossp/mempcpy.o
[OHOS INFO] [1604/1633] CC obj/out/rk3568/obj/third_party/musl/intermidiates/linux/musl_src_ported/src/string/soft_musl_src_nossp/memset.o
[OHOS INFO] [1605/1633] STAMP obj/third_party/musl/soft_musl_src.stamp
[OHOS INFO] [1606/1633] CC obj/third_party/speexdsp/libspeexdsp/speexdsp_share/buffer.o
[OHOS INFO] [1607/1633] CC obj/third_party/speexdsp/libspeexdsp/speexdsp_share/fftwrap.o
[OHOS INFO] [1608/1633] CC obj/third_party/speexdsp/libspeexdsp/speexdsp_share/filterbank.o
[OHOS INFO] [1609/1633] CC obj/out/rk3568/obj/third_party/musl/intermidiates/linux/musl_src_ported/src/env/soft_musl_src_nossp/__libc_start_main.o
[OHOS INFO] [1610/1633] CC obj/third_party/speexdsp/libspeexdsp/speexdsp_share/scal.o
[OHOS INFO] [1611/1633] ASM obj/out/rk3568/obj/third_party/musl/intermidiates/linux/musl_src_ported/src/thread/aarch64/soft_musl_src_nossp/__set_thread_area.o
[OHOS INFO] [1612/1633] CC obj/out/rk3568/obj/third_party/musl/intermidiates/linux/musl_src_ported/src/env/soft_musl_src_nossp/__init_tls.o
[OHOS INFO] [1613/1633] CC obj/out/rk3568/obj/third_party/musl/intermidiates/linux/musl_src_ported/src/env/soft_musl_src_nossp/__stack_chk_fail.o
[OHOS INFO] [1614/1633] STAMP obj/third_party/musl/soft_musl_src_nossp.stamp
[OHOS INFO] [1615/1633] CC obj/third_party/speexdsp/libspeexdsp/speexdsp_share/jitter.o
[OHOS INFO] [1616/1633] CC obj/third_party/speexdsp/libspeexdsp/speexdsp_share/preprocess.o
[OHOS INFO] [1617/1633] CC obj/third_party/speexdsp/libspeexdsp/speexdsp_share/resample.o
[OHOS INFO] [1618/1633] CC obj/third_party/speexdsp/libspeexdsp/speexdsp_share/mdf.o
[OHOS INFO] [1619/1633] SOLINK obj/third_party/musl/usr/lib/aarch64-linux-ohos/libc.so
[OHOS INFO] [1620/1633] STAMP obj/third_party/musl/soft_shared_libs.stamp
[OHOS INFO] [1621/1633] STAMP obj/build/config/common_deps.stamp
[OHOS INFO] [1622/1633] STAMP obj/build/config/executable_deps.stamp
[OHOS INFO] [1623/1633] STAMP obj/build/config/shared_library_deps.stamp
[OHOS INFO] [1624/1633] CC obj/third_party/speexdsp/libspeexdsp/speexdsp_share/smallft.o
[OHOS INFO] [1625/1633] SOLINK speexdsp/speexdsp/libspeexdsp_share.z.so
[OHOS INFO] [1626/1633] LINK speexdsp/speexdsp/testdenoise
[OHOS INFO] [1627/1633] LINK speexdsp/speexdsp/testecho
[OHOS INFO] [1628/1633] LINK speexdsp/speexdsp/testjitter
[OHOS INFO] [1629/1633] LINK speexdsp/speexdsp/testresample
[OHOS INFO] [1630/1633] LINK speexdsp/speexdsp/testresample2
[OHOS INFO] [1631/1633] STAMP obj/out/rk3568/build_configs/speexdsp/speexdsp/speexdsp_info.stamp
[OHOS INFO] [1632/1633] ACTION //out/rk3568/build_configs/speexdsp/speexdsp:speexdsp(//build/toolchain/ohos:ohos_clang_arm64)
[OHOS INFO] [1633/1633] STAMP obj/out/rk3568/build_configs/speexdsp/speexdsp/speexdsp.stamp
[OHOS INFO] ---------------------------------------------
[OHOS INFO] ccache summary:
[OHOS INFO] cache hit (direct) : 0
[OHOS INFO] cache hit (preprocessed) : 0
[OHOS INFO] cache miss : 1340
[OHOS INFO] hit rate: 0.00%
[OHOS INFO] mis rate: 100.00%
[OHOS INFO] ---------------------------------------------
[OHOS INFO] c targets overlap rate statistics
[OHOS INFO] subsystem files NO. percentage builds NO. percentage overlap rate
[OHOS INFO] aafwk 25 0.9% 25 0.9% 1.00
[OHOS INFO] arkui 11 0.4% 11 0.4% 1.00
[OHOS INFO] bundlemanager 45 1.5% 45 1.5% 1.00
[OHOS INFO] communication 197 6.7% 197 6.7% 1.00
[OHOS INFO] hiviewdfx 32 1.1% 32 1.1% 1.00
[OHOS INFO] securec 78 2.7% 78 2.7% 1.00
[OHOS INFO] speexdsp 14 0.5% 14 0.5% 1.00
[OHOS INFO] startup 46 1.6% 46 1.6% 1.00
[OHOS INFO] third_party 1065 36.3% 1065 36.3% 1.00
[OHOS INFO] thirdparty 1065 36.3% 1065 36.3% 1.00
[OHOS INFO] utils 58 2.0% 58 2.0% 1.00
[OHOS INFO] zxing-cpp-1.2.0 117 4.0% 117 4.0% 1.00
[OHOS INFO]
[OHOS INFO] c overall build overlap rate: 1.00
[OHOS INFO]
[OHOS INFO]
[OHOS INFO] rk3568 build success
[OHOS INFO] cost time: 0:02:24
=====build successful=====
驗證編譯結果
編譯speexdsp生成的動態鏈接庫和測試用的可執行程序,在openharmony源碼目錄的out/rk3568下。
out/rk3568/speexdsp目錄結構如下:
├── libspeexdsp_share.z.so # 動態鏈接庫
├── testdenoise # 測試用例
├── testecho # 測試用例
├── testjitter # 測試用例
├── testresample # 測試用例
└── testresample2 # 測試用例
六、API接口導出
在源碼third_party/speexdsp目錄下新建export_api文件夾。
1.在export_api目錄下新建allHeads.h文件
該頭文件中包含所有庫對外導出的頭文件。speexdsp有5個測試程序testdenoise、testecho、testjitter、testresample、testresample2。
查看這五個測試程序的源文件testdenoise.c、testecho.c、testjitter.c、testresample.c、testresample2.c。
其用到的libspeexdsp_share.z.so的頭文件如下:
#include "speex_preprocess.h"
#include "speex_echo.h"
#include "speex_jitter.h"
#include "speex_resampler.h"
2.新增allDySos目錄,該目錄下放置生成的動態庫:
3、新增allTests目錄,該目錄下放置所有生成的測試文件:
4、新建自動化測試腳本export_interface.sh,如下所示:
其中cxx="0"表示根據.c文件進行導出,cxx="1"則表示根據.cpp文件進行導出(如果導出c++的三方庫的api接口,使用該腳本就讓cxx=1):
#!/bin/sh
#C庫
cxx="0"
mixed_api() {
while read line
do
if [ $cxx != "1" -o "$4" == "1" ];then
tmp=$line
else
tmp=`echo $line | sed "s/(.*$//g" | sed "s/^.*:://g"`
fi
res=`cat $2 |grep "$tmp" -F`
if [ "$res" != "" ];then
echo "$line" >> $3
fi
done < $1
}
remove_standard_api() {
flag="0"
while read line
do
tmp1=`echo $line |grep ".*#.*/usr/"`
tmp2=`echo $line |grep ".*#.*[0-9].*".*""`
if [ "$tmp1" != "" ];then
flag="0"
elif [ "$tmp2" != "" ];then
flag="1"
elif [ $flag == "1" ];then
echo "$line" >> $2
fi
done < $1
}
src1="allHeads.h"
src2="allDySos"
src3="allTests"
if [ $cxx == "1" ];then
flags_D="-DC"
flags_DU="-DCu"
CC=g++
else
flags_D="-D"
flags_DU="-Du"
CC=gcc
fi
if [ ! -e $src1 ];then
echo "$src1 is not exist!"
exit 1
fi
if [ ! -e $src2 ];then
echo "$src2 is not exist!"
exit 1
fi
if [ ! -e $src3 ];then
echo "$src3 is not exist!"
exit 1
fi
rm -rf $src1.i* $src2.txt $src3.txt export_api.txt tested_api.txt
$CC -E $* $src1 -o $src1.i
if [ "$?" != "0" ];then
exit 1
fi
remove_standard_api $src1.i $src1.i.tmp
nm $src2/* $flags_D | sort -u | grep " T " | sed "s/^.* T //g" >> $src2.txt
nm $src3/* $flags_DU | sort -u | sed "s/^.* U //g" >> $src3.txt
mixed_api $src2.txt $src1.i.tmp export_api.txt 0
mixed_api export_api.txt $src3.txt tested_api.txt 1
rm -rf $src1.i* $src2.txt $src3.txt
執行腳本導出api接口
執行該腳本導出api接口時,需要給腳本傳入編譯頭文件的參數。(運行此api接口導出腳本在PC端)
-
例如
./export_interface.sh -I 頭文件所在路徑 -D宏定義(編譯所有動態庫時,cflags/cflags_cc中的參數)
- 頭文件所在路徑為絕對路徑
- D宏定義指的是(編譯所有動態庫時,cflags/cflags_cc中的參數)
筆者導出speexdsp API接口,在export_api文件夾下打開終端輸入了如下命令:
chmod 777 export_interface.sh
./export_interface.sh -I/home/jiajiahao/Desktop/OpenHarmony/sources/third_party/speexdsp/include/speex
結果是生成export_api.txt(導出so對外api接口)與testd_api.txt(導出測試程序所用到so對外導出api接口 )。
export_api.txt文件內容如下:
speex_preprocess_state_init
speex_preprocess_state_destroy
speex_preprocess
speex_preprocess_run
speex_preprocess_estimate_update
speex_preprocess_ctl
jitter_buffer_init
jitter_buffer_ctl
jitter_buffer_reset
jitter_buffer_destroy
jitter_buffer_put
jitter_buffer_get
jitter_buffer_get_another
jitter_buffer_update_delay
jitter_buffer_get_pointer_timestamp
jitter_buffer_tick
jitter_buffer_remaining_span
speex_echo_state_init
speex_echo_state_init_mc
speex_echo_state_reset
speex_echo_state_destroy
speex_echo_capture
speex_echo_cancellation
speex_echo_playback
speex_echo_cancel
speex_echo_ctl
speex_resampler_init
speex_resampler_init_frac
speex_resampler_set_quality
speex_resampler_set_rate_frac
speex_resampler_destroy
speex_resampler_process_float
speex_resampler_process_int
speex_resampler_process_interleaved_float
speex_resampler_process_interleaved_int
speex_resampler_set_rate
speex_resampler_get_rate
speex_resampler_get_ratio
speex_resampler_get_quality
speex_resampler_set_input_stride
speex_resampler_get_input_stride
speex_resampler_set_output_stride
speex_resampler_get_output_stride
speex_resampler_get_input_latency
speex_resampler_get_output_latency
speex_resampler_skip_zeros
speex_resampler_reset_mem
speex_resampler_strerror
speex_decorrelate_new
speex_decorrelate
speex_decorrelate_destroy
tested_api.txt文件內容如下:
speex_preprocess_state_init
speex_preprocess_state_destroy
speex_preprocess
speex_preprocess_run
speex_preprocess_ctl
jitter_buffer_init
jitter_buffer_reset
jitter_buffer_put
jitter_buffer_get
jitter_buffer_tick
speex_echo_state_init
speex_echo_state_destroy
speex_echo_cancellation
speex_echo_cancel
speex_echo_ctl
speex_resampler_init
speex_resampler_destroy
speex_resampler_process_float
speex_resampler_set_rate
speex_resampler_skip_zeros
下期預告:speexdsp功能分析和功能測試
-
dayu200
+關注
關注
1文章
26瀏覽量
1193 -
潤和軟件
+關注
關注
1文章
266瀏覽量
867
發布評論請先 登錄
相關推薦
評論