前言 RTP (Real-timeTransportProtocol)是用于Internet上针对多媒体数据流的一种传输协议,做流媒体传输方面的应用离不开RTP协议的实现及使用。可在项目中应用RTP 协议实现流媒体(音视频)的传输,比如我们的游戏机项目实现就可以通过RTP推流音视频到PC,通过PC显示和播放音频,这样就不需要使用开发板的LCD和音频模块,刚好开发板也没有附带LCD,所以我们就这么干了。RTP实现有一些开源库可以选择,这里选择ORTP 库,这个库是纯使用c语言编写,移植比较简单。
开发环境搭建
交叉编译
WSL中 sudo apt install make git clone https://github.com/dmonakhov/ortp.git cd ortp/ ./autogen.sh 报如下错误
lhj@lhj:~/ortp$ ./autogen.sh
+ rm -rf config.cache autom4te.cache
+ libtoolize --copy --force
./autogen.sh: 36: ./autogen.sh: libtoolize: not found
+ aclocal
./autogen.sh: 37: ./autogen.sh: aclocal: not found
+ autoheader
./autogen.sh: 38: ./autogen.sh: autoheader: not found
+ automake --force-missing --add-missing --copy
./autogen.sh: 39: ./autogen.sh: automake: not found
+ autoconf
./autogen.sh: 40: ./autogen.sh: autoconf: not found
解决
sudo apt-get install libtool*
sudo apt-get install m4
sudo apt-get install automake
重新 ./autogen.sh 配置 ./configure CC=aarch64-linux-gnu-gcc --host=aarch64-linux --target=aarch64-linux --prefix=/home/lhj/opt/ 报错
configure: Could not find libsrtp headers or lib, cryto transport disabled.
./configure: line 12958: syntax error near unexpected token `LIBZRTPCPP,'
./configure: line 12958: ` PKG_CHECK_MODULES(LIBZRTPCPP, libzrtpcpp >= 2.0.0)'
解决 cd ../ git clone https://github.com/cisco/libsrtp.git cd libsrtp ./configure make make runtest sudo make install 再重新配置 cd ../ortp ./configure CC=aarch64-linux-gnu-gcc --host=aarch64-linux --target=aarch64-linux --prefix=/home/lhj/opt/ 报错
configure: Could not find libsrtp headers or lib, cryto transport disabled.
./configure: line 12958: syntax error near unexpected token `LIBZRTPCPP,'
./configure: line 12958: ` PKG_CHECK_MODULES(LIBZRTPCPP, libzrtpcpp >= 2.0.0)'
解决
sudo apt-get install pkg-config
sudo apt-get update
sudo apt-get upgrade
sudo aclocal
sudo autoheader
sudo autoconf
sudo automake
再重新配置 ./configure CC=aarch64-linux-gnu-gcc --host=aarch64-linux --target=aarch64-linux --prefix=/home/lhj/opt/ 编译 make make install 查看编译的内容
sudo apt-get install tree
lhj@lhj:~/opt$ tree /home/lhj/opt/
/home/lhj/opt/
├── include
│ └── ortp
│ ├── b64.h
│ ├── event.h
│ ├── logging.h
│ ├── ortp.h
│ ├── ortp_srtp.h
│ ├── payloadtype.h
│ ├── port.h
│ ├── rtcp.h
│ ├── rtp.h
│ ├── rtpprofile.h
│ ├── rtpsession.h
│ ├── rtpsignaltable.h
│ ├── sessionset.h
│ ├── str_utils.h
│ ├── stun.h
│ ├── stun_udp.h
│ ├── telephonyevents.h
│ └── zrtp.h
└── lib
├── libortp.la
├── libortp.so -> libortp.so.9.0.0
├── libortp.so.9 -> libortp.so.9.0.0
├── libortp.so.9.0.0
└── pkgconfig
└── ortp.pc
4 directories, 23 files
将上述lib/下的libortp.so.9.0.0和 libortp.la导入到开发板的/usr/lib目录下 并创建软连接
root@g2uliot:/usr/lib# ln -s libortp.so.9.0.0 libortp.so
root@g2uliot:/usr/lib# ln -s libortp.so.9.0.0 libortp.so.9
最终开发板中文件如下
-rw-r--r-- 1 root root 944 Dec 19 2022 libortp.la
lrwxrwxrwx 1 root root 16 Sep 20 10:49 libortp.so -> libortp.so.9.0.0
lrwxrwxrwx 1 root root 16 Sep 20 10:49 libortp.so.9 -> libortp.so.9.0.0
-rw-r--r-- 1 root root 651368 Dec 19 2022 libortp.so.9.0.
PC编译 cd /home/lhj/ortp ./autogen.sh ./configure --prefix=/home/lhj/opt/win make clean make make install cd src/tests/ sudo cp /home/lhj/opt/win/lib/libortp.so.9* /usr/lib gcc rtpsend.c -lortp -L/home/lhj/opt/win/lib -I/home/lhj/opt/win/include -o rtpsend gcc rtprecv.c -lortp -L/home/lhj/opt/win/lib -I/home/lhj/opt/win/include -o rtprecv PC中测试 新建一个终端接收 ./rtprecv test 5000
lhj@lhj:~/ortp/src/tests$ ./rtprecv test 5000
ortp-message-Not sending rtcp report: sockfd=5, rem_addrlen=0, connected=0
ortp-message-Not sending rtcp report: sockfd=5, rem_addrlen=0, connected=0
ortp-message-Not sending rtcp report: sockfd=5, rem_addrlen=0, connected=0
ortp-message-Not sending rtcp report: sockfd=5, rem_addrlen=0, connected=0
新建一个终端发送 ./rtpsend hello.txt 127.0.0.1 5000
lhj@lhj:~/ortp/src/tests$ ./rtpsend hello.txt 127.0.0.1 5000
ortp-message-Setting random local addresses.
ortp-message-oRTP-stats:
Global statistics :
ortp-message- number of rtp packet sent=1
ortp-message- number of rtp bytes sent=23 bytes
ortp-message- number of rtp packet received=0
ortp-message- number of rtp bytes received=0 bytes
ortp-message- number of incoming rtp bytes successfully delivered to the application=0
ortp-message- number of rtp packet lost=0
ortp-message- number of rtp packets received too late=0
ortp-message- number of bad formatted rtp packets=0
ortp-message- number of packet discarded because of queue overflow=0
开发板-PC测试分别交叉编译和本地编译测试代码 cd /home/lhj/ortp/src/tests 编译 aarch64-linux-gnu-gcc rtpsend.c -lortp -L/home/lhj/opt/board/lib -I/home/lhj/opt/board/include -o rtpsend aarch64-linux-gnu-gcc rtprecv.c -lortp -L/home/lhj/opt/board/lib -I/home/lhj/opt/board/include -o rtprecv 将交叉编译的程序rtpsend rtprecv导入到开发板 chmod +x rtpsend rtprecv 开发板中运行 vi hello.txt新建测试文件,内容随便写,比如简单一句hello ortp
./rtprecv test 5000
root@g2uliot:~# ./rtprecv test 5000
ortp-message-Not sending rtcp report: sockfd=5, rem_addrlen=0, connected=0
ortp-message-Not sending rtcp report: sockfd=5, rem_addrlen=0, connected=0
ortp-message-Not sending rtcp report: sockfd=5, rem_addrlen=0, connected=0
ortp-message-Not sending rtcp report: sockfd=5, rem_addrlen=0, connected=0
ortp-message-Not sending rtcp report: sockfd=5, rem_addrlen=0, connected=0
WSL中运行本地编译的版本 ./rtpsend hello.txt 192.168.1.10 5000
lhj@lhj:~/ortp/src/tests$ ./rtpsend hello.txt 192.168.1.10 5000
ortp-message-Setting random local addresses.
ortp-message-oRTP-stats:
Global statistics :
ortp-message- number of rtp packet sent=1
ortp-message- number of rtp bytes sent=23 bytes
ortp-message- number of rtp packet received=0
ortp-message- number of rtp bytes received=0 bytes
ortp-message- number of incoming rtp bytes successfully delivered to the application=0
ortp-message- number of rtp packet lost=0
ortp-message- number of rtp packets received too late=0
ortp-message- number of bad formatted rtp packets=0
ortp-message- number of packet discarded because of queue overflow=0
开发板中打开收到文件tets vi test
说明收发测试OK。 总结 以上实现了ortp的开发环境搭建,并进行了文件实时传输的测试,为后面音视频的传输做了准备,后面就是分别实现音频和视频的实时推流到PC播放,为游戏机项目做准备。
|