srs-librtmp移植到树莓派
SRS(Simple Rtmp Server)是一个国人编写的开源的RTMP/HLS流媒体服务器,非常强大。
Gitee上的介绍:v2_CN_Home - Wiki - Gitee.com
SRS提供的librtmp
srs提供的客户端srs-librtmp的定位和librtmp(rtmpdump)不一样,主要是:
-
librtmp的代码确实很烂,毋庸置疑,典型的代码堆积。
-
librtmp接口定义不良好,这个对比srs就可以看出,使用起来得看实现代码。
-
没有实例:接口的使用最好提供实例,srs提供了publish/play/rtmpdump实例。
-
最小依赖关系:srs调整了模块化,只取出了core/kernel/rtmp三个模块,其他代码没有编译到srs-librtmp中,避免了冗余。
-
最少依赖库:srs-librtmp只依赖c/c++标准库(若需要复杂握手需要依赖openssl,srs也编译出来了,只需要加入链接即可)。
-
不依赖st:srs-librtmp使用同步阻塞socket,没有使用st(st主要是服务器处理并发需要)。
-
SRS提供了测速函数,直接调用srs-librtmp就可以完成到服务器的测速。参考:Bandwidth Test
-
SRS提供了日志接口,可以获取服务器端的信息,譬如版本,对应的session id。参考:Tracable log
-
支持直接发布h.264裸码流,参考:publish-h264-raw-data
-
SRS可以直接导出一个srs-librtmp的project,编译成.h和.a使用。或者导出为.h和.cpp,一个大文件。参考:export srs librtmp
一句话,srs为何提供客户端开发库?因为rtmp客户端开发不方便,不直观,不简洁。
这些都是官网的介绍与说明,总之就是srs-librtmp提供了更简单的方式完成rtmp的客户端推流。
重点关注最后一点,将代码导出后进行编译移植。
移植到树莓派
下载源码
SRS 2.0版本开始支持librtmp,貌似4.0开始不再支持。因此这里下载3.0的版本。
boy@ubuntu:~/opensource/srs_librtmp/srs_3.0_r8/srs-v3.0-r8$ ls
AUTHORS.txt LICENSE README.md trunk
boy@ubuntu:~/opensource/srs_librtmp/srs_3.0_r8/srs-v3.0-r8$ cd trunk/
boy@ubuntu:~/opensource/srs_librtmp/srs_3.0_r8/srs-v3.0-r8/trunk$ ls
3rdparty auto conf configure doc etc ide modules research scripts src usr
boy@ubuntu:~/opensource/srs_librtmp/srs_3.0_r8/srs-v3.0-r8/trunk$ ./configure --with
--with-gcp --with-librtmp --without-hds --without-valgrind
--with-gmc --without-gcp --without-librtmp --with-research
--with-gmd --without-gmc --without-research --with-ssl
--with-gmp --without-gmd --without-ssl --with-stat
--with-gperf --without-gmp --without-stat --with-stream-caster
--with-gprof --without-gperf --without-stream-caster --with-utest
--with-hds --without-gprof --without-utest --with-valgrind
boy@ubuntu:~/opensource/srs_librtmp/srs_3.0_r8/srs-v3.0-r8/trunk$ ./configure --with
使用./configure --with补全查看到–without-librtmp字样即支持librtmp。
导出代码
编译一个配置脚本pi_config.sh,将srs-rtmp推流的demo工程导出:
#!/bin/sh
./configure \
--prefix=/home/boy/opensource/srs_librtmp/srs_3.0_r8/srs-v3.0-r8/trunk/pi_install \
--arm \
--cc=/opt/rpi_tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc \
--cxx=/opt/rpi_tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ \
--ar=/opt/rpi_tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-ar \
--ld=/opt/rpi_tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-ld \
--randlib=/opt/rpi_tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-randlib \
--without-ssl \
--export-librtmp-single=/home/boy/opensource/SRS_librtmp
以上选项都是根据configure --help的帮助信息进行配置的,下面这些选项是交叉编译相关的配置。
--without-ssl Disable rtmp complex handshake.
--export-librtmp-single=<path> Export srs-librtmp to a single file(.h+.cpp) in path.
执行脚本后导出的工程如下:
boy@ubuntu:~/opensource/SRS_librtmp$ ls
example.c srs_librtmp.cpp srs_librtmp.h
将srs_librtmp.cpp srs_librtmp.h两个文件迁移到自己代码即可,example.c是使用的示例。