mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-11-03 09:51:26 +08:00
rtsp: support reading streams tunneled with HTTP or WebSocket (#4986)
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user