RTSP source: support proxing with UDP-multicast

This commit is contained in:
aler9 2021-06-18 21:15:49 +02:00
parent 75e1e3e4dc
commit e64edcfda9
6 changed files with 33 additions and 28 deletions

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.15
require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/aler9/gortsplib v0.0.0-20210617144524-db28e87ecb0c
github.com/aler9/gortsplib v0.0.0-20210618154725-9595e298f812
github.com/asticode/go-astits v0.0.0-00010101000000-000000000000
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.4.9

4
go.sum
View File

@ -4,8 +4,8 @@ github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2c
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/aler9/go-astits v0.0.0-20210423195926-582b09ed7c04 h1:CXgQLsU4uxWAmsXNOjGLbj0A+0IlRcpZpMgI13fmVwo=
github.com/aler9/go-astits v0.0.0-20210423195926-582b09ed7c04/go.mod h1:DkOWmBNQpnr9mv24KfZjq4JawCFX1FCqjLVGvO0DygQ=
github.com/aler9/gortsplib v0.0.0-20210617144524-db28e87ecb0c h1:IqV2N1yifhnVPafY8SknenVL6k66gGa5jhrujcbjl5Q=
github.com/aler9/gortsplib v0.0.0-20210617144524-db28e87ecb0c/go.mod h1:ozu0NvgZMhb4AT6VdyV6OfmgPviSiZImRkaTwW1nEKc=
github.com/aler9/gortsplib v0.0.0-20210618154725-9595e298f812 h1:8MJKyFmw6GMsWfTmG4t2r2BVrjsd5Zgrqu0tvXXj1F4=
github.com/aler9/gortsplib v0.0.0-20210618154725-9595e298f812/go.mod h1:ozu0NvgZMhb4AT6VdyV6OfmgPviSiZImRkaTwW1nEKc=
github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927 h1:95mXJ5fUCYpBRdSOnLAQAdJHHKxxxJrVCiaqDi965YQ=
github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927/go.mod h1:vzuE21rowz+lT1NGsWbreIvYulgBpCGnQyeTyFblUHc=
github.com/asticode/go-astikit v0.20.0 h1:+7N+J4E4lWx2QOkRdOf6DafWJMv6O4RRfgClwQokrH8=

View File

