Skip to content

Commit

Permalink
messages:
Browse files Browse the repository at this point in the history
  - [feat] lalserver增加中继转推(relay push)功能,可将接收到的推流(pub)转推(push)到其他rtmp类型的服务器,支持1对n的转推
  - [feat] package rtmp: 新增函数amf0::ReadArray,用于解析amf array数据
  - [refactor] `rtmp/client_push_session`增加当前会话连接状态
  - [fix] demo/analyseflv: 修复解析metadata的bug
  - [perf] httpflv协议关闭时,不做httpflv的GOP缓存
  - [refactor] logic中的配置变更为全局变量
  - [refactor] lal/demo移动到lal/app/demo
  - [refactor] 日志整理
  • Loading branch information
q191201771 committed Jun 13, 2020
1 parent 843952a commit b3024c8
Show file tree
Hide file tree
Showing 37 changed files with 604 additions and 158 deletions.
91 changes: 46 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<img alt="Wide" src="https://pengrl.com/images/other/lallogo.png">
</a>
<br>
Go语言编写的直播流媒体网络传输服务器
Go live stream lib/client/server and much more.
<br><br>
<a title="TravisCI" target="_blank" href="https://www.travis-ci.org/q191201771/lal"><img src="https://www.travis-ci.org/q191201771/lal.svg?branch=master"></a>
<a title="codecov" target="_blank" href="https://codecov.io/gh/q191201771/lal"><img src="https://codecov.io/gh/q191201771/lal/branch/master/graph/badge.svg?style=flat-square"></a>
Expand All @@ -27,7 +27,7 @@ Go语言编写的直播流媒体网络传输服务器

---

已支持RTMP,HTTP-FLV,HLS(m3u8 + ts),H264/AVC,H265/HEVC,AAC,GOP缓存。
Go直播流媒体网络传输服务器,已支持RTMP,HTTP-FLV,HLS(m3u8+ts),H264/AVC,H265/HEVC,AAC,GOP缓存,中继转推。更多功能持续迭代中

### README 目录

Expand Down Expand Up @@ -56,7 +56,7 @@ $cd $GOPATH/src/github.com/q191201771/lal
$./build.sh

