rtsp: support reading streams tunneled with HTTP or WebSocket (#4986)

This commit is contained in:
Alessandro Ros
2025-09-17 22:31:20 +02:00
committed by GitHub
parent 558d1c3818
commit f81c50ee68
6 changed files with 50 additions and 17 deletions

View File

@@ -2,6 +2,8 @@
package rtsp
import (
"net/url"
"regexp"
"time"
"github.com/bluenviron/gortsplib/v5"
@@ -116,14 +118,37 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error {
decodeErrors.Start()
defer decodeErrors.Stop()
u, err := base.ParseURL(params.ResolvedSource)
u0, err := url.Parse(params.ResolvedSource)
if err != nil {
return err
}
var scheme string
if u0.Scheme == "rtsp" || u0.Scheme == "rtsp+http" || u0.Scheme == "rtsp+ws" {
scheme = "rtsp"
} else {
scheme = "rtsps"
}
var tunnel gortsplib.Tunnel
switch u0.Scheme {
case "rtsp+http", "rtsps+http":
tunnel = gortsplib.TunnelHTTP
case "rtsp+ws", "rtsps+ws":
tunnel = gortsplib.TunnelWebSocket
default:
tunnel = gortsplib.TunnelNone
}
u, err := base.ParseURL(regexp.MustCompile("^.*?://").ReplaceAllString(params.ResolvedSource, "rtsp://"))
if err != nil {
return err
}
c := &gortsplib.Client{
Scheme: u.Scheme,
Scheme: scheme,
Host: u.Host,
Tunnel: tunnel,
Protocol: params.Conf.RTSPTransport.Protocol,
TLSConfig: tls.MakeConfig(u.Hostname(), params.Conf.SourceFingerprint),
ReadTimeout: time.Duration(s.ReadTimeout),