Compare commits

...

3 Commits
v4.3.3 ... v3

Author SHA1 Message Date
dexter
a331359e97 增加流超时再次重连功能 2021-10-14 10:00:55 +08:00
dexter
bbd668796e 优化重连逻辑 2021-10-11 15:40:50 +08:00
dexter
107b4e8941 AACPayloader 2021-10-06 20:43:18 +08:00
4 changed files with 31 additions and 15 deletions

View File

@@ -35,7 +35,26 @@ func (rtsp *RTSP) PullStream(streamPath string, rtspUrl string) (err error) {
rtsp.aRTPControlChannel = 3
rtsp.URL = rtspUrl
rtsp.UDPServer = &UDPServer{Session: rtsp}
go rtsp.startStream()
if config.Reconnect {
go func() {
for rtsp.Err() == nil {
rtsp.RTSPClientInfo = RTSPClientInfo{}
Printf("reconnecting:%s in 5 seconds", rtspUrl)
time.Sleep(time.Second * 5)
rtsp.startStream()
}
rtsp.Stop()
if rtsp.IsTimeout {
go rtsp.PullStream(streamPath, rtspUrl)
}
}()
} else {
rtsp.RTSPClientInfo = RTSPClientInfo{}
go func() {
rtsp.startStream()
rtsp.Stop()
}()
}
return
}
return errors.New("publish badname")
@@ -266,15 +285,6 @@ func (client *RTSP) startStream() {
}
startTime := time.Now()
//loggerTime := time.Now().Add(-10 * time.Second)
defer func() {
if client.Err() == nil && config.Reconnect {
client.RTSPClientInfo = RTSPClientInfo{}
Printf("reconnecting:%s in 5 seconds", client.URL)
time.AfterFunc(time.Second*5, client.startStream)
} else {
client.Stop()
}
}()
if err := client.requestStream(); err != nil {
Printf("rtsp requestStream err:%v", err)
return

6
go.mod
View File

@@ -3,9 +3,9 @@ module github.com/Monibuca/plugin-rtsp/v3
go 1.16
require (
github.com/Monibuca/engine/v3 v3.3.0
github.com/Monibuca/engine/v3 v3.3.7
github.com/Monibuca/utils/v3 v3.0.2
github.com/pion/rtp v1.6.5
github.com/pion/rtp v1.7.2
github.com/teris-io/shortid v0.0.0-20201117134242-e59966efd125
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069 // indirect
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c // indirect
)

6
go.sum
View File

@@ -2,6 +2,8 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Monibuca/engine/v3 v3.3.0 h1:7zwYsLEHdeVZy6+JjVlaDhl/asr0HG6jirBL4uynj0s=
github.com/Monibuca/engine/v3 v3.3.0/go.mod h1:odyqD/VTQDN4qgzajsgn7kW7MWDIzTHt+j+BcI8i+4g=
github.com/Monibuca/engine/v3 v3.3.7 h1:EB77gSzvu4ThRWcWBWPmqWcCmMqC4B21/sUQmf/i2XU=
github.com/Monibuca/engine/v3 v3.3.7/go.mod h1:odyqD/VTQDN4qgzajsgn7kW7MWDIzTHt+j+BcI8i+4g=
github.com/Monibuca/utils/v3 v3.0.1/go.mod h1:RpNS95gapWs6gimwh8Xn2x72FN5tO7Powabj7dTFyvE=
github.com/Monibuca/utils/v3 v3.0.2 h1:n2vr67DHanav8wBC9IENk8xrKzeGJnBsxYUu69s8TrQ=
github.com/Monibuca/utils/v3 v3.0.2/go.mod h1:RpNS95gapWs6gimwh8Xn2x72FN5tO7Powabj7dTFyvE=
@@ -41,6 +43,8 @@ github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TB
github.com/pion/rtp v1.6.2/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
github.com/pion/rtp v1.6.5 h1:o2cZf8OascA5HF/b0PAbTxRKvOWxTQxWYt7SlToxFGI=
github.com/pion/rtp v1.6.5/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
github.com/pion/rtp v1.7.2 h1:HCDKDCixh7PVjkQTsqHAbk1lg+bx059EHxcnyl42dYs=
github.com/pion/rtp v1.7.2/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
github.com/pixelbender/go-sdp v1.1.0/go.mod h1:6IBlz9+BrUHoFTea7gcp4S54khtOhjCW/nVDLhmZBAs=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -69,6 +73,8 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069 h1:siQdpVirKtzPhKl3lZWozZraCFObP8S1v6PRp0bLrtU=
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c h1:taxlMj0D/1sOAuv/CbSD+MMDof2vbyPTqz5FNYKpXt8=
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@@ -454,8 +454,8 @@ func (session *RTSP) handleRequest(req *Request) {
case 10:
// TODO:
sdpInfo = append(sdpInfo, fmt.Sprintf("a=rtpmap:97 MPEG4-GENERIC/%d/%d", at.SoundRate, at.Channels))
session.UDPClient.APacketizer = rtp.NewPacketizer(1200, 97, uint32(ssrc), &AACPayloader{}, rtp.NewFixedSequencer(1), uint32(at.SoundRate))
session.UDPClient.AT = at
// session.UDPClient.APacketizer = rtp.NewPacketizer(1200, 97, uint32(ssrc), &AACPayloader{}, rtp.NewFixedSequencer(1), uint32(at.SoundRate))
//session.UDPClient.AT = at
}
}
session.SDPRaw = strings.Join(sdpInfo, "\r\n") + "\r\n"