@ -9,6 +9,7 @@ import (
"strings"
"time"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/base"
)
@ -68,17 +69,17 @@ type PathConf struct {
Regexp *regexp.Regexp `yaml:"-" json:"-"`
// source
Source string `yaml:"source"`
SourceProtocol string `yaml:"sourceProtocol"`
SourceProtocolParsed *base.StreamProtocol `yaml:"-" json:"-"`
SourceAnyPortEnable bool `yaml:"sourceAnyPortEnable"`
SourceFingerprint string `yaml:"sourceFingerprint" json:"sourceFingerprint"`
SourceOnDemand bool `yaml:"sourceOnDemand"`
SourceOnDemandStartTimeout time.Duration `yaml:"sourceOnDemandStartTimeout"`
SourceOnDemandCloseAfter time.Duration `yaml:"sourceOnDemandCloseAfter"`
SourceRedirect string `yaml:"sourceRedirect"`
DisablePublisherOverride bool `yaml:"disablePublisherOverride"`
Fallback string `yaml:"fallback"`
Source string `yaml:"source"`
SourceProtocol string `yaml:"sourceProtocol"`
SourceProtocolParsed *gortsplib.ClientProtocol `yaml:"-" json:"-"`
SourceAnyPortEnable bool `yaml:"sourceAnyPortEnable"`
SourceFingerprint string `yaml:"sourceFingerprint" json:"sourceFingerprint"`
SourceOnDemand bool `yaml:"sourceOnDemand"`
SourceOnDemandStartTimeout time.Duration `yaml:"sourceOnDemandStartTimeout"`
SourceOnDemandCloseAfter time.Duration `yaml:"sourceOnDemandCloseAfter"`
SourceRedirect string `yaml:"sourceRedirect"`
DisablePublisherOverride bool `yaml:"disablePublisherOverride"`
Fallback string `yaml:"fallback"`
// authentication
PublishUser string `yaml:"publishUser"`
@ -148,11 +149,15 @@ func (pconf *PathConf) fillAndCheck(name string) error {
switch pconf.SourceProtocol {
case "udp":
v := base.StreamProtocolUDP
v := gortsplib.ClientProtocolUDP
pconf.SourceProtocolParsed = &v
case "multicast":
v := gortsplib.ClientProtocolMulticast
pconf.SourceProtocolParsed = &v
case "tcp":
v := base.StreamProtocolTCP
v := gortsplib.ClientProtocolTCP
pconf.SourceProtocolParsed = &v
case "automatic":

View File

@ -34,7 +34,7 @@ type Parent interface {
// Source is a RTSP external source.
type Source struct {
ur string
proto *base.StreamProtocol
proto *gortsplib.ClientProtocol
anyPortEnable bool
fingerprint string
readTimeout time.Duration
@ -53,7 +53,7 @@ type Source struct {
func New(
ctxParent context.Context,
ur string,
proto *base.StreamProtocol,
proto *gortsplib.ClientProtocol,
anyPortEnable bool,
fingerprint string,
readTimeout time.Duration,
@ -136,7 +136,7 @@ func (s *Source) runInner() bool {
s.log(logger.Debug, "connecting")
client := &gortsplib.Client{
StreamProtocol: s.proto,
Protocol: s.proto,
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
VerifyConnection: func(cs tls.ConnectionState) error {

View File

@ -361,7 +361,7 @@ func TestClientRTSPAuthFail(t *testing.T) {
"rtsp://"+ca.user+":"+ca.pass+"@localhost:8554/test/stream",
gortsplib.Tracks{track},
)
require.Equal(t, "wrong status code: 401 (Unauthorized)", err.Error())
require.Equal(t, "invalid status code: 401 (Unauthorized)", err.Error())
})
}
@ -399,7 +399,7 @@ func TestClientRTSPAuthFail(t *testing.T) {
_, err := gortsplib.DialRead(
"rtsp://" + ca.user + ":" + ca.pass + "@localhost:8554/test/stream",
)
require.Equal(t, "wrong status code: 401 (Unauthorized)", err.Error())
require.Equal(t, "invalid status code: 401 (Unauthorized)", err.Error())
})
}
@ -419,7 +419,7 @@ func TestClientRTSPAuthFail(t *testing.T) {
"rtsp://localhost:8554/test/stream",
gortsplib.Tracks{track},
)
require.Equal(t, "wrong status code: 401 (Unauthorized)", err.Error())
require.Equal(t, "invalid status code: 401 (Unauthorized)", err.Error())
})
}
@ -548,8 +548,8 @@ func TestClientRTSPNonCompliantFrameSize(t *testing.T) {
require.NoError(t, err)
client := &gortsplib.Client{
StreamProtocol: func() *base.StreamProtocol {
v := base.StreamProtocolTCP
Protocol: func() *gortsplib.ClientProtocol {
v := gortsplib.ClientProtocolTCP
return &v
}(),
ReadBufferSize: 4500,
@ -598,8 +598,8 @@ func TestClientRTSPNonCompliantFrameSize(t *testing.T) {
require.NoError(t, err)
client := &gortsplib.Client{
StreamProtocol: func() *base.StreamProtocol {
v := base.StreamProtocolTCP
Protocol: func() *gortsplib.ClientProtocol {
v := gortsplib.ClientProtocolTCP
return &v
}(),
ReadBufferSize: 4500,

View File

@ -116,8 +116,8 @@ paths:
source: record
# if the source is an RTSP or RTSPS URL, this is the protocol that will be used to
# pull the stream. available options are "automatic", "udp", "tcp".
# the tcp protocol can help to overcome the error "no UDP packets received recently".
# pull the stream. available options are "automatic", "udp", "multicast", "tcp".
# the TCP protocol can help to overcome the error "no UDP packets received recently".
sourceProtocol: automatic
# if the source is an RTSP or RTSPS URL, this allows to support cameras that