【20240227】银河麒麟V4系统(4.4.131-20200604)源码编译ZLMediaKit

【20240227】银河麒麟V4系统(4.4.131-20200604)源码编译ZLMediaKit

0 前言

转载请附上原文出处链接

稀土掘金本文链接:juejin.cn/post/734090...

CSDN本文链接:blog.csdn.net/qq_43252610...

1 编译环境

系统版本:

shell 复制代码
uname -a

4.4.131-20200604.kylin.desktop.android-generic #kylin SMP Thu Jun 4 14:00:02 CST 2020 aarch64 aarch64 aarch64 GNU/Linux

2 下载ZLMediaKit源码

我这次使用的是主线代码(选用commit644a333

ZLMediaKit:github.com/ZLMediaKit/...

2.1 通过git下载

更新apt源并安装git

shell 复制代码
sudo apt update

sudo apt install git

如果有网络环境,最好是通过git下载,这样可以自动下载第三方代码

shell 复制代码
# gitee在国内访问不会有问题
git clone https://gitee.com/xia-chu/ZLMediaKit

cd ZLMediaKit

# 下载子模块代码
git submodule update --init

如果需要切换到特定分支

shell 复制代码
# 切换到特定commit-644a333ec306b012df36d77841e89e61fa4c569b
git checkout 644a333ec306b012df36d77841e89e61fa4c569b

# 子模块切换到匹配的commit
git submodule update

2.2 下载源码包及第三方代码

如果没有网络环境,只能离线下载源码及第三方代码

ZLMediaKit:gitee.com/xia-chu/ZLM...

使用命令或者在网页中确认第三方代码对应的commit

shell 复制代码
git submodule
 ad44a16c99834540b397774ad6c7f3f8ed619d56 3rdpart/ZLToolKit (remotes/origin/4.0-594-gad44a16)
 69098a18b9af0c47549d9a271c054d13ca92b006 3rdpart/jsoncpp (1.9.0-178-g69098a1)
 a8a80e0738b052aa5671ef82a295ef388bd28e13 3rdpart/media-server (v1.0.0-144-ga8a80e0)
 b02d2a4c1abf95db45e50bb77d789defa0fcc4b7 www/webassist (heads/main)

位于3rdpart文件夹

ZLToolKit:gitee.com/xia-chu/ZLT...
jsoncpp:gitee.com/mirrors/jso...
media-server:gitee.com/ireader/med...

位于www文件夹

webassist:gitee.com/victor1002/...

下载后的第三方代码,解压到对应文件夹

shell 复制代码
unzip ZLToolKit-ad44a16c99834540b397774ad6c7f3f8ed619d56.zip
mv ZLToolKit-ad44a16c99834540b397774ad6c7f3f8ed619d56 ZLMediaKit/3rdpart/ZLToolKit

unzip jsoncpp-69098a18b9af0c47549d9a271c054d13ca92b006.zip
mv jsoncpp-69098a18b9af0c47549d9a271c054d13ca92b006 ZLMediaKit/3rdpart/jsoncpp

unzip media-server-a8a80e0738b052aa5671ef82a295ef388bd28e13.zip
mv media-server-a8a80e0738b052aa5671ef82a295ef388bd28e13 ZLMediaKit/3rdpart/media-server

unzip zlm_webassist-b02d2a4c1abf95db45e50bb77d789defa0fcc4b7.zip
mv zlm_webassist-b02d2a4c1abf95db45e50bb77d789defa0fcc4b7 ZLMediaKit/www/webassist

3 编译与安装

3.1 apt软件源检查与配置

银河麒麟默认提供了apt的软件源

shell 复制代码
cat /etc/apt/sources.list

deb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.0 main restricted universe multiverse
deb http://archive.kylinos.cn/kylin/partner juniper main

拉取软件包列表

shell 复制代码
sudo apt update

3.2 安装依赖

3.2.1 apt安装依赖

shell 复制代码
sudo apt install build-essential libpcap-dev libfaac-dev libx264-dev 

# 如果编译安装ffmpeg、mpv
sudo apt install libsdl2-dev liblua5.1-0-dev libass-dev libbluray-dev libuchardet-dev librubberband-dev liblcms2-dev libpulse-dev libalsa-ocaml-dev libgbm-dev libx11-dev libxinerama-dev libxv-dev x11proto-scrnsaver-dev libxss-dev libcaca-dev libxrandr-dev libxtst-dev libxi-dev

如果存在离线环境需要下载对应的deb安装包进行离线安装,可以执行下面的命令下载对应的包

shell 复制代码
apt download build-essential libpcap0.8-dev libpcap-dev libfaac-dev libfaac0 libx264-dev

# 如果编译安装ffmpeg、mpv
apt download camlp4 ledit libalsa-ocaml libalsa-ocaml-dev libasound2-dev libass-dev libbluray-dev libcaca-dev libcamlp4-ocaml-dev libdbus-1-dev libexpat1-dev libfindlib-ocaml libfindlib-ocaml-dev libfontconfig1-dev libfreetype6-dev libfribidi-dev libgbm-dev libglib2.0-dev libharfbuzz-dev libharfbuzz-gobject0 liblcms2-dev liblua5.1-0 liblua5.1-0-dev libmirclient-dev libmircommon-dev libmircookie-dev libmircookie2 libmircore-dev libncurses5-dev libpcre3-dev libpcre32-3 libpcrecpp0v5 libpng12-dev libprotobuf-dev libpulse-dev libreadline-dev libreadline6-dev librubberband-dev libsdl2-dev libslang2-dev libsndio-dev libtinfo-dev libtool-bin libuchardet-dev libuchardet0 libudev-dev libxcursor-dev libxi-dev libxinerama-dev libxkbcommon-dev libxrandr-dev libxrender-dev libxss-dev libxtst-dev libxv-dev ocaml-base-nox ocaml-compiler-libs ocaml-findlib ocaml-interp ocaml-nox x11proto-randr-dev x11proto-record-dev x11proto-render-dev x11proto-scrnsaver-dev x11proto-video-dev x11proto-xinerama-dev dbus dbus-x11 libcaca0 libdbus-1-3 libegl1-mesa libegl1-mesa-dev libexpat1 libfreetype6 libgbm1 libgl1-mesa-dri libglib2.0-0 libglib2.0-bin libncurses5 libncursesw5 libpcre16-3 libpcre3 libpng12-0 libprotobuf-lite9v5 libprotobuf9v5 libpulse-mainloop-glib0 libpulse0 libpulsedsp libtinfo5 libudev1 libwayland-egl1-mesa libx11-6 libx11-dev libxrandr2 libxv1 pulseaudio pulseaudio-module-bluetooth pulseaudio-utils

3.3 源码编译ZLMediaKit

3.3.1 升级OpenSSL

具体问题及分析见章节:4.2 error: 'X509_up_ref' was not declared in this scope

我这里选择的是OpenSSL_1_1_1k

github.com/openssl/ope...

解压OpenSSL_1_1_1k源码

shell 复制代码
tar -xvf openssl-OpenSSL_1_1_1k.tar.gz

cd openssl-OpenSSL_1_1_1k/

编译安装

shell 复制代码
./config shared -fPIC

make 

sudo make install

默认情况下,OpenSSL 将安装到以下子目录中

bash 复制代码
/usr/local/bin
/usr/local/lib
/usr/local/include/openssl

替换系统自带的OpenSSL

bash 复制代码
# 进入root权限
sudo su

# 添加路径到
echo '/usr/local/lib' >> /etc/ld.so.conf

#重新加载动态库
ldconfig -v

# 进入到安装目录
cd /usr/local/bin

# 查看安装的版本				
./openssl version

# 把/usr/bin/openssl 文件重命名备份							
mv /usr/bin/openssl /usr/bin/openssl-bak

# 把/usr/include/openssl 目录重命名备份
mv /usr/include/openssl /usr/include/openssl-bak

# 建一个/usr/bin/openssl软链接,链接到新安装的可执行程序
ln -s /usr/local/bin/openssl  /usr/bin/openssl

# 建一个/usr/include/openssl软链接,链接到新安装的openssl目录
ln -s /usr/local/include/openssl  /usr/include/openssl

# 查看安装的版本(与前面一致则配置成功)
openssl version

# 退出特权模式
exit

3.3.2 源码编译srtp

具体问题及分析见章节:4.1 srtp 未找到, WebRTC 相关功能打开失败

我这里选择的是libsrtp-2.4.2

libsrtp:github.com/cisco/libsr...

解压libsrtp-2.4.2源码

shell 复制代码
tar -xvf libsrtp-2.4.2.tar.gz

cd libsrtp-2.4.2/

检查依赖并生成Makefile文件

shell 复制代码
./configure --enable-openssl --enable-nss

checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for ar... ar
checking the archiver (ar) interface... ar
checking for ranlib... ranlib
checking for a BSD-compatible install... /usr/bin/install -c
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking whether byte ordering is bigendian... no
checking build system type... aarch64-unknown-linux-gnu
checking host system type... aarch64-unknown-linux-gnu
checking whether gcc accepts -Werror... yes
checking whether gcc accepts -fPIC... yes
checking whether gcc accepts -Wall... yes
checking whether gcc accepts -pedantic... yes
checking whether gcc accepts -Wstrict-prototypes... yes
checking whether gcc accepts -O3... yes
checking whether gcc accepts -fexpensive-optimizations... yes
checking whether gcc accepts -funroll-loops... yes
checking whether gcc accepts -Wno-language-extension-token... no
checking for ANSI C header files... (cached) yes
checking for unistd.h... (cached) yes
checking for byteswap.h... yes
checking for stdint.h... (cached) yes
checking for sys/uio.h... yes
checking for inttypes.h... (cached) yes
checking for sys/types.h... (cached) yes
checking for machine/types.h... no
checking for sys/int_types.h... no
checking for sys/socket.h... yes
checking for netinet/in.h... yes
checking for arpa/inet.h... yes
checking for windows.h... no
checking for int8_t... yes
checking for uint8_t... yes
checking for int16_t... yes
checking for uint16_t... yes
checking for int32_t... yes
checking for uint32_t... yes
checking for uint64_t... yes
checking size of unsigned long... 8
checking size of unsigned long long... 8
checking for an ANSI C-conforming const... yes
checking for inline... inline
checking for size_t... yes
checking for socket... yes
checking for inet_aton... yes
checking for usleep... yes
checking for sigaction... yes
checking whether to enable debug logging in all modules... no
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking whether to leverage OpenSSL crypto... yes
checking whether to leverage NSS crypto... yes
checking for user specified OpenSSL directory... no
checking for crypto... yes
checking for library containing EVP_EncryptInit... none required
checking for library containing EVP_aes_128_ctr... none required
checking for library containing EVP_aes_128_gcm... none required
checking whether to leverage OpenSSL KDF algorithm... no
checking for pcap_create in -lpcap... yes
checking for pcap_create in -lwpcap... no
checking whether to redirect logging to stdout... no
checking wheather to use a file for logging... no
checking for extra C compiler flags... no
configure: creating ./config.status
config.status: creating Makefile
config.status: creating crypto/Makefile
config.status: creating doc/Makefile
config.status: creating fuzzer/Makefile
config.status: creating libsrtp2.pc
config.status: creating crypto/include/config.h

编译

shell 复制代码
# 编译
make -j8

一般来说,使用autotools工具链进行构建管理的项目,会使用libtool来编译动态库,启用libtoolconfigure脚本也会增加--enable-shared--disable-shared--enable-static--disable-static--with-pic--without-pic配置标志的支持。

该项目没有使用该功能实现动态库生成,单独增加了sudo make shared_library实现:github.com/cisco/libsr...

生成动态库

shell 复制代码
make shared_library

gcc -shared -o libsrtp2.so.1 -shared -Wl,-soname,libsrtp2.so.1 \
                        srtp/srtp.o crypto/cipher/cipher.o crypto/cipher/null_cipher.o crypto/cipher/cipher_test_cases.o crypto/cipher/aes_icm_ossl.o crypto/cipher/aes_gcm_ossl.o crypto/hash/null_auth.o crypto/hash/auth.o crypto/hash/auth_test_cases.o crypto/hash/hmac_ossl.o crypto/math/datatypes.o crypto/kernel/crypto_kernel.o crypto/kernel/alloc.o crypto/kernel/key.o crypto/kernel/err.o crypto/replay/rdb.o crypto/replay/rdbx.o -L.  -lcrypto -ldl
if [ -n "1" ]; then \
        ln -sfn libsrtp2.so.1 libsrtp2.so; \
fi

安装

shell 复制代码
sudo make install

/usr/bin/install -c -d /usr/local/include/srtp2
/usr/bin/install -c -d /usr/local/lib
cp ./include/srtp.h /usr/local/include/srtp2
cp ./crypto/include/cipher.h /usr/local/include/srtp2
cp ./crypto/include/auth.h /usr/local/include/srtp2
cp ./crypto/include/crypto_types.h /usr/local/include/srtp2
if [ -f libsrtp2.a ]; then cp libsrtp2.a /usr/local/lib/; fi
if [ -f libsrtp2.dll.a ]; then cp libsrtp2.dll.a /usr/local/lib/; fi
if [ -f libsrtp2.so.1 ]; then \
        /usr/bin/install -c -d /usr/local/lib; \
        cp libsrtp2.so.1 /usr/local/lib/; \
        cp libsrtp2.so /usr/local/lib/; \
        if [ -n "1" ]; then \
                ln -sfn libsrtp2.so.1 /usr/local/lib/libsrtp2.so; \
        fi; \
fi
/usr/bin/install -c -d /usr/local/lib/pkgconfig
cp ./libsrtp2.pc /usr/local/lib/pkgconfig/

3.3.4 源码编译安装usrsctp

具体问题及分析见章节:4.3 [ZLMediaKit]SCTP LIBRARIES: SCTP_LIBRARIES-NOTFOUND

我这里选择的是usrsctp-0.9.5.0

usrsctp:github.com/sctplab/usr...

解压usrsctp-0.9.5.0源码

shell 复制代码
tar -xvf usrsctp-0.9.5.0.tar.gz

cd usrsctp-0.9.5.0/

生成configure脚本

shell 复制代码
./bootstrap

libtoolize: putting auxiliary files in '.'.
libtoolize: linking file './ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: linking file 'm4/libtool.m4'
libtoolize: linking file 'm4/ltoptions.m4'
libtoolize: linking file 'm4/ltsugar.m4'
libtoolize: linking file 'm4/ltversion.m4'
libtoolize: linking file 'm4/lt~obsolete.m4'
configure.ac:34: installing './compile'
configure.ac:35: installing './config.guess'
configure.ac:35: installing './config.sub'
configure.ac:32: installing './install-sh'
configure.ac:32: installing './missing'
programs/Makefile.am: installing './depcomp'

运行configure脚本

shell 复制代码
./configure

checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking build system type... aarch64-unknown-linux-gnu
checking host system type... aarch64-unknown-linux-gnu
checking how to print strings... printf
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert aarch64-unknown-linux-gnu file names to aarch64-unknown-linux-gnu format... func_convert_file_noop
checking how to convert aarch64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking whether we should treat compiler warnings as errors... yes
checking for size_t... yes
checking for ssize_t... yes
checking for socket... yes
checking for inet_addr... yes
checking stdatomic.h usability... yes
checking stdatomic.h presence... yes
checking for stdatomic.h... yes
checking sys/queue.h usability... yes
checking sys/queue.h presence... yes
checking for sys/queue.h... yes
checking for linux/if_addr.h... yes
checking for linux/rtnetlink.h... yes
checking for netinet/ip_icmp.h... yes
checking for struct sockaddr.sa_len... no
checking for struct sockaddr_in.sin_len... no
checking for struct sockaddr_in6.sin6_len... no
checking for struct sockaddr_conn.sconn_len... no
checking for socklen_t... yes
checking whether byte ordering is bigendian... no
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating usrsctplib/Makefile
config.status: creating programs/Makefile
config.status: creating Makefile
config.status: executing depfiles commands
config.status: executing libtool commands

编译并安装

shell 复制代码
sudo make install

3.3.5 源码编译安装ffmpeg、mpv(可选)

具体原因可查看文章:【20231129】银河麒麟V4系统(4.4.131-20200604)硬件解码支持问题

(上面文章使用的场景较为简单,这里应用场景更复杂,打开了更多的ffmpeg特性)

3.3.5.1 源码编译libva

我这里选择的是libva-2.1.0

libva-2.1.0:github.com/intel/libva...

解压libva-2.1.0源码,编译并安装

shell 复制代码
tar -xvf libva-2.1.0.tar.gz

cd libva-2.1.0

./autogen.sh -with-drivers-path=/usr/lib/aarch64-linux-gnu/dri

sudo make install
3.3.5.2 源码编译ffmpeg

我这里选择的是FFmpeg-n4.2.2

FFmpeg-n4.2.2:github.com/FFmpeg/FFmp...

解压FFmpeg-n4.2.2源码,编译并安装

shell 复制代码
tar -xvf FFmpeg-n4.2.2.tar.gz

cd FFmpeg-n4.2.2

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

./configure --enable-libdrm --enable-libx264 --enable-gpl --enable-debug --enable-shared

make -j8

sudo make install

sudo ldconfig

# 查看打印是否包含vaapi
ffmpeg -hwaccels
3.3.5.3 源码编译mpv

我这里选择的是mpv-0.32.0

mpv-0.32.0:github.com/mpv-player/...

解压FFmpeg-n4.2.2源码,编译并安装

shell 复制代码
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
export LD_LIBRARY_PATH=/usr/lib/aarch64-linux-gnu/XXXXX
export LIBVA_DRIVER_NAME=XXXXX
export LIBVA_DRIVERS_PATH=/usr/lib/aarch64-linux-gnu/dri

tar -xvf mpv-0.32.0-Waf.tar.gz

cd  mpv-0.32.0

./waf configure --enable-libmpv-shared

./waf build

sudo ./waf install

# 播放视频测试
mpv --vo=gpu --hwdec=vaapi /home/kylin/videos/3840x2160_60fps_Main_h264.mp4

3.3.6 源码编译安装ZLMediaKit

这里记录离线环境,下载源码包的形式

ZLMediaKit:gitee.com/xia-chu/ZLM...

解压ZLMediaKit源码,解压拷贝第三方代码

shell 复制代码
unzip ZLMediaKit-644a333ec306b012df36d77841e89e61fa4c569b.zip

mv ZLMediaKit-644a333ec306b012df36d77841e89e61fa4c569b ZLMediaKit

unzip ZLToolKit-ad44a16c99834540b397774ad6c7f3f8ed619d56.zip
mv ZLToolKit-ad44a16c99834540b397774ad6c7f3f8ed619d56 ZLMediaKit/3rdpart/ZLToolKit

unzip jsoncpp-69098a18b9af0c47549d9a271c054d13ca92b006.zip
mv jsoncpp-69098a18b9af0c47549d9a271c054d13ca92b006 ZLMediaKit/3rdpart/jsoncpp

unzip media-server-a8a80e0738b052aa5671ef82a295ef388bd28e13.zip
mv media-server-a8a80e0738b052aa5671ef82a295ef388bd28e13 ZLMediaKit/3rdpart/media-server

unzip zlm_webassist-b02d2a4c1abf95db45e50bb77d789defa0fcc4b7.zip
mv zlm_webassist-b02d2a4c1abf95db45e50bb77d789defa0fcc4b7 ZLMediaKit/www/webassist

cd ZLMediaKit

修改player/CMakeLists.txt

具体原因见:4.4 [ZLMediaKit]test_player disabled, please install sdl2 ffmpeg/libavcodec ffmpeg/libavutil ffmpeg/libswresample

diff 复制代码
diff --git "a/player/CMakeLists.txt" "b/player/CMakeLists.txt"
--- "a/player/CMakeLists.txt"
+++ "b/player/CMakeLists.txt"
@@ -31,7 +31,9 @@ if(PKG_CONFIG_FOUND)
     list(APPEND LINK_LIBRARIES PkgConfig::SDL2)
     message(STATUS "found library: ${SDL2_LIBRARIES}")
   endif()
-else()
+endif()
+
+if(NOT SDL2_FOUND)
   find_package(SDL2 QUIET)
   if(SDL2_FOUND)
     include_directories(SYSTEM ${SDL2_INCLUDE_DIR})

使用cmake构建工程

shell 复制代码
mkdir build

cd build

cmake .. -DENABLE_X264=ON -DENABLE_FAAC=ON -DENABLE_SCTP=ON -DENABLE_OPENSSL=ON
# 如果源码编译了ffmpeg,则使用下面的参数
# cmake .. -DENABLE_X264=ON -DENABLE_FAAC=ON -DENABLE_SCTP=ON -DENABLE_OPENSSL=ON -DENABLE_FFMPEG=ON

编译

shell 复制代码
make -j8

4 问题记录

4.1 [ZLMediaKit]srtp 未找到, WebRTC 相关功能打开失败

dpkg查看对应包,已经安装了srtp

cmake 复制代码
dpkg -l | grep srtp

ii  libsrtp0                                    1.4.5~20130609~dfsg-1.1kord1                  arm64        Secure RTP (SRTP) and UST Reference Implementations - shared library
ii  libsrtp0-dev                                1.4.5~20130609~dfsg-1.1kord1                  arm64        Secure RTP (SRTP) and UST Reference Implementations - development files
ii  srtp-utils                                  1.4.5~20130609~dfsg-1.1kord1                  arm64        Secure RTP (SRTP) and UST Reference Implementations - utilities

看一下webrtc/CMakeLists.txt文件,是怎么查找srtp库的

cmake 复制代码
# 查找 srtp 是否安装
find_package(SRTP QUIET)
if(NOT SRTP_FOUND OR NOT ENABLE_OPENSSL)
  set(ENABLE_WEBRTC OFF)
  message(WARNING "srtp 未找到, WebRTC 相关功能打开失败")
  return()
endif()

find_package可以通过编写的Find<LibraryName>.cmake文件,查找对应的so库和头文件,刚好项目的cmake目录下就存在FindSRTP.cmake

cmake 复制代码
cat cmake/FindSRTP.cmake

set(_SRTP_ROOT_PATHS
        ${CMAKE_INSTALL_PREFIX}
        )

find_path(SRTP_INCLUDE_DIRS
        NAMES srtp2/srtp.h
        HINTS _SRTP_ROOT_PATHS  ${SRTP_PREFIX}
        PATH_SUFFIXES include
        )

if(SRTP_INCLUDE_DIRS)
    set(HAVE_SRTP_SRTP_H 1)
endif()

find_library(SRTP_LIBRARIES
        NAMES srtp2
        HINTS ${_SRTP_ROOT_PATHS} ${SRTP_PREFIX}
        PATH_SUFFIXES bin lib
        )

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SRTP
        DEFAULT_MSG
        SRTP_INCLUDE_DIRS SRTP_LIBRARIES HAVE_SRTP_SRTP_H
        )

