├── LICENSE ├── README.en.md ├── README.md ├── client.go ├── go.mod ├── go.sum ├── main.go ├── publisher.go ├── server.go └── subscriber.go /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019-present, dexter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.en.md: -------------------------------------------------------------------------------- 1 | _[简体中文](https://github.com/Monibuca/plugin-rtsp) | English_ 2 | # RTSP Plugin 3 | 4 | The RTSP plugin provides the ability to push and pull the RTSP protocol and also to push and pull the RTSP protocol to remote servers. 5 | 6 | ## Plugin address 7 | 8 | https://github.com/Monibuca/plugin-rtsp 9 | 10 | ## Plugin introduction 11 | 12 | ```go 13 | import ( 14 | _ "m7s.live/plugin/rtsp/v4" 15 | ) 16 | ``` 17 | 18 | ## Push and Pull address form 19 | 20 | ``` 21 | rtsp://localhost/live/test 22 | ``` 23 | - `localhost` is the m7s server domain name or IP address, and the default port `554` can be omitted, otherwise it is required to be written. 24 | - `live` represents `appName` 25 | - `test` represents `streamName` 26 | - `live/test` in m7s will serve as the stream identity. 27 | 28 | For example, push stream to m7s through ffmpeg 29 | 30 | ```bash 31 | ffmpeg -i [video source] -c:v h264 -c:a aac -f rtsp rtsp://localhost/live/test 32 | ``` 33 | 34 | This will create a stream named `live/test` inside m7s. 35 | 36 | If the `live/test` stream already exists in m7s, then you can use the RTSP protocol to play it. 37 | 38 | ```bash 39 | ffplay rtsp://localhost/live/test 40 | ``` 41 | 42 | ## Configuration 43 | 44 | ```yaml 45 | rtsp: 46 | publish: # Refer to the global configuration format 47 | subscribe: # Refer to the global configuration format 48 | pull: # Format reference document https://m7s.live/guide/config.html#%E6%8F%92%E4%BB%B6%E9%85%8D%E7%BD%AE 49 | push: # Format reference document https://m7s.live/guide/config.html#%E6%8F%92%E4%BB%B6%E9%85%8D%E7%BD%AE 50 | listenaddr: :554 51 | udpaddr: :8000 52 | rtcpaddr: :8001 53 | readbuffercount: 2048 54 | writebuffercount: 2048 55 | ``` 56 | :::tip Configuration override 57 | publish and subscribe, any section not configured will use global configuration. 58 | ::: 59 | 60 | ## API 61 | 62 | ### `rtsp/api/list` 63 | Get all RTSP streams 64 | 65 | ### `rtsp/api/pull?target=[RTSP address]&streamPath=[Stream identity]&save=[0|1|2]` 66 | Pull the RTSP to m7s from a remote server 67 | - save meaning: 0, do not save; 1, save to pullonstart; 2, save to pullonsub 68 | - The RTSP address needs to be urlencoded to prevent special characters from affecting parsing 69 | ### `rtsp/api/push?target=[RTSP address]&streamPath=[Stream identity]` 70 | Push local streams to remote servers -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | _[English](https://github.com/Monibuca/plugin-rtsp/blob/v4/README.en.md) | 简体中文_ 2 | # RTSP插件 3 | rtsp插件提供rtsp协议的推拉流能力,以及向远程服务器推拉rtsp协议的能力。 4 | ## 插件地址 5 | 6 | https://github.com/Monibuca/plugin-rtsp 7 | 8 | ## 插件引入 9 | ```go 10 | import ( 11 | _ "m7s.live/plugin/rtsp/v4" 12 | ) 13 | ``` 14 | 15 | ## 推拉地址形式 16 | ``` 17 | rtsp://localhost/live/test 18 | ``` 19 | - `localhost`是m7s的服务器域名或者IP地址,默认端口`554`可以不写,否则需要写 20 | - `live`代表`appName` 21 | - `test`代表`streamName` 22 | - m7s中`live/test`将作为`streamPath`为流的唯一标识 23 | 24 | 25 | 例如通过ffmpeg向m7s进行推流 26 | 27 | ```bash 28 | ffmpeg -i [视频源] -c:v h264 -c:a aac -f rtsp rtsp://localhost/live/test 29 | ``` 30 | 31 | 会在m7s内部形成一个名为live/test的流 32 | 33 | 34 | 如果m7s中已经存在live/test流的话就可以用rtsp协议进行播放 35 | ```bash 36 | ffplay rtsp://localhost/live/test 37 | ``` 38 | 39 | ## 配置 40 | 41 | ```yaml 42 | rtsp: 43 | publish: # 参考全局配置格式 44 | subscribe: # 参考全局配置格式 45 | pull: # 格式参考文档 https://m7s.live/guide/config.html#%E6%8F%92%E4%BB%B6%E9%85%8D%E7%BD%AE 46 | push: # 格式参考文档 https://m7s.live/guide/config.html#%E6%8F%92%E4%BB%B6%E9%85%8D%E7%BD%AE 47 | listenaddr: :554 48 | udpaddr: :8000 49 | rtcpaddr: :8001 50 | readbuffercount: 2048 # 读取缓存队列大小 51 | writebuffercount: 2048 # 写出缓存队列大小 52 | ``` 53 | :::tip 配置覆盖 54 | publish 55 | subscribe 56 | 两项中未配置部分将使用全局配置 57 | ::: 58 | ## API 59 | 60 | ### `rtsp/api/list` 61 | 获取所有rtsp流 62 | 63 | ### `rtsp/api/pull?target=[RTSP地址]&streamPath=[流标识]&save=[0|1|2]` 64 | 从远程拉取rtsp到m7s中 65 | - save含义:0、不保存;1、保存到pullonstart;2、保存到pullonsub 66 | - RTSP地址需要进行urlencode 防止其中的特殊字符影响解析 67 | ### `rtsp/api/push?target=[RTSP地址]&streamPath=[流标识]` 68 | 将本地的流推送到远端 -------------------------------------------------------------------------------- /client.go: -------------------------------------------------------------------------------- 1 | package rtsp 2 | 3 | import ( 4 | "context" 5 | "net" 6 | 7 | "github.com/bluenviron/gortsplib/v4" 8 | "github.com/bluenviron/gortsplib/v4/pkg/base" 9 | "github.com/bluenviron/gortsplib/v4/pkg/url" 10 | "go.uber.org/zap" 11 | "m7s.live/engine/v4" 12 | ) 13 | 14 | type RTSPClient struct { 15 | *gortsplib.Client `json:"-" yaml:"-"` 16 | gortsplib.Transport 17 | DialContext func(ctx context.Context, network, address string) (net.Conn, error) `json:"-" yaml:"-"` 18 | } 19 | type RTSPPuller struct { 20 | RTSPPublisher 21 | engine.Puller 22 | RTSPClient 23 | } 24 | 25 | func (p *RTSPClient) Close() error { 26 | if p.Client != nil { 27 | p.Client.Close() 28 | } 29 | return nil 30 | } 31 | 32 | func (p *RTSPClient) Disconnect() { 33 | if p.Client != nil { 34 | p.Client.Close() 35 | } 36 | } 37 | 38 | func (p *RTSPPuller) Connect() error { 39 | client := &gortsplib.Client{ 40 | DialContext: p.DialContext, 41 | 42 | AnyPortEnable: true, 43 | } 44 | p.Transport = gortsplib.TransportTCP 45 | client.Transport = &p.Transport 46 | // parse URL 47 | u, err := url.Parse(p.RemoteURL) 48 | if err != nil { 49 | return err 50 | } 51 | // connect to the server 52 | if err = client.Start(u.Scheme, u.Host); err != nil { 53 | return err 54 | } 55 | p.Client = client 56 | p.SetIO(p) 57 | return nil 58 | } 59 | 60 | func (p *RTSPPuller) Pull() (err error) { 61 | u, _ := url.Parse(p.RemoteURL) 62 | var res *base.Response 63 | if rtspConfig.SendOptions { 64 | if res, err = p.Options(u); err != nil { 65 | p.Error("Options", zap.Error(err)) 66 | return 67 | } 68 | } 69 | p.Debug("Options", zap.Any("res", res)) 70 | // find published tracks 71 | session, res, err := p.Describe(u) 72 | if err != nil { 73 | p.Error("Describe", zap.Error(err)) 74 | return err 75 | } 76 | p.Debug("Describe", zap.Any("res", res)) 77 | p.session = session 78 | err = p.SetTracks() 79 | if err != nil { 80 | p.Error("SetTracks", zap.Error(err)) 81 | return err 82 | } 83 | if err = p.SetupAll(session.BaseURL, session.Medias); err != nil { 84 | p.Error("SetupAndPlay", zap.Error(err)) 85 | return err 86 | } 87 | p.OnPacketRTPAny(p.OnPacket) 88 | res, err = p.Play(nil) 89 | p.Debug("Play", zap.Any("res", res)) 90 | if err != nil { 91 | p.Error("Play", zap.Error(err)) 92 | return err 93 | } 94 | return p.Wait() 95 | } 96 | 97 | type RTSPPusher struct { 98 | RTSPSubscriber 99 | engine.Pusher 100 | RTSPClient 101 | } 102 | 103 | func (p *RTSPPusher) OnEvent(event any) { 104 | switch v := event.(type) { 105 | case engine.VideoRTP: 106 | p.Client.WritePacketRTP(p.videoTrack, v.Packet) 107 | case engine.AudioRTP: 108 | p.Client.WritePacketRTP(p.audioTrack, v.Packet) 109 | default: 110 | p.RTSPSubscriber.OnEvent(event) 111 | } 112 | } 113 | 114 | func (p *RTSPPusher) Connect() error { 115 | p.Client = &gortsplib.Client{ 116 | DialContext: p.DialContext, 117 | WriteQueueSize: rtspConfig.WriteBufferCount, 118 | } 119 | p.Transport = gortsplib.TransportTCP 120 | p.Client.Transport = &p.Transport 121 | // parse URL 122 | u, err := url.Parse(p.RemoteURL) 123 | if err != nil { 124 | p.Error("url.Parse", zap.Error(err)) 125 | return err 126 | } 127 | // connect to the server 128 | if err = p.Client.Start(u.Scheme, u.Host); err != nil { 129 | p.Error("Client.Start", zap.Error(err)) 130 | return err 131 | } 132 | p.SetIO(p) 133 | if rtspConfig.SendOptions { 134 | _, err = p.Client.Options(u) 135 | } 136 | return err 137 | } 138 | 139 | func (p *RTSPPusher) Push() (err error) { 140 | var u *url.URL 141 | u, err = url.Parse(p.RemoteURL) 142 | // startTime := time.Now() 143 | // for len(p.tracks) < 2 { 144 | // if time.Sleep(time.Second); time.Since(startTime) > time.Second*10 { 145 | // return fmt.Errorf("timeout") 146 | // } 147 | // } 148 | var res *base.Response 149 | if res, err = p.Announce(u, p.session); err != nil { 150 | p.Error("Announce", zap.Error(err)) 151 | return 152 | } else { 153 | p.Debug("Announce", zap.Any("res", res)) 154 | } 155 | err = p.SetupAll(u, p.session.Medias) 156 | if err != nil { 157 | p.Error("Setup", zap.Error(err)) 158 | return 159 | } 160 | 161 | if res, err = p.Record(); err != nil { 162 | p.Error("Record", zap.Error(err)) 163 | return 164 | } else { 165 | p.Debug("Record", zap.Any("res", res)) 166 | } 167 | p.PlayRTP() 168 | return 169 | } 170 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module m7s.live/plugin/rtsp/v4 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/bluenviron/gortsplib/v4 v4.6.2 7 | github.com/bluenviron/mediacommon v1.5.1 8 | github.com/pion/rtp v1.8.3 9 | go.uber.org/zap v1.26.0 10 | m7s.live/engine/v4 v4.15.2 11 | ) 12 | 13 | require ( 14 | github.com/deepch/vdk v0.0.27 // indirect 15 | github.com/denisbrodbeck/machineid v1.0.1 // indirect 16 | github.com/go-ole/go-ole v1.2.6 // indirect 17 | github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect 18 | github.com/golang/mock v1.6.0 // indirect 19 | github.com/google/pprof v0.0.0-20230309165930-d61513b1440d // indirect 20 | github.com/google/uuid v1.4.0 // indirect 21 | github.com/logrusorgru/aurora/v4 v4.0.0 // indirect 22 | github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a // indirect 23 | github.com/mcuadros/go-defaults v1.2.0 // indirect 24 | github.com/onsi/ginkgo/v2 v2.9.5 // indirect 25 | github.com/pion/randutil v0.1.0 // indirect 26 | github.com/pion/rtcp v1.2.12 // indirect 27 | github.com/pion/sdp/v3 v3.0.6 // indirect 28 | github.com/pion/webrtc/v3 v3.2.20 // indirect 29 | github.com/pkg/errors v0.9.1 // indirect 30 | github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect 31 | github.com/q191201771/naza v0.30.48 // indirect 32 | github.com/quic-go/qtls-go1-20 v0.3.3 // indirect 33 | github.com/quic-go/quic-go v0.38.1 // indirect 34 | github.com/shirou/gopsutil/v3 v3.23.8 // indirect 35 | github.com/shoenig/go-m1cpu v0.1.6 // indirect 36 | github.com/tklauser/go-sysconf v0.3.12 // indirect 37 | github.com/tklauser/numcpus v0.6.1 // indirect 38 | github.com/yapingcat/gomedia v0.0.0-20230905155010-55b9713fcec1 // indirect 39 | github.com/yusufpapurcu/wmi v1.2.3 // indirect 40 | go.uber.org/multierr v1.11.0 // indirect 41 | golang.org/x/crypto v0.16.0 // indirect 42 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect 43 | golang.org/x/mod v0.12.0 // indirect 44 | golang.org/x/net v0.19.0 // indirect 45 | golang.org/x/sync v0.3.0 // indirect 46 | golang.org/x/sys v0.15.0 // indirect 47 | golang.org/x/tools v0.13.0 // indirect 48 | gopkg.in/yaml.v3 v3.0.1 // indirect 49 | ) 50 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/bluenviron/gortsplib/v4 v4.6.2 h1:CGIsxpnUFvSlIxnSFS0oFSSfwsHMmBCmYcrGAtIcwXc= 2 | github.com/bluenviron/gortsplib/v4 v4.6.2/go.mod h1:dN1YjyPNMfy/NwC17Ga6MiIMiUoQfg5GL7LGsVHa0Jo= 3 | github.com/bluenviron/mediacommon v1.5.1 h1:yYVF+ebqZOJh8yH+EeuPcAtTmWR66BqbJGmStxkScoI= 4 | github.com/bluenviron/mediacommon v1.5.1/go.mod h1:Ij/kE1LEucSjryNBVTyPL/gBI0d6/Css3f5PyrM957w= 5 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 6 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 7 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 8 | github.com/deepch/vdk v0.0.27 h1:j/SHaTiZhA47wRpaue8NRp7P9xwOOO/lunxrDJBwcao= 9 | github.com/deepch/vdk v0.0.27/go.mod h1:JlgGyR2ld6+xOIHa7XAxJh+stSDBAkdNvIPkUIdIywk= 10 | github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= 11 | github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= 12 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 13 | github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= 14 | github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= 15 | github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= 16 | github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= 17 | github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= 18 | github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= 19 | github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= 20 | github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= 21 | github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= 22 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 23 | github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= 24 | github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= 25 | github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= 26 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= 27 | github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= 28 | github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= 29 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 30 | github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= 31 | github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= 32 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 33 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 34 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 35 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 36 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 37 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 38 | github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 39 | github.com/google/pprof v0.0.0-20230309165930-d61513b1440d h1:um9/pc7tKMINFfP1eE7Wv6PRGXlcCSJkVajF7KJw3uQ= 40 | github.com/google/pprof v0.0.0-20230309165930-d61513b1440d/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk= 41 | github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 42 | github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= 43 | github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 44 | github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= 45 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 46 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 47 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 48 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 49 | github.com/logrusorgru/aurora/v4 v4.0.0 h1:sRjfPpun/63iADiSvGGjgA1cAYegEWMPCJdUpJYn9JA= 50 | github.com/logrusorgru/aurora/v4 v4.0.0/go.mod h1:lP0iIa2nrnT/qoFXcOZSrZQpJ1o6n2CUf/hyHi2Q4ZQ= 51 | github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= 52 | github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a h1:N9zuLhTvBSRt0gWSiJswwQ2HqDmtX/ZCDJURnKUt1Ik= 53 | github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a/go.mod h1:JKx41uQRwqlTZabZc+kILPrO/3jlKnQ2Z8b7YiVw5cE= 54 | github.com/mcuadros/go-defaults v1.2.0 h1:FODb8WSf0uGaY8elWJAkoLL0Ri6AlZ1bFlenk56oZtc= 55 | github.com/mcuadros/go-defaults v1.2.0/go.mod h1:WEZtHEVIGYVDqkKSWBdWKUVdRyKlMfulPaGDWIVeCWY= 56 | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= 57 | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= 58 | github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= 59 | github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= 60 | github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 61 | github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= 62 | github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= 63 | github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= 64 | github.com/onsi/ginkgo/v2 v2.9.5 h1:+6Hr4uxzP4XIUyAkg61dWBw8lb/gc4/X5luuxN/EC+Q= 65 | github.com/onsi/ginkgo/v2 v2.9.5/go.mod h1:tvAoo1QUJwNEU2ITftXTpR7R1RbCzoZUOs3RonqW57k= 66 | github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= 67 | github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= 68 | github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= 69 | github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE= 70 | github.com/pion/datachannel v1.5.5/go.mod h1:iMz+lECmfdCMqFRhXhcA/219B0SQlbpoR2V118yimL0= 71 | github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s= 72 | github.com/pion/ice/v2 v2.3.11/go.mod h1:hPcLC3kxMa+JGRzMHqQzjoSj3xtE9F+eoncmXLlCL4E= 73 | github.com/pion/interceptor v0.1.18/go.mod h1:tpvvF4cPM6NGxFA1DUMbhabzQBxdWMATDGEUYOR9x6I= 74 | github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms= 75 | github.com/pion/mdns v0.0.8/go.mod h1:hYE72WX8WDveIhg7fmXgMKivD3Puklk0Ymzog0lSyaI= 76 | github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA= 77 | github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8= 78 | github.com/pion/rtcp v1.2.10/go.mod h1:ztfEwXZNLGyF1oQDttz/ZKIBaeeg/oWbRYqzBM9TL1I= 79 | github.com/pion/rtcp v1.2.12 h1:bKWiX93XKgDZENEXCijvHRU/wRifm6JV5DGcH6twtSM= 80 | github.com/pion/rtcp v1.2.12/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4= 81 | github.com/pion/rtp v1.8.1/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU= 82 | github.com/pion/rtp v1.8.3 h1:VEHxqzSVQxCkKDSHro5/4IUUG1ea+MFdqR2R3xSpNU8= 83 | github.com/pion/rtp v1.8.3/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU= 84 | github.com/pion/sctp v1.8.5/go.mod h1:SUFFfDpViyKejTAdwD1d/HQsCu+V/40cCs2nZIvC3s0= 85 | github.com/pion/sctp v1.8.8/go.mod h1:igF9nZBrjh5AtmKc7U30jXltsFHicFCXSmWA2GWRaWs= 86 | github.com/pion/sdp/v3 v3.0.6 h1:WuDLhtuFUUVpTfus9ILC4HRyHsW6TdugjEX/QY9OiUw= 87 | github.com/pion/sdp/v3 v3.0.6/go.mod h1:iiFWFpQO8Fy3S5ldclBkpXqmWy02ns78NOKoLLL0YQw= 88 | github.com/pion/srtp/v2 v2.0.17/go.mod h1:y5WSHcJY4YfNB/5r7ca5YjHeIr1H3LM1rKArGGs8jMc= 89 | github.com/pion/stun v0.6.1/go.mod h1:/hO7APkX4hZKu/D0f2lHzNyvdkTGtIy3NDmLR7kSz/8= 90 | github.com/pion/transport v0.14.1/go.mod h1:4tGmbk00NeYA3rUa9+n+dzCCoKkcy3YlYb99Jn2fNnI= 91 | github.com/pion/transport/v2 v2.2.1/go.mod h1:cXXWavvCnFF6McHTft3DWS9iic2Mftcz1Aq29pGcU5g= 92 | github.com/pion/transport/v2 v2.2.2/go.mod h1:OJg3ojoBJopjEeECq2yJdXH9YVrUJ1uQ++NjXLOUorc= 93 | github.com/pion/transport/v2 v2.2.3/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0= 94 | github.com/pion/turn/v2 v2.1.3/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY= 95 | github.com/pion/webrtc/v3 v3.2.20 h1:BQJiXQsJq9LgLp3op7rLy1y8d2WD+LtiS9cpY0uQ22A= 96 | github.com/pion/webrtc/v3 v3.2.20/go.mod h1:vVURQTBOG5BpWKOJz3nlr23NfTDeyKVmubRNqzQp+Tg= 97 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 98 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 99 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 100 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 101 | github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= 102 | github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b h1:0LFwY6Q3gMACTjAbMZBjXAqTOzOwFaj2Ld6cjeQ7Rig= 103 | github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= 104 | github.com/q191201771/naza v0.30.48 h1:lbYUaa7A15kJKYwOiU4AbFS1Zo8oQwppl2tLEbJTqnw= 105 | github.com/q191201771/naza v0.30.48/go.mod h1:n+dpJjQSh90PxBwxBNuifOwQttywvSIN5TkWSSYCeBk= 106 | github.com/quic-go/qtls-go1-20 v0.3.3 h1:17/glZSLI9P9fDAeyCHBFSWSqJcwx1byhLwP5eUIDCM= 107 | github.com/quic-go/qtls-go1-20 v0.3.3/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k= 108 | github.com/quic-go/quic-go v0.38.1 h1:M36YWA5dEhEeT+slOu/SwMEucbYd0YFidxG3KlGPZaE= 109 | github.com/quic-go/quic-go v0.38.1/go.mod h1:ijnZM7JsFIkp4cRyjxJNIzdSfCLmUMg9wdyhGmg+SN4= 110 | github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw= 111 | github.com/shirou/gopsutil/v3 v3.23.8 h1:xnATPiybo6GgdRoC4YoGnxXZFRc3dqQTGi73oLvvBrE= 112 | github.com/shirou/gopsutil/v3 v3.23.8/go.mod h1:7hmCaBn+2ZwaZOr6jmPBZDfawwMGuo1id3C6aM8EDqQ= 113 | github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= 114 | github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= 115 | github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= 116 | github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k= 117 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 118 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 119 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 120 | github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= 121 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 122 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 123 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 124 | github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= 125 | github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 126 | github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= 127 | github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 128 | github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= 129 | github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= 130 | github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= 131 | github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= 132 | github.com/yapingcat/gomedia v0.0.0-20230905155010-55b9713fcec1 h1:ilNIuDBR+UKA3qefiyWRoFufIFn3E4tgEXbBM4ILH28= 133 | github.com/yapingcat/gomedia v0.0.0-20230905155010-55b9713fcec1/go.mod h1:WSZ59bidJOO40JSJmLqlkBJrjZCtjbKKkygEMfzY/kc= 134 | github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 135 | github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= 136 | github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= 137 | github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= 138 | github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= 139 | go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= 140 | go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= 141 | go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= 142 | go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= 143 | go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= 144 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 145 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 146 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 147 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 148 | golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= 149 | golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= 150 | golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= 151 | golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= 152 | golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= 153 | golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= 154 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= 155 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= 156 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 157 | golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 158 | golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= 159 | golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= 160 | golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= 161 | golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= 162 | golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 163 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 164 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 165 | golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 166 | golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 167 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= 168 | golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= 169 | golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= 170 | golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= 171 | golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= 172 | golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= 173 | golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= 174 | golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= 175 | golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= 176 | golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= 177 | golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= 178 | golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= 179 | golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= 180 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 181 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 182 | golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 183 | golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 184 | golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 185 | golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 186 | golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= 187 | golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= 188 | golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 189 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 190 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 191 | golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 192 | golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 193 | golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 194 | golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 195 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 196 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 197 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 198 | golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 199 | golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 200 | golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 201 | golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 202 | golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 203 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 204 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 205 | golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 206 | golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 207 | golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 208 | golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 209 | golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 210 | golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 211 | golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 212 | golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 213 | golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 214 | golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= 215 | golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 216 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 217 | golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 218 | golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 219 | golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= 220 | golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= 221 | golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= 222 | golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo= 223 | golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= 224 | golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= 225 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 226 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 227 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 228 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 229 | golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 230 | golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 231 | golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= 232 | golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= 233 | golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= 234 | golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= 235 | golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= 236 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 237 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 238 | golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= 239 | golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= 240 | golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= 241 | golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= 242 | golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= 243 | golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= 244 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 245 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 246 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 247 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 248 | google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= 249 | google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= 250 | google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= 251 | google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= 252 | google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= 253 | google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 254 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 255 | google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 256 | google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= 257 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 258 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 259 | gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= 260 | gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 261 | gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= 262 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= 263 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 264 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 265 | gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 266 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 267 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 268 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 269 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 270 | m7s.live/engine/v4 v4.15.2 h1:Uws658Ict2B8JojBG7fNmd2G2i63MlomsQ4npgNzF3g= 271 | m7s.live/engine/v4 v4.15.2/go.mod h1:uKxjmsjU1WARUNowEkP83BSrJMUjGwkJrX5nPi6DGmE= 272 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package rtsp 2 | 3 | import ( 4 | "net/http" 5 | "strconv" 6 | "sync" 7 | 8 | "github.com/bluenviron/gortsplib/v4" 9 | "go.uber.org/zap" 10 | . "m7s.live/engine/v4" 11 | "m7s.live/engine/v4/config" 12 | "m7s.live/engine/v4/util" 13 | ) 14 | 15 | type RTSPConfig struct { 16 | config.Publish 17 | config.Subscribe 18 | config.Pull 19 | config.Push 20 | ListenAddr string `default:":554" desc:"rtsp监听地址"` 21 | UDPAddr string `default:":8000" desc:"udp rtp监听地址"` 22 | RTCPAddr string `default:":8001" desc:"udp rtcp监听地址"` 23 | WriteBufferCount int `default:"2048" desc:"rtsp写缓冲区大小"` 24 | SendOptions bool `default:"true" desc:"是否发送options请求"` 25 | sync.Map 26 | server *gortsplib.Server 27 | } 28 | 29 | func (conf *RTSPConfig) OnEvent(event any) { 30 | switch v := event.(type) { 31 | case FirstConfig: 32 | conf.server = &gortsplib.Server{ 33 | Handler: conf, 34 | RTSPAddress: conf.ListenAddr, 35 | UDPRTPAddress: conf.UDPAddr, 36 | UDPRTCPAddress: conf.RTCPAddr, 37 | MulticastIPRange: "224.1.0.0/16", 38 | MulticastRTPPort: 8002, 39 | MulticastRTCPPort: 8003, 40 | WriteQueueSize: conf.WriteBufferCount, 41 | } 42 | if err := conf.server.Start(); err != nil { 43 | RTSPPlugin.Error("server start", zap.Error(err)) 44 | RTSPPlugin.Disabled = true 45 | } 46 | for streamPath, url := range conf.PullOnStart { 47 | if err := RTSPPlugin.Pull(streamPath, url, new(RTSPPuller), 0); err != nil { 48 | RTSPPlugin.Error("pull", zap.String("streamPath", streamPath), zap.String("url", url), zap.Error(err)) 49 | } 50 | } 51 | case SEpublish: 52 | if remoteURL := conf.CheckPush(v.Target.Path); remoteURL != "" { 53 | if err := RTSPPlugin.Push(v.Target.Path, remoteURL, new(RTSPPusher), false); err != nil { 54 | RTSPPlugin.Error("push", zap.String("streamPath", v.Target.Path), zap.String("url", remoteURL), zap.Error(err)) 55 | } 56 | } 57 | case InvitePublish: //按需拉流 58 | if remoteURL := conf.CheckPullOnSub(v.Target); remoteURL != "" { 59 | if err := RTSPPlugin.Pull(v.Target, remoteURL, new(RTSPPuller), 0); err != nil { 60 | RTSPPlugin.Error("pull", zap.String("streamPath", v.Target), zap.String("url", remoteURL), zap.Error(err)) 61 | } 62 | } 63 | } 64 | } 65 | 66 | var rtspConfig = &RTSPConfig{} 67 | var RTSPPlugin = InstallPlugin(rtspConfig) 68 | 69 | func filterStreams() (ss []*Stream) { 70 | Streams.Range(func(key string, s *Stream) { 71 | switch s.Publisher.(type) { 72 | case *RTSPPublisher, *RTSPPuller: 73 | ss = append(ss, s) 74 | } 75 | }) 76 | return 77 | } 78 | 79 | func (*RTSPConfig) API_list(w http.ResponseWriter, r *http.Request) { 80 | util.ReturnFetchValue(filterStreams, w, r) 81 | } 82 | 83 | func (*RTSPConfig) API_Pull(rw http.ResponseWriter, r *http.Request) { 84 | query := r.URL.Query() 85 | save, _ := strconv.Atoi(query.Get("save")) 86 | err := RTSPPlugin.Pull(query.Get("streamPath"), query.Get("target"), new(RTSPPuller), save) 87 | if err != nil { 88 | util.ReturnError(util.APIErrorQueryParse, err.Error(), rw, r) 89 | } else { 90 | util.ReturnOK(rw, r) 91 | } 92 | } 93 | 94 | func (*RTSPConfig) API_Push(rw http.ResponseWriter, r *http.Request) { 95 | query := r.URL.Query() 96 | err := RTSPPlugin.Push(query.Get("streamPath"), query.Get("target"), new(RTSPPusher), query.Has("save")) 97 | if err != nil { 98 | util.ReturnError(util.APIErrorQueryParse, err.Error(), rw, r) 99 | } else { 100 | util.ReturnOK(rw, r) 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /publisher.go: -------------------------------------------------------------------------------- 1 | package rtsp 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/bluenviron/gortsplib/v4/pkg/description" 7 | "github.com/bluenviron/gortsplib/v4/pkg/format" 8 | "github.com/bluenviron/mediacommon/pkg/codecs/mpeg4audio" 9 | "github.com/pion/rtp" 10 | "go.uber.org/zap" 11 | . "m7s.live/engine/v4" 12 | "m7s.live/engine/v4/codec" 13 | "m7s.live/engine/v4/common" 14 | . "m7s.live/engine/v4/track" 15 | "m7s.live/engine/v4/util" 16 | ) 17 | 18 | type RTSPPublisher struct { 19 | Publisher 20 | Tracks map[*description.Media]common.AVTrack `json:"-" yaml:"-"` 21 | RTSPIO 22 | } 23 | 24 | func (p *RTSPPublisher) SetTracks() error { 25 | p.Tracks = make(map[*description.Media]common.AVTrack, len(p.session.Medias)) 26 | defer func() { 27 | for _, track := range p.Tracks { 28 | p.Info("set track", zap.String("name", track.GetName())) 29 | } 30 | }() 31 | for _, track := range p.session.Medias { 32 | for _, forma := range track.Formats { 33 | switch f := forma.(type) { 34 | case *format.H264: 35 | vt := p.VideoTrack 36 | if vt == nil { 37 | vt = p.CreateVideoTrack(codec.CodecID_H264, byte(f.PayloadType())) 38 | } 39 | p.Tracks[track] = vt 40 | if len(f.SPS) > 0 { 41 | vt.WriteSliceBytes(f.SPS) 42 | } 43 | if len(f.PPS) > 0 { 44 | vt.WriteSliceBytes(f.PPS) 45 | } 46 | case *format.H265: 47 | vt := p.VideoTrack 48 | if vt == nil { 49 | vt = p.CreateVideoTrack(codec.CodecID_H265, byte(f.PayloadType())) 50 | } 51 | p.Tracks[track] = vt 52 | if len(f.VPS) > 0 { 53 | vt.WriteSliceBytes(f.VPS) 54 | } 55 | if len(f.SPS) > 0 { 56 | vt.WriteSliceBytes(f.SPS) 57 | } 58 | if len(f.PPS) > 0 { 59 | vt.WriteSliceBytes(f.PPS) 60 | } 61 | case *format.AV1: 62 | vt := p.VideoTrack 63 | if vt == nil { 64 | vt = p.CreateVideoTrack(codec.CodecID_AV1, byte(f.PayloadType())) 65 | } 66 | p.Tracks[track] = vt 67 | case *format.MPEG4Audio: 68 | at := p.AudioTrack 69 | if at == nil { 70 | conf := f.Config 71 | if f.LATM && f.StreamMuxConfig != nil && len(f.StreamMuxConfig.Programs) > 0 && len(f.StreamMuxConfig.Programs[0].Layers) > 0 { 72 | conf = f.StreamMuxConfig.Programs[0].Layers[0].AudioSpecificConfig 73 | } 74 | at := p.CreateAudioTrack(codec.CodecID_AAC, byte(f.PayloadType()), uint32(conf.SampleRate)).(*AAC) 75 | at.AACFormat = f 76 | at.AACDecoder.LATM = f.LATM 77 | at.AACDecoder.IndexDeltaLength = f.IndexDeltaLength 78 | at.AACDecoder.IndexLength = f.IndexLength 79 | at.AACDecoder.SizeLength = f.SizeLength 80 | if conf.Type == mpeg4audio.ObjectTypeAACLC { 81 | at.Mode = 1 82 | } 83 | at.Channels = uint8(conf.ChannelCount) 84 | asc, _ := conf.Marshal() 85 | // 复用AVCC写入逻辑,解析出AAC的配置信息 86 | at.WriteSequenceHead(append([]byte{0xAF, 0x00}, asc...)) 87 | } 88 | p.Tracks[track] = p.AudioTrack 89 | case *format.G711: 90 | at := p.AudioTrack 91 | if at == nil { 92 | at = p.CreateAudioTrack(util.Conditoinal(f.MULaw, codec.CodecID_PCMU, codec.CodecID_PCMA), byte(f.PayloadType()), uint32(f.ClockRate())) 93 | } 94 | p.Tracks[track] = at 95 | case *format.Opus: 96 | at := p.AudioTrack 97 | if at == nil { 98 | p.CreateAudioTrack(codec.CodecID_OPUS, byte(f.PayloadType()), uint32(f.ClockRate())) 99 | } 100 | p.Tracks[track] = at 101 | default: 102 | rtpMap := strings.ToLower(forma.RTPMap()) 103 | if strings.Contains(rtpMap, "pcm") { 104 | isMulaw := false 105 | if strings.Contains(rtpMap, "pcmu") { 106 | isMulaw = true 107 | } 108 | at := p.AudioTrack 109 | if at == nil { 110 | at = p.CreateAudioTrack(util.Conditoinal(isMulaw, codec.CodecID_PCMU, codec.CodecID_PCMA), byte(f.PayloadType()), uint32(f.ClockRate())) 111 | } 112 | p.Tracks[track] = at 113 | } else { 114 | p.Warn("unknown format", zap.Any("format", f.FMTP())) 115 | } 116 | } 117 | } 118 | } 119 | if p.VideoTrack == nil { 120 | p.Config.PubVideo = false 121 | p.Info("no video track") 122 | } 123 | if p.AudioTrack == nil { 124 | p.Config.PubAudio = false 125 | p.Info("no audio track") 126 | } 127 | return nil 128 | } 129 | 130 | func (p *RTSPPublisher) OnPacket(m *description.Media, f format.Format, pack *rtp.Packet) { 131 | if t, ok := p.Tracks[m]; ok { 132 | t.WriteRTPPack(pack) 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /server.go: -------------------------------------------------------------------------------- 1 | package rtsp 2 | 3 | import ( 4 | "github.com/bluenviron/gortsplib/v4" 5 | "github.com/bluenviron/gortsplib/v4/pkg/base" 6 | "github.com/bluenviron/gortsplib/v4/pkg/description" 7 | "go.uber.org/zap" 8 | "m7s.live/engine/v4/common" 9 | ) 10 | 11 | type RTSPIO struct { 12 | server *gortsplib.Server 13 | session *description.Session 14 | tracks []*description.Media 15 | stream *gortsplib.ServerStream 16 | audioTrack *description.Media 17 | videoTrack *description.Media 18 | } 19 | 20 | func (conf *RTSPConfig) OnConnOpen(ctx *gortsplib.ServerHandlerOnConnOpenCtx) { 21 | RTSPPlugin.Debug("conn opened") 22 | } 23 | 24 | func (conf *RTSPConfig) OnConnClose(ctx *gortsplib.ServerHandlerOnConnCloseCtx) { 25 | RTSPPlugin.Debug("conn closed") 26 | if p, ok := conf.LoadAndDelete(ctx.Conn); ok { 27 | p.(common.IIO).Stop(zap.String("conn", "closed")) 28 | } 29 | } 30 | 31 | func (conf *RTSPConfig) OnSessionOpen(ctx *gortsplib.ServerHandlerOnSessionOpenCtx) { 32 | RTSPPlugin.Debug("session opened") 33 | } 34 | 35 | func (conf *RTSPConfig) OnSessionClose(ctx *gortsplib.ServerHandlerOnSessionCloseCtx) { 36 | RTSPPlugin.Debug("session closed") 37 | conf.Delete(ctx.Session) 38 | } 39 | 40 | // called after receiving a DESCRIBE request. 41 | func (conf *RTSPConfig) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error) { 42 | RTSPPlugin.Debug("describe request", zap.String("sdp", string(ctx.Request.Body))) 43 | var suber RTSPSubscriber 44 | suber.server = conf.server 45 | suber.RemoteAddr = ctx.Conn.NetConn().RemoteAddr().String() 46 | suber.SetIO(ctx.Conn.NetConn()) 47 | streamPath := ctx.Path 48 | if ctx.Query != "" { 49 | streamPath = streamPath + "?" + ctx.Query 50 | } 51 | if err := RTSPPlugin.Subscribe(streamPath, &suber); err == nil { 52 | RTSPPlugin.Debug("describe replay ok") 53 | conf.Store(ctx.Conn, &suber) 54 | return &base.Response{ 55 | StatusCode: base.StatusOK, 56 | }, suber.stream, nil 57 | } else { 58 | return &base.Response{ 59 | StatusCode: base.StatusNotFound, 60 | }, suber.stream, nil 61 | } 62 | } 63 | 64 | func (conf *RTSPConfig) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) { 65 | var resp base.Response 66 | resp.StatusCode = base.StatusOK 67 | if p, ok := conf.Load(ctx.Conn); ok { 68 | switch v := p.(type) { 69 | case *RTSPSubscriber: 70 | return &resp, v.stream, nil 71 | case *RTSPPublisher: 72 | return &resp, v.stream, nil 73 | } 74 | } 75 | resp.StatusCode = base.StatusNotFound 76 | return &resp, nil, nil 77 | } 78 | 79 | func (conf *RTSPConfig) OnPlay(ctx *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, error) { 80 | var resp base.Response 81 | resp.StatusCode = base.StatusNotFound 82 | if p, ok := conf.Load(ctx.Conn); ok { 83 | switch v := p.(type) { 84 | case *RTSPSubscriber: 85 | resp.StatusCode = base.StatusOK 86 | go func() { 87 | v.PlayRTP() 88 | ctx.Session.Close() 89 | }() 90 | } 91 | } 92 | return &resp, nil 93 | } 94 | func (conf *RTSPConfig) OnRecord(ctx *gortsplib.ServerHandlerOnRecordCtx) (*base.Response, error) { 95 | if p, ok := conf.Load(ctx.Session); ok { 96 | ctx.Session.OnPacketRTPAny(p.(*RTSPPublisher).OnPacket) 97 | } 98 | return &base.Response{ 99 | StatusCode: base.StatusOK, 100 | }, nil 101 | } 102 | func (conf *RTSPConfig) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (*base.Response, error) { 103 | RTSPPlugin.Debug("annouce request", zap.String("sdp", string(ctx.Request.Body))) 104 | p := &RTSPPublisher{} 105 | p.SetIO(ctx.Conn.NetConn()) 106 | if err := RTSPPlugin.Publish(ctx.Path, p); err == nil { 107 | p.session = ctx.Description 108 | p.stream = gortsplib.NewServerStream(conf.server, ctx.Description) 109 | if err = p.SetTracks(); err != nil { 110 | return nil, err 111 | } 112 | conf.Store(ctx.Conn, p) 113 | conf.Store(ctx.Session, p) 114 | } else { 115 | return &base.Response{ 116 | StatusCode: base.StatusBadRequest, 117 | }, nil 118 | } 119 | return &base.Response{ 120 | StatusCode: base.StatusOK, 121 | }, nil 122 | } 123 | -------------------------------------------------------------------------------- /subscriber.go: -------------------------------------------------------------------------------- 1 | package rtsp 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/bluenviron/gortsplib/v4" 7 | "github.com/bluenviron/gortsplib/v4/pkg/description" 8 | "github.com/bluenviron/gortsplib/v4/pkg/format" 9 | "github.com/bluenviron/mediacommon/pkg/codecs/mpeg4audio" 10 | . "m7s.live/engine/v4" 11 | "m7s.live/engine/v4/codec" 12 | "m7s.live/engine/v4/track" 13 | ) 14 | 15 | type RTSPSubscriber struct { 16 | Subscriber 17 | RTSPIO 18 | } 19 | 20 | func (s *RTSPSubscriber) OnEvent(event any) { 21 | switch v := event.(type) { 22 | case *track.Video: 23 | if s.Video != nil { 24 | return 25 | } 26 | switch v.CodecID { 27 | case codec.CodecID_H264: 28 | s.videoTrack = &description.Media{ 29 | Type: description.MediaTypeVideo, 30 | Formats: []format.Format{&format.H264{ 31 | PacketizationMode: 1, 32 | PayloadTyp: v.PayloadType, 33 | SPS: v.ParamaterSets[0], 34 | PPS: v.ParamaterSets[1], 35 | }}, 36 | } 37 | case codec.CodecID_H265: 38 | s.videoTrack = &description.Media{ 39 | Type: description.MediaTypeVideo, 40 | Formats: []format.Format{&format.H265{ 41 | PayloadTyp: v.PayloadType, 42 | VPS: v.ParamaterSets[0], 43 | SPS: v.ParamaterSets[1], 44 | PPS: v.ParamaterSets[2], 45 | }}, 46 | } 47 | case codec.CodecID_AV1: 48 | var idx, profile, tail int 49 | idx = int(v.ParamaterSets[1][0]) 50 | profile = int(v.ParamaterSets[1][1]) 51 | tail = int(v.ParamaterSets[1][2]) 52 | s.videoTrack = &description.Media{ 53 | Type: description.MediaTypeVideo, 54 | Formats: []format.Format{&format.AV1{ 55 | PayloadTyp: v.PayloadType, 56 | LevelIdx: &idx, 57 | Profile: &profile, 58 | Tier: &tail, 59 | }}, 60 | } 61 | } 62 | if s.videoTrack != nil { 63 | s.tracks = append(s.tracks, s.videoTrack) 64 | s.AddTrack(v) 65 | } 66 | case *track.Audio: 67 | if s.Audio != nil { 68 | return 69 | } 70 | switch v.CodecID { 71 | case codec.CodecID_AAC: 72 | f := v.AACFormat 73 | if f == nil { 74 | f = &format.MPEG4Audio{ 75 | PayloadTyp: v.PayloadType, 76 | Config: &mpeg4audio.Config{ 77 | Type: mpeg4audio.ObjectTypeAACLC, 78 | SampleRate: int(v.SampleRate), 79 | ChannelCount: int(v.Channels), 80 | }, 81 | SizeLength: v.AACDecoder.SizeLength, 82 | IndexLength: v.AACDecoder.IndexLength, 83 | IndexDeltaLength: v.AACDecoder.IndexDeltaLength, 84 | } 85 | } 86 | s.audioTrack = &description.Media{ 87 | Type: description.MediaTypeAudio, 88 | Formats: []format.Format{f}, 89 | } 90 | case codec.CodecID_PCMA: 91 | s.audioTrack = &description.Media{ 92 | Type: description.MediaTypeAudio, 93 | Formats: []format.Format{&format.Generic{ 94 | PayloadTyp: v.PayloadType, 95 | ClockRat: int(v.SampleRate), 96 | RTPMa: fmt.Sprintf("PCMA/%d", v.SampleRate), 97 | }}, 98 | } 99 | case codec.CodecID_PCMU: 100 | s.audioTrack = &description.Media{ 101 | Type: description.MediaTypeAudio, 102 | Formats: []format.Format{&format.Generic{ 103 | PayloadTyp: v.PayloadType, 104 | ClockRat: int(v.SampleRate), 105 | RTPMa: fmt.Sprintf("PCMU/%d", v.SampleRate), 106 | }}, 107 | } 108 | case codec.CodecID_OPUS: 109 | s.audioTrack = &description.Media{ 110 | Type: description.MediaTypeAudio, 111 | Formats: []format.Format{&format.Opus{ 112 | PayloadTyp: v.PayloadType, 113 | }}, 114 | } 115 | } 116 | if s.audioTrack != nil { 117 | s.tracks = append(s.tracks, s.audioTrack) 118 | s.AddTrack(v) 119 | } 120 | case ISubscriber: 121 | s.session = &description.Session{ 122 | Medias: s.tracks, 123 | } 124 | if s.server != nil { 125 | s.stream = gortsplib.NewServerStream(s.server, s.session) 126 | } 127 | case VideoRTP: 128 | s.stream.WritePacketRTP(s.videoTrack, v.Packet) 129 | case AudioRTP: 130 | s.stream.WritePacketRTP(s.audioTrack, v.Packet) 131 | default: 132 | s.Subscriber.OnEvent(event) 133 | } 134 | } 135 | --------------------------------------------------------------------------------