Clone
15
v3_CN_SrsLinuxArm
winlin edited this page 2022-01-06 11:57:15 +08:00
This file contains ambiguous Unicode characters

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.

HOME > CN > ARM

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

使用dockerUbuntu 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

播放:http://ossrs.net/srs.release/trunk/research/players/srs_player.html?app=live&stream=livestream&server=localhost&port=1935&autostart=true&vhost=localhost

image

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的交叉环境是cpuv7debian armhf所以arm虚拟机需要是v7的。

若使用debian armelcpu是v5的信息如下

root@debian-armel:~# cat /proc/cpuinfo 
Processor	: ARM926EJ-S rev 5 (v5l)
CPU revision	: 5

若使用debian armhfcpu是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