mark_as_advanced(SRTP_INCLUDE_DIRS SRTP_LIBRARIES HAVE_SRTP_SRTP_H)

可以看出,这里需要的是srtp2库,系统的apt软件源提供的版本不符合要求,需要源码编译高版本

4.2 [ZLMediaKit]error: 'X509_up_ref' was not declared in this scope

编译时出现以下报错

shell 复制代码
/ZLMediaKit/webrtc/DtlsTransport.cpp: In member function 'bool RTC::DtlsTransport::DtlsEnvironment::ReadCertificateAndPrivateKeyFromContext(SSL_CTX*)':
/home/kylin/test/ZLMediaKit/webrtc/DtlsTransport.cpp:303:32: error: 'X509_up_ref' was not declared in this scope
         X509_up_ref(certificate);
                                ^
/home/kylin/test/ZLMediaKit/webrtc/DtlsTransport.cpp:309:35: error: 'EVP_PKEY_up_ref' was not declared in this scope
         EVP_PKEY_up_ref(privateKey);
                                   ^
/home/kylin/test/ZLMediaKit/webrtc/DtlsTransport.cpp: In constructor 'RTC::DtlsTransport::DtlsTransport(toolkit::EventPoller::Ptr, RTC::DtlsTransport::Listener*)':
/home/kylin/test/ZLMediaKit/webrtc/DtlsTransport.cpp:560:52: error: 'DTLS_set_timer_cb' was not declared in this scope
         DTLS_set_timer_cb(this->ssl, onSslDtlsTimer);

一般这种都是OpenSSL的版本问题

看一下系统自带的OpenSSL版本,版本是1.0.2g

shell 复制代码
dpkg -l | grep openssl

ii  openssl                                     1.0.2g-1kord4.15                              arm64        Secure Sockets Layer toolkit - cryptographic utility

github上拉一下OpenSSL的代码,看一下X509_up_ref函数是在什么时候被添加的

切换到1.0.2gtag,看是否包含该commit

OpenSSL1.0.2g版本不包含X509_up_ref函数的commit,而程序实际使用了X509_up_ref函数,自然会出现报错。

需要升级OpenSSL的版本,我这里选择的版本是1.1.1k

4.3 [ZLMediaKit]SCTP LIBRARIES: SCTP_LIBRARIES-NOTFOUND

cmake的打印发现找不到sctp的库,用dpkg看一下是否安装了sctp的库

shell 复制代码
dpkg -l | grep sctp

ii  libsctp-dev                                 1.0.16+dfsg-3kord                             arm64        user-space access to Linux kernel SCTP - development files
ii  libsctp1:arm64                              1.0.16+dfsg-3kord                             arm64        user-space access to Linux kernel SCTP - shared library

但是实际cmake没有找到库,查看对应库的搜索逻辑

cmake 复制代码
cat camke/FindSCTP.cmake

