This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Note: 如果觉得Github的Wiki访问太慢,可以访问 Gitee 镜像。
SRS for linux-arm
arm芯片上,如何使用SRS?一般arm上的硬件可以获取到h.264裸码流。有几个方案:
- arm推送RTMP到SRS:从arm上将h.264裸码流包装成flv流,使用srs-librtmp,或者librtmp,将flv格式的包以RTMP发送到SRS。
- arm上运行SRS:在arm上运行SRS,使用上面两个方案将h.264裸码流推送到arm上的SRS。客户端或者RTMP边缘直接从arm上的SRS源站取RTMP流。
注意:一般情况下,直接在ARM下是可以编译SRS的,参考官网正常的编译方法就可以,不需要交叉编译。
Why run SRS on ARM?
ARM跑SRS主要原因:
- arm设备,像摄像头,比较多,譬如一万个摄像头,如果有中心服务器,都往上面推,中心服务器就完蛋了。
- 用户看摄像头时,一般需要装插件,一般摄像头只能出rtmp。所以没法用浏览器flash直接看。所以arm上跑个srs,就可以让用户直接打开。
- arm上跑srs,每个摄像头都是服务器,相当于分布式服务器。不过都是源站。
注意:一般情况下,直接在ARM下是可以编译SRS的,参考官网正常的编译方法就可以,不需要交叉编译。
Ubuntu Cross Build SRS
!!! 注意,请先确认是否需要交叉编译,一般可以直接编译,除非极少数情况。
翁晓晶:看来很多人误解了交叉编译的意思了,异构平台编译才要,比如编译平台跟运行平台是异构的,才需要,都是同一个平台不需要。
翁晓晶:最常见的场景就是玩网络设备的,因为网络设备的u都很弱,编译很慢,所以才在pc上做交叉编译,因为pc的u是x86,网络设备的u基本上都是mips或者arm的低频率的,属于异构,x86的u编译速度明显快于它们,所以大家都在pc上做交叉编译,然后把结果拷贝进网络设备,这样编译速度快很多,当然你有时间也可以直接在网络设备上正常编译也是可以的,就是慢很多。
翁晓晶:我看到有个朋友提到arm的服务器比如鲲鹏,那就直接在arm的服务器上编译就好了,没必要再交叉编译了,arm服务器又不是网络设备,U编译个程序还是没问题的,不要走弯路了。
先使用UBUNTU16交叉编译SRS以及依赖的ST和OpenSSL。
CrossBuild SRS in Ubuntu16
使用docker,Ubuntu 16(xenial):
docker pull registry.cn-hangzhou.aliyuncs.com/ossrs/srs:ubuntu16
推荐使用阿里云的容器,下载的速度比较快,也可以使用docker官方容器:
docker pull ossrs/srs:ubuntu16
启动容器,主目录为SRS:
cd ~/git && docker run -it -v `pwd`:/tmp/git -w /tmp/git/srs/trunk \
registry.cn-hangzhou.aliyuncs.com/ossrs/srs:ubuntu16 bash
安装toolchain,例如Acqua or RoadRunner board
apt-get install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
交叉编译SRS:
./configure --arm --cc=arm-linux-gnueabihf-gcc --cxx=arm-linux-gnueabihf-g++ \
--ar=arm-linux-gnueabihf-ar --ld=arm-linux-gnueabihf-ld --randlib=arm-linux-gnueabihf-randlib &&
make
编译时,默认会重新交叉编译OpenSSL,而不会使用系统的SSL,如果需要强制使用系统的SSL,可以用
--use-sys-ssl。
Run SRS on ARM board
在ARMv7的docker上跑:https://hub.docker.com/r/armv7/armhf-ubuntu
docker pull armv7/armhf-ubuntu &&
cd ~/git && docker run -it -v `pwd`:/tmp/git -w /tmp/git/srs/trunk \
-p 1935:1935 -p 1985:1985 -p 8080:8080 armv7/armhf-ubuntu \
./objs/srs -c conf/console.conf
推流,由于没有ARM的FFMEPG,可以在其他机器推流到这个docker:
ffmpeg -re -i doc/source.200kbps.768x320.flv -c copy \
-f flv -y rtmp://127.0.0.1:1935/live/livestream
Use Other Cross build tools
注意:一般情况下,直接在ARM下是可以编译SRS的,参考官网正常的编译方法就可以,不需要交叉编译。
从这个comment( https://github.com/ossrs/srs/issues/1168#issuecomment-404376674 )看,除了设置tookchain,可能CFlags也需要设置,需要开放多个选项,不仅仅是开启crossbuild就可以了。
参考FFMPEG的选项:
Mac:ffmpeg chengli.ycl$ ./configure -h
--ar=AR use archive tool AR [ar]
--cc=CC use C compiler CC [gcc]
--cxx=CXX use C compiler CXX [g++]
--ld=LD use linker LD []
可能OpenSSL在交叉编译时也需要一些额外的Flags( https://stackoverflow.com/questions/7827622/how-can-one-provide-custom-compiler-linker-flags-for-openssl ),但也可以用
--use-sys-ssl使用系统的已经编译好的ssl库。
SRS相关的参数如下:
root@4c618f90fc4c:/tmp/git/srs/trunk# ./configure -h
Toolchain options: @see https://github.com/ossrs/srs/issues/1547#issuecomment-576078411
--arm Enable crossbuild for ARM.
--mips Enable crossbuild for MIPS.
--cc=<CC> Use c compiler CC, default is gcc.
--cxx=<CXX> Use c++ compiler CXX, default is g++.
--ar=<AR> Use archive tool AR, default is ar.
--ld=<LD> Use linker tool LD, default is ld.
--randlib=<RANDLIB> Use randlib tool RANDLIB, default is randlib.
--extra-flags=<EFLAGS> Set EFLAGS as CFLAGS and CXXFLAGS. Also passed to ST as EXTRA_CFLAGS.
具体使用例子参考这里
--extra-flags
之前在支持ARM时,新增过一个Flags的选项( https://github.com/ossrs/srs/issues/1282#issuecomment-568891854 ),会设置CFLAGS and CXXFLAGS,也会将这个设置传递到ST设置EXTRA_CFLAGS。
同样,对于交叉编译,这个选项也是有效的。
RaspberryPi
SRS可以直接在RespberryPI上编译和运行,不用交叉编译。
Armel and Armhf
有时候总是碰到Illegal instruction,那是编译器的目标CPU太高,虚拟机的CPU太低。
参考:http://stackoverflow.com/questions/14253626/arm-cross-compiling
写一个简单的测试程序,测试编译环境:
/*
arm-linux-gnueabi-g++ -o test test.cpp -static
arm-linux-gnueabi-strip test
*/
#include <stdio.h>
int main(int argc, char** argv) {
printf("hello, arm!\n");
return 0;
}
编译出test后,使用工具查看目标CPU:
arm-linux-gnueabi-readelf --file-header --arch-specific test
运行结果如下:
Machine: ARM
File Attributes
Tag_CPU_name: "7-A"
Tag_CPU_arch: v7
可见Ubuntu12的交叉环境是cpuv7(debian armhf),所以arm虚拟机需要是v7的。
若使用debian armel,cpu是v5的,信息如下:
root@debian-armel:~# cat /proc/cpuinfo
Processor : ARM926EJ-S rev 5 (v5l)
CPU revision : 5
若使用debian armhf,cpu是v7的,信息如下:
root@debian-armhf:~# cat /proc/cpuinfo
Processor : ARMv7 Processor rev 0 (v7l)
CPU architecture: 7
将测试程序编译后scp到arm虚拟机,可以运行:
root@debian-armhf:~# ./test
hello, arm!
Winlin 2014.2
Welcome to SRS wiki!
SRS 5.0 wiki
Please select your language:
SRS 4.0 wiki
Please select your language:
SRS 3.0 wiki
Please select your language:
SRS 2.0 wiki
Please select your language:
SRS 1.0 wiki
Please select your language:

