-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
v3_CN_SrsLinuxArm
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主要原因:
- arm设备,像摄像头,比较多,譬如一万个摄像头,如果有中心服务器,都往上面推,中心服务器就完蛋了。
- 用户看摄像头时,一般需要装插件,一般摄像头只能出rtmp。所以没法用浏览器flash直接看。所以arm上跑个srs,就可以让用户直接打开。
- arm上跑srs,每个摄像头都是服务器,相当于分布式服务器。不过都是源站。
先使用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
若需要使用其他的交叉编译工具,或者其他的CPU体系或OS,也可以支持,参考这里。
SRS可以直接在RespberryPI上编译和运行,不用交叉编译。
有时候总是碰到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!
Please select your language:
Please select your language:
Please select your language:
Please select your language:
Please select your language: