Skip to content

Commit

Permalink
GB28181: Support GB28181-2016 protocol. v5.0.74 (#3201)
Browse files Browse the repository at this point in the history
01. Support GB config as StreamCaster.
02. Support disable GB by --gb28181=off.
03. Add utests for SIP examples.
04. Wireshark plugin to decode TCP/9000 as rtp.rfc4571
05. Support MPEGPS program stream codec.
06. Add utest for PS stream codec.
07. Decode MPEGPS packet stream.
08. Carry RTP and PS packet as helper in PS message.
09. Support recover from error mode.
10. Support process by a pack of PS/TS messages.
11. Add statistic for recovered and msgs dropped.
12. Recover from err position fastly.
13. Define state machine for GB session.
14. Bind context to GB session.
15. Re-invite when media disconnected.
16. Update GitHub actions with GB28181.
17. Support parse CANDIDATE by env or pip.
18. Support mux GB28181 to RTMP.
19. Support regression test by srs-bench.
  • Loading branch information
winlinvip authored Oct 6, 2022
1 parent 9c81a0e commit 5a420ec
Show file tree
Hide file tree
Showing 298 changed files with 43,333 additions and 753 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
# Build for CentOS 7
- name: Build on CentOS7, baseline
run: DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target centos7-baseline .
- name: Build on CentOS7, with SRT
run: DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target centos7-srt .
- name: Build on CentOS7, with all features
run: DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target centos7-all .
- name: Build on CentOS7, without WebRTC
run: DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target centos7-no-webrtc .
- name: Build on CentOS7, without ASM
Expand All @@ -35,8 +35,8 @@ jobs:
# Build for CentOS 6
- name: Build on CentOS6, baseline
run: DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target centos6-baseline .
- name: Build on CentOS6, with SRT
run: DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target centos6-srt .
- name: Build on CentOS6, with all features
run: DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target centos6-all .

build-ubuntu16:
name: build-ubuntu16
Expand All @@ -49,8 +49,8 @@ jobs:
# Build for Ubuntu16
- name: Build on Ubuntu16, baseline
run: DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu16-baseline .
- name: Build on Ubuntu16, with SRT
run: DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu16-srt .
- name: Build on Ubuntu16, with all features
run: DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu16-all .

build-ubuntu18:
name: build-ubuntu18
Expand All @@ -63,8 +63,8 @@ jobs:
# Build for Ubuntu18
- name: Build on Ubuntu18, baseline
run: DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu18-baseline .
- name: Build on Ubuntu18, with SRT
run: DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu18-srt .
- name: Build on Ubuntu18, with all features
run: DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu18-all .

build-ubuntu20:
name: build-ubuntu20
Expand All @@ -77,8 +77,8 @@ jobs:
# Build for Ubuntu20
- name: Build on Ubuntu20, baseline
run: DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu20-baseline .
- name: Build on Ubuntu20, with SRT
run: DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu20-srt .
- name: Build on Ubuntu20, with all features
run: DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu20-all .

build-cross-arm:
name: build-cross-arm
Expand Down
37 changes: 32 additions & 5 deletions trunk/3rdparty/srs-bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fi
然后运行回归测试用例,如果只跑一次,可以直接运行:

```bash
go test ./srs -mod=vendor -v
go test ./srs -mod=vendor -v -count=1
```

也可以用make编译出重复使用的二进制:
Expand All @@ -137,7 +137,7 @@ PASS
可以给回归测试传参数,这样可以测试不同的序列,比如:

```bash
go test ./srs -mod=vendor -v -srs-server=127.0.0.1
go test ./srs -mod=vendor -v -count=1 -srs-server=127.0.0.1
# Or
make && ./objs/srs_test -test.v -srs-server=127.0.0.1
```
Expand All @@ -151,8 +151,8 @@ make && ./objs/srs_test -test.v -srs-log -test.run TestRtcBasic_PublishPlay
支持的参数如下:

* `-srs-server`,RTC服务器地址。默认值:`127.0.0.1`
* `-srs-stream`,RTC流地址。默认值:`/rtc/regression`
* `-srs-timeout`,每个Case的超时时间,毫秒。默认值:`3000`,即3秒
* `-srs-stream`,RTC流地址,一般会加上随机的后缀。默认值:`/rtc/regression`
* `-srs-timeout`,每个Case的超时时间,毫秒。默认值:`5000`,即5秒
* `-srs-publish-audio`,推流时,使用的音频文件。默认值:`avatar.ogg`
* `-srs-publish-video`,推流时,使用的视频文件。默认值:`avatar.h264`
* `-srs-publish-video-fps`,推流时,视频文件的FPS。默认值:`25`
Expand Down Expand Up @@ -189,7 +189,7 @@ pip install lxml && pip install gcovr
支持Janus的压测,使用选项`-sfu janus`可以查看帮助:

```bash
./objs/srs_bench -sfu janus --help
make && ./objs/srs_bench -sfu janus --help
```

首先需要启动Janus,推荐使用[janus-docker](https://github.com/winlinvip/janus-docker#usage):
Expand Down Expand Up @@ -221,4 +221,31 @@ make -j10 && ./objs/srs_bench -sfu janus \
-nn 5
```

## GB28181

支持GB28181的压测,使用选项`-sfu gb28181`可以查看帮助:

```bash
make && ./objs/srs_bench -sfu gb28181 --help
```

运行回归测试用例,更多命令请参考[Regression Test](#regression-test)

```bash
go test ./gb28181 -mod=vendor -v -count=1
```

支持的参数如下:

* `-srs-sip`,SIP服务器地址。默认值:`tcp://127.0.0.1:5060`
* `-srs-stream`,GB的user,即流名称,一般会加上随机的后缀。默认值:`3402000000`
* `-srs-timeout`,每个Case的超时时间,毫秒。默认值:`11000`,即11秒。
* `-srs-publish-audio`,推流时,使用的音频文件。默认值:`avatar.aac`
* `-srs-publish-video`,推流时,使用的视频文件。默认值:`avatar.h264`
* `-srs-publish-video-fps`,推流时,视频文件的FPS。默认值:`25`

其他不常用参数:

* `-srs-log`,是否开启详细日志。默认值:`false`

2021.01, Winlin
Binary file added trunk/3rdparty/srs-bench/avatar.aac
Binary file not shown.
145 changes: 145 additions & 0 deletions trunk/3rdparty/srs-bench/gb28181/gb28181.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// The MIT License (MIT)
//
// Copyright (c) 2022 Winlin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package gb28181

import (
"context"
"flag"
"fmt"
"github.com/ossrs/go-oryx-lib/errors"
"github.com/ossrs/go-oryx-lib/logger"
"io"
"os"
"strings"
"time"
)

type gbMainConfig struct {
sipConfig SIPConfig
psConfig PSConfig
}

func Parse(ctx context.Context) interface{} {
fl := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)

var sfu string
fl.StringVar(&sfu, "sfu", "srs", "The SFU server, srs or gb28181 or janus")

c := &gbMainConfig{}
fl.StringVar(&c.sipConfig.addr, "pr", "", "")
fl.StringVar(&c.sipConfig.user, "user", "", "")
fl.StringVar(&c.sipConfig.server, "server", "", "")
fl.StringVar(&c.sipConfig.domain, "domain", "", "")
fl.IntVar(&c.sipConfig.random, "random", 0, "")

fl.StringVar(&c.psConfig.video, "sv", "", "")
fl.StringVar(&c.psConfig.audio, "sa", "", "")
fl.IntVar(&c.psConfig.fps, "fps", 0, "")

fl.Usage = func() {
fmt.Println(fmt.Sprintf("Usage: %v [Options]", os.Args[0]))
fmt.Println(fmt.Sprintf("Options:"))
fmt.Println(fmt.Sprintf(" -sfu The target SFU, srs or gb28181 or janus. Default: srs"))
fmt.Println(fmt.Sprintf("SIP:"))
fmt.Println(fmt.Sprintf(" -user The SIP username, ID of device."))
fmt.Println(fmt.Sprintf(" -random Append N number to user as random device ID, like 1320000001."))
fmt.Println(fmt.Sprintf(" -server The SIP server ID, ID of server."))
fmt.Println(fmt.Sprintf(" -domain The SIP domain, domain of server and device."))
fmt.Println(fmt.Sprintf("Publisher:"))
fmt.Println(fmt.Sprintf(" -pr The SIP server address, format is tcp://ip:port over TCP."))
fmt.Println(fmt.Sprintf(" -fps [Optional] The fps of .h264 source file."))
fmt.Println(fmt.Sprintf(" -sa [Optional] The file path to read audio, ignore if empty."))
fmt.Println(fmt.Sprintf(" -sv [Optional] The file path to read video, ignore if empty."))
fmt.Println(fmt.Sprintf("\n例如,1个推流:"))
fmt.Println(fmt.Sprintf(" %v -sfu gb28181 -pr tcp://127.0.0.1:5060 -user 34020000001320000001 -server 34020000002000000001 -domain 3402000000", os.Args[0]))
fmt.Println(fmt.Sprintf(" %v -sfu gb28181 -pr tcp://127.0.0.1:5060 -user 3402000000 -random 10 -server 34020000002000000001 -domain 3402000000", os.Args[0]))
fmt.Println(fmt.Sprintf(" %v -sfu gb28181 -pr tcp://127.0.0.1:5060 -user 3402000000 -random 10 -server 34020000002000000001 -domain 3402000000 -sa avatar.aac -sv avatar.h264 -fps 25", os.Args[0]))
fmt.Println(fmt.Sprintf(" %v -sfu gb28181 -pr tcp://127.0.0.1:5060 -user livestream -server srs -domain ossrs.io -sa avatar.aac -sv avatar.h264 -fps 25", os.Args[0]))
fmt.Println()
}
if err := fl.Parse(os.Args[1:]); err == flag.ErrHelp {
os.Exit(0)
}

showHelp := c.sipConfig.String() == ""
if showHelp {
fl.Usage()
os.Exit(-1)
}

summaryDesc := ""
if c.sipConfig.addr != "" {
pubString := strings.Join([]string{c.sipConfig.String(), c.psConfig.String()}, ",")
summaryDesc = fmt.Sprintf("%v, publish(%v)", summaryDesc, pubString)
}
logger.Tf(ctx, "Run benchmark with %v", summaryDesc)

return c
}

func Run(ctx context.Context, r0 interface{}) (err error) {
conf := r0.(*gbMainConfig)
ctx, cancel := context.WithCancel(ctx)

session := NewGBSession(&GBSessionConfig{
regTimeout: 3 * time.Hour, inviteTimeout: 3 * time.Hour,
}, &conf.sipConfig)
defer session.Close()

if err := session.Connect(ctx); err != nil {
return errors.Wrapf(err, "connect %v", conf.sipConfig)
}

if err := session.Register(ctx); err != nil {
return errors.Wrapf(err, "register %v", conf.sipConfig)
}

if err := session.Invite(ctx); err != nil {
return errors.Wrapf(err, "invite %v", conf.sipConfig)
}

if conf.psConfig.video == "" || conf.psConfig.audio == "" {
cancel()
return nil
}

ingester := NewPSIngester(&IngesterConfig{
psConfig: conf.psConfig,
ssrc: uint32(session.out.ssrc),
clockRate: session.out.clockRate,
payloadType: uint8(session.out.payloadType),
})
defer ingester.Close()

if ingester.conf.serverAddr, err = utilBuildMediaAddr(session.sip.conf.addr, session.out.mediaPort); err != nil {
return err
}

if err := ingester.Ingest(ctx); err != nil {
if errors.Cause(err) == io.EOF {
logger.Tf(ctx, "EOF, video=%v, audio=%v", conf.psConfig.video, conf.psConfig.audio)
return nil
}
return errors.Wrap(err, "ingest")
}

return nil
}
45 changes: 45 additions & 0 deletions trunk/3rdparty/srs-bench/gb28181/gb28181_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// The MIT License (MIT)
//
// Copyright (c) 2022 Winlin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package gb28181

import (
"github.com/ossrs/go-oryx-lib/logger"
"io/ioutil"
"os"
"testing"
)

func TestMain(m *testing.M) {
if err := prepareTest(); err != nil {
logger.Ef(nil, "Prepare test fail, err %+v", err)
os.Exit(-1)
}

// Disable the logger during all tests.
if *srsLog == false {
olw := logger.Switch(ioutil.Discard)
defer func() {
logger.Switch(olw)
}()
}

os.Exit(m.Run())
}
Loading

0 comments on commit 5a420ec

Please sign in to comment.