# - Try to find sctp
#
# Once done this will define
#  SCTP_FOUND        - System has mbedtls
#  SCTP_INCLUDE_DIRS - The mbedtls include directories
#  SCTP_LIBRARIES    - The mbedtls library


#find Mbedtls
FIND_PATH(
    SCTP_INCLUDE_DIRS
    NAMES usrsctp.h
)

FIND_LIBRARY(
    SCTP_LIBRARIES
    NAMES usrsctp
)

message(STATUS "SCTP LIBRARIES: " ${SCTP_LIBRARIES})
message(STATUS "SCTP INCLUDE DIRS: " ${SCTP_INCLUDE_DIRS})

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SCTP DEFAULT_MSG SCTP_LIBRARIES SCTP_INCLUDE_DIRS)

查找的库名称是usrsctp,并不是sctp

使用命令查看软件源中是否有现成的包:apt-cache search usrsctp

软件源中未提供该包,需要源码编译

4.4 [ZLMediaKit]test_player disabled, please install sdl2 ffmpeg/libavcodec ffmpeg/libavutil ffmpeg/libswresample

cmake的打印发现test_player选项未能开启,需要安装sdl2的库,用dpkg看一下是否安装了sdl2的库

shell 复制代码
dpkg -l | grep sdl2

ii  libsdl2-2.0-0:arm64                         2.0.4+dfsg1-2kord2.16.04.2                    arm64        Simple DirectMedia Layer
ii  libsdl2-dev                                 2.0.4+dfsg1-2kord2.16.04.2                    arm64        Simple DirectMedia Layer development files