# 使用 Go module
$export GOPROXY=https://goproxy.cn
$export GOPROXY=https://goproxy.io
$git clone https://github.com/q191201771/lal.git
$cd lal
$./build.sh
Expand Down Expand Up @@ -93,6 +93,11 @@ $./bin/lalserver -c conf/lalserver.conf.json
"fragment_duration_ms": 3000, // 单个TS文件切片时长,单位毫秒
"fragment_num": 6 // M3U8文件列表中TS文件的数量
},
"relay_push": {
"enable": false, // 是否开启中继转推功能,开启后,自身接收到的所有流都会转推出去
"addr_list":[ // 中继转推的对端地址,支持填写多个地址,做1对n的转推
]
},
"pprof": {
"enable": true, // 是否开启Go pprof web服务的监听
"addr": ":10001" // Go pprof web地址
Expand All @@ -110,39 +115,39 @@ $./bin/lalserver -c conf/lalserver.conf.json

### 三. 仓库目录框架

简单来说,源码在`pkg/``app/``demo/`三个目录下。
简单来说,源码在`pkg/``app/lalserver/``app/demo/`三个目录下。

- `pkg/`:存放各package包,供本repo的程序以及其他业务方使用
- `app/`:重要程序的入口(目前仅包含lalserver——基于lal编写的一个通用流媒体服务器程序)
- `demo/`:存放各种基于`lal/pkg`开发的小程序(小工具),一个子目录是一个程序,详情见各源码文件中头部的说明
- `app/lalserver`:基于lal编写的一个通用流媒体服务器程序入口
- `app/demo/`:存放各种基于`lal/pkg`开发的小程序(小工具),一个子目录是一个程序,详情见各源码文件中头部的说明

```
pkg/ ......
|-- rtmp/ ......RTMP协议
|-- httpflv/ ......HTTP-FLV协议
|-- hls/ ......HLS协议
|-- logic/ ......lalserver服务器程序的上层业务逻辑
|-- aac/ ......音频AAC编码格式相关
|-- avc/ ......视频H264/AVC编码格式相关
|-- hevc/ ......视频H265/HEVC编码格式相关
|-- innertest/ ......测试代码
app/ ......
|-- lalserver/ ......流媒体服务器lalserver的main函数入口
demo/ ......
|-- analyseflv ......
|-- analysehls ......
|-- flvfile2rtmppush ......
|-- rtmppull ......
|-- httpflvpull ......
|-- modflvfile ......
|-- flvfile2es ......
|-- learnts ......
|-- tscmp ......
conf/ ......配置文件目录
bin/ ......可执行文件编译输出目录
pkg/ ......
|-- rtmp/ ......RTMP协议
|-- httpflv/ ......HTTP-FLV协议
|-- hls/ ......HLS协议
|-- logic/ ......lalserver服务器程序的上层业务逻辑
|-- aac/ ......音频AAC编码格式相关
|-- avc/ ......视频H264/AVC编码格式相关
|-- hevc/ ......视频H265/HEVC编码格式相关
|-- innertest/ ......测试代码
app/ ......
|-- lalserver/ ......流媒体服务器lalserver的main函数入口
|-- demo/ ......
|-- analyseflv ......
|-- analysehls ......
|-- flvfile2rtmppush ......
|-- rtmppull ......
|-- httpflvpull ......
|-- modflvfile ......
|-- flvfile2es ......
|-- learnts ......
|-- tscmp ......
conf/ ......配置文件目录
bin/ ......可执行文件编译输出目录
```

后续我再画些源码架构图。
Expand All @@ -152,24 +157,14 @@ bin/ ......可执行文件编译输出目录

### 四. Roadmap

#### 项目原则:

* 代码可读可维护
* 框架清晰,模块化。业务与协议隔离。协议、网络传输等基础功能都是功能纯粹,可独立使用的库。
* 高性能
* 提供各种client代码,即使你使用其他流媒体服务器,这些client也是非常好用的
* 依托Go语言,提供所有平台下最简单的编译、调试、发布方式
* 不依赖第三方代码
* 后续可快速集成各种网络传输协议,流媒体封装协议

#### lalserver服务器功能

- [x] **pub 接收推流** RTMP
- [x] **sub 接收拉流** RTMP,HTTP-FLV,HLS(m3u8+ts)
- [x] **pub接收推流** RTMP
- [x] **sub接收拉流** RTMP,HTTP-FLV,HLS(m3u8+ts)
- [x] **音频编码格式:** AAC
- [x] **视频编码格式:** H264/AVC,H265/HEVC
- [x] **GOP缓存:** 用于秒开
- [ ] RTMP转推
- [x] **relay push中继转推:** RTMP
- [ ] RTMP回源
- [ ] HTTP-FLV回源
- [ ] 静态转推、回源
Expand Down Expand Up @@ -204,3 +199,9 @@ bin/ ......可执行文件编译输出目录

[TEST.md](https://github.com/q191201771/lal/blob/master/TEST.md)

### 八. 项目star趋势图

觉得这个repo还不错,就点个star支持一下吧 :)

[![Stargazers over time](https://starchart.cc/q191201771/lal.svg)](https://starchart.cc/q191201771/lal)

2 changes: 1 addition & 1 deletion TEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
| 1000 | 1000 | 125% | 464MB |

* 测试机:32核16G(lalserver服务器和压测工具同时跑在这一个机器上)
* 压测工具:lal中的 `/demo/flvfile2rtmppush` 以及 `/demo/rtmppull`
* 压测工具:lal中的 `/app/demo/flvfile2rtmppush` 以及 `/app/demo/rtmppull`
* 推流码率:使用`srs-bench`中的FLV文件,大概200kbps
* lalserver版本:基于 git commit: xxx

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,18 @@ func main() {

switch tag.Header.Type {
case httpflv.TagTypeMetadata:
//nazalog.Debugf("----------\n", hex.Dump(tag.Raw))
if printMetaData {
nazalog.Debugf("----------\n%s", hex.Dump(tag.Raw[11:]))

// TODO chef: 这部分可以移入到rtmp package中
_, l, err := rtmp.AMF0.ReadString(tag.Raw[11:])
nazalog.Assert(nil, err)
kv, _, err := rtmp.AMF0.ReadObject(tag.Raw[11+l:])
ops, _, err := rtmp.AMF0.ReadArray(tag.Raw[11+l : len(tag.Raw)-4])
nazalog.Assert(nil, err)
var buf bytes.Buffer
buf.WriteString(fmt.Sprintf("-----\ncount:%d\n", len(kv)))
for k, v := range kv {
buf.WriteString(fmt.Sprintf(" %s: %v\n", k, v))
buf.WriteString(fmt.Sprintf("-----\ncount:%d\n", len(ops)))
for _, op := range ops {
buf.WriteString(fmt.Sprintf(" %s: %+v\n", op.Key, op.Value))
}
nazalog.Debugf("%+v", buf.String())
}
Expand Down Expand Up @@ -172,8 +173,17 @@ func analysisVideoTag(tag httpflv.Tag) {
} else {
body := tag.Raw[11:]

for i := 5; i != int(tag.Header.DataSize); {
i := 5
for i != int(tag.Header.DataSize) {
if i+4 > int(tag.Header.DataSize) {
nazalog.Errorf("invalid nalu size. i=%d, tag size=%d", i, int(tag.Header.DataSize))
break
}
naluLen := bele.BEUint32(body[i:])
if i+int(naluLen) > int(tag.Header.DataSize) {
nazalog.Errorf("invalid nalu size. i=%d, naluLen=%d, tag size=%d", i, naluLen, int(tag.Header.DataSize))
break
}
switch t {
case typeAVC:
if avc.CalcNaluType(body[i+4:]) == avc.NaluUnitTypeIDRSlice {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 6 additions & 11 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,14 @@ LDFlags=" \
-X 'github.com/q191201771/naza/pkg/bininfo.BuildGoVersion=${BuildGoVersion}' \
"

for file in `ls ${ROOT_DIR}/app`
do
if [ -d ${ROOT_DIR}/app/${file} ]; then
echo "build" ${ROOT_DIR}/app/${file} "..."
cd ${ROOT_DIR}/app/${file} && go build -ldflags "$LDFlags" -o ${ROOT_DIR}/${OUT_DIR}/${file}
fi
done
echo "build" ${ROOT_DIR}/app/lalserver "..."
cd ${ROOT_DIR}/app/lalserver && go build -ldflags "$LDFlags" -o ${ROOT_DIR}/${OUT_DIR}/lalserver

for file in `ls ${ROOT_DIR}/demo`
for file in `ls ${ROOT_DIR}/app/demo`
do
if [ -d ${ROOT_DIR}/demo/${file} ]; then
echo "build" ${ROOT_DIR}/demo/${file} "..."
cd ${ROOT_DIR}/demo/${file} && go build -ldflags "$LDFlags" -o ${ROOT_DIR}/${OUT_DIR}/${file}
if [ -d ${ROOT_DIR}/app/demo/${file} ]; then
echo "build" ${ROOT_DIR}/app/demo/${file} "..."
cd ${ROOT_DIR}/app/demo/${file} && go build -ldflags "$LDFlags" -o ${ROOT_DIR}/${OUT_DIR}/${file}
fi
done

Expand Down
37 changes: 37 additions & 0 deletions conf/edge.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"rtmp": {
"enable": true,
"addr": ":19351",
"gop_num": 2
},
"httpflv": {
"enable": false,
"sub_listen_addr": ":8080",
"gop_num": 2
},
"hls": {
"enable": false,
"sub_listen_addr": ":8081",
"out_path": "/tmp/lal/hls/",
"fragment_duration_ms": 3000,
"fragment_num": 6
},
"relay_push": {
"enable": true,
"addr_list":[
"127.0.0.1:19350"
]
},
"pprof": {
"enable": false,
"addr": ":10001"
},
"log": {
"level": 1,
"filename": "./logs/edge.log",
"is_to_stdout": true,
"is_rotate_daily": true,
"short_file_flag": true,
"assert_behavior": 1
}
}
5 changes: 5 additions & 0 deletions conf/lalserver.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
"fragment_duration_ms": 3000,
"fragment_num": 6
},
"relay_push": {
"enable": false,
"addr_list":[
]
},
"pprof": {
"enable": true,
"addr": ":10001"
Expand Down
5 changes: 5 additions & 0 deletions conf/lalserver.default.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
"fragment_duration_ms": 3000,
"fragment_num": 6
},
"relay_push": {
"enable": false,
"addr_list":[
]
},
"pprof": {
"enable": true,
"addr": ":10001"
Expand Down
2 changes: 1 addition & 1 deletion gen_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ROOT_DIR=`pwd`
OUT_DIR=release

v=`git tag | tail -n 1`
v=`git tag --sort=version:refname | tail -n 1`
prefix=lal_${v}_

rm -rf ${ROOT_DIR}/${OUT_DIR}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/q191201771/lal

go 1.12

require github.com/q191201771/naza v0.13.0
require github.com/q191201771/naza v0.13.1
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github.com/q191201771/naza v0.13.0 h1:tHgsMlMu9dHGmL26cGpFJDeP1qdFwbXVJHPg6IlAuvo=
github.com/q191201771/naza v0.13.0/go.mod h1:SE14GBGO9mAn6JZl3NlfWGtNOT7xQjxOG7f3YOdBThM=
github.com/q191201771/naza v0.13.1 h1:eA2n87AfADKKFNtRyulKbuD942POferOHZwmAfwBw7I=
github.com/q191201771/naza v0.13.1/go.mod h1:SE14GBGO9mAn6JZl3NlfWGtNOT7xQjxOG7f3YOdBThM=
1 change: 1 addition & 0 deletions pkg/hls/hls.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package hls
// - 配置项
// - Server
// - 超时时间
// - 考虑删除过期的TS文件,并考虑做一个全量TS的m3u8作为点播用

// https://developer.apple.com/documentation/http_live_streaming/example_playlists_for_http_live_streaming/incorporating_ads_into_a_playlist
// https://developer.apple.com/documentation/http_live_streaming/example_playlists_for_http_live_streaming/event_playlist_construction
Expand Down
Loading

0 comments on commit b3024c8

Please sign in to comment.