但是实际cmake没有找到库,查看对应库的搜索逻辑

cmake 复制代码
cat player/CMakeLists.txt

find_package(PkgConfig QUIET)
# 查找 SDL2 是否安装
if(PKG_CONFIG_FOUND)
  pkg_check_modules(SDL2 QUIET IMPORTED_TARGET sdl2)
  if(SDL2_FOUND)
    list(APPEND LINK_LIBRARIES PkgConfig::SDL2)
    message(STATUS "found library: ${SDL2_LIBRARIES}")
  endif()
else()
  find_package(SDL2 QUIET)
  if(SDL2_FOUND)
    include_directories(SYSTEM ${SDL2_INCLUDE_DIR})
    list(APPEND LINK_LIBRARIES ${SDL2_LIBRARY})
    message(STATUS "found library: ${SDL2_LIBRARY}")
  endif()
endif()

set(PLAYER_NAME "test_player")

# 如果 ffmpeg/libavcodec ffmpeg/libavcodec SDL 都安装了则编译播放器
if(NOT SDL2_FOUND)
  message(WARNING "${PLAYER_NAME} disabled, please install sdl2 ffmpeg/libavcodec ffmpeg/libavutil ffmpeg/libswresample")
  return()
endif()

sdl2的库是使用pkg-config来查找的,那么直接在终端用pkg-config查找库

shell 复制代码
pkg-config sdl2 --libs --cflags

-I/usr/include/SDL2  -lSDL2

打印是有点问题,libs部分没有打印出来,但是整个库有搜索到,SDL2_FOUND的值不应该为False

libs部分未打印出来的原因是,libs所在路径为系统路径,默认不打印,使用环境变量export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1后,可以正常打印

去掉pkg_check_modules函数中的QUIET参数,开放打印信息

shell 复制代码
-- Checking for modules 'IMPORTED_TARGET;sdl2'
--   Package IMPORTED_TARGET was not found in the pkg-config search path.
Perhaps you should add the directory containing `IMPORTED_TARGET.pc'
to the PKG_CONFIG_PATH environment variable
Package 'IMPORTED_TARGET', required by 'world', not found

IMPORTED_TARGET参数not found,感觉又是版本的问题......

看一下当前的cmake版本

shell 复制代码
dpkg -l | grep cmake

ii  cmake                                       3.5.1-1kord1                                  arm64        cross-platform, open-source make system
ii  cmake-data                                  3.5.1-1kord1                                  all          CMake data files (modules, templates and documentation)

看一下cmake的文档,看看IMPORTED_TARGET参数是在哪个版本支持的

3.5:cmake.org/cmake/help/... 3.6:cmake.org/cmake/help/...

cmake在3.6.0版本的对应文件(支持参数IMPORTED_TARGET):

github.com/Kitware/CMa...

cmake在3.5.2版本的对应文件(不支持参数IMPORTED_TARGET):

github.com/Kitware/CMa...

IMPORTED_TARGET参数在3.6.0及以上版本才支持

升级cmake可以解决问题,也有不需要升级cmake的方法:cmake/FindSDL2.cmake实现了如何查找SDL2

但是由于PKG_CONFIG_FOUND,没有走到这个分支,可以更改成pkg_check_modules没有找到SDL2库后,再使用find_package搜索

shell 复制代码
# 查找 SDL2 是否安装
if(PKG_CONFIG_FOUND)
  pkg_check_modules(SDL2 QUIET IMPORTED_TARGET sdl2)
  if(SDL2_FOUND)
    list(APPEND LINK_LIBRARIES PkgConfig::SDL2)
    message(STATUS "found library: ${SDL2_LIBRARIES}")
  endif()
endif()

if(NOT SDL2_FOUND)
  find_package(SDL2 QUIET)
  if(SDL2_FOUND)
    include_directories(SYSTEM ${SDL2_INCLUDE_DIR})
    list(APPEND LINK_LIBRARIES ${SDL2_LIBRARY})
    message(STATUS "found library: ${SDL2_LIBRARY}")
  endif()
endif()
相关推荐
小安运维日记2 小时前
Linux云计算 |【第四阶段】NOSQL-DAY1
linux·运维·redis·sql·云计算·nosql
CoolTiger、5 小时前
【Vmware16安装教程】
linux·虚拟机·vmware16
学习3人组6 小时前
CentOS 中配置 OpenJDK以及多版本管理
linux·运维·centos
厨 神6 小时前
vmware中的ubuntu系统扩容分区
linux·运维·ubuntu
Karoku0666 小时前
【网站架构部署与优化】web服务与http协议
linux·运维·服务器·数据库·http·架构
geek_Chen016 小时前
虚拟机共享文件夹开启后mnt/hgfs/下无sharefiles? --已解决
linux·运维·服务器
(⊙o⊙)~哦7 小时前
linux 解压缩
linux·运维·服务器
牧小七8 小时前
Linux命令---查看端口是否被占用
linux
鸡鸭扣9 小时前
虚拟机:3、(待更)WSL2安装Ubuntu系统+实现GPU直通
linux·运维·ubuntu
友友马9 小时前
『 Linux 』HTTP(一)
linux·运维·服务器·网络·c++·tcp/